Question

I have made a cylinder using triangles by calculating points on the top and bottom circles and then joining those points. I start from (1,1,0). Then, I calculate one point at the bottom (by changing just the y-axis -> (1,0,0)), then the next point on the top (x = xcosA, z = zsinA where A is any angle) and so on. So, I am tracing circles at the top and bottom in the counterclockwise direction. Now, I want to draw normals to these triangles.

I take points in groups of three. Suppose they are stored in vectors a,b and c where a is the first point (at the top), b is the second point (at the bottom) and c is the third point (at the top). According to the right hand rule, to calculate the normal, I have to do this: normal = (c-b) x (a-b). This should give me a normal facing outwards. However, the normal is being drawn inwards. To draw the normal, I just glTranslatef to the centre of the triangle and I draw a line from (0,0,0) to normal. Is my calculation incorrect?

Was it helpful?

Solution

The calculation is correct, but the order of the points isn't. Remember that the cross product is anticommutative, i.e, a x b = - (b x a).

In your particular example of a cylinder, you're defining the points a and c from left to right(when seen from the front). With your current normal calculation, the normal should be inwards. If you want it outwards, you can just reverse the order of the normal calculation. A possible solution is: normal = (a - b) x (c - b).

PS.: The usual definition for a triangle normal (in books) is (b - a) x (c - a), which is equivalent to the one above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top