0
\$\begingroup\$

I have a rectangle which is created by 2 triangles and it is in x-z plane, and i have object on it. Now, the normals of two triangles (face normals) are y axis i.e. (0,1,0). I want to display normals of two triangles for which i need two points to draw a line to show normal. Intuitively if i take center of a triangle as one and (0,1,0) as second point of a normal then both of the normals will converge to single point. I dont think it is correct as the normal should be exactly perpendicular to the surface. We can do a trick and take one point as a center and other by increasing y coordinate keeping x and z same, but what if we have curved surface and not a plane board? What about the cylinder made of triangles? How could we display normals as a lines of cylinder? I guess i am missing very basic concept here, please help me to understand it and tell me how to calculate the two points of normal.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Usually you already have normals for all three vertecies that make a tri. In that case you average the position of the vertecies as the first point and add the average of all 3 normals to get the second point.

(v0 v1 and v2 are supposed to be the vertecies that make up the triangle) If you don't already have normals and you want to calculate them then you just calculate the cross product of perpendicular = v0v1 x v0v2 and then normalize the result (divide by length). The order is important. v0 is the first vertex, v1 the second and v2 the third. v0v1 = v1-v0 and v0v2 = v2-v0. Start point is as was before start = (v0+v1+v2)/3.0 and the end is then end = start+ (perpendicular/length(perpendicular))

Also, depending on your model size the length of 1 might be too small or too huge, in that case just use a scaling factor.

This is really more of a comment but it's a little too long so I'm posting it as an answer

\$\endgroup\$
3
  • \$\begingroup\$ just to confirm, here end is start+normal (which is to be passed in glNormal3f, normalized) right? \$\endgroup\$ Commented Oct 12, 2013 at 23:50
  • \$\begingroup\$ (Edited this comment, misunderstood you) yes basically only that in this case you're passing the normal for the face (which equal the vertex normals for flat/solid/hard shading) \$\endgroup\$
    – PeterT
    Commented Oct 13, 2013 at 0:06
  • \$\begingroup\$ yeah, actually you got me wrong :) i mean, the coordinates which are to be passed to normalf function and in my case, all 3 vertices will have same normal as it is per face. For e.g. end point= start point + coordinates of a normal (0,1,0 in above case). \$\endgroup\$ Commented Oct 13, 2013 at 0:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .