Original Post
🔒 Locked
normal calculation
Advertisement
I don't have a lot of time to explain it in detail, but it has to do with taking the cross product of the two vectors that extend from the vertex you want to calculate the normal for. That will give you the normal. Do a search for it on google or even on this site and you should come up with some good stuff.
Triangle points, counter clockwise, are P0, P1, and P2. (P1-P0).cross(P2-P0) gives you the normal to the polygon. The normals will all be the same if you want a polygonal surface. If you want a smooth contoured surface, you will want to average the normals of all of the polys around each vertex.
First you need to calculate each triangle's normal:
Then, for each vertex, you need to figure out which triangles it is a part of, and average those triangles' normals. This gives you the vertex normal.
This assumes that the mesh is an approximation of a smooth surface.
To average the normals, simply add them all up and scale the result by 1/numNormals.
Vector CalcTriangleNormal(Vector p1, Vector p2, Vector p3){ Vector edge1 = v2 - v1; Vector edge2 = v3 - v1; Vector normal = CrossProduct(edge1, edge2); return normal;}Then, for each vertex, you need to figure out which triangles it is a part of, and average those triangles' normals. This gives you the vertex normal.
This assumes that the mesh is an approximation of a smooth surface.
To average the normals, simply add them all up and scale the result by 1/numNormals.
There is more than one way of creating normals in order to simulate a smooth surface. The easiest way is this:
No. To "average" the normals, you add them and then normalize the result. Dividing by the number of vectors will not give you a unit vector.
- Compute a normal for each triangle.
- For each vertex, "average" the normals of all the triangles that use this vertex. This is known as an "unweighted" normal.
Quote:
Original post by mother
To average the normals, simply add them all up and scale the result by 1/numNormals.
No. To "average" the normals, you add them and then normalize the result. Dividing by the number of vectors will not give you a unit vector.
Quote:
Original post by mother
To average the normals, simply add them all up and scale the result by 1/numNormals.
No. To "average" the normals, you add them and then normalize the result. Dividing by the number of vectors will not give you a unit vector.[/quote]
Right you are. My mistake. Thanks for the correction. :)
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement