Sign in to follow this  
serratemplar

Computing a normal for an arbitrary quad

Recommended Posts

I've got four vertices and I'd like to compute a general normal for the entire quad. Cross-producting two of the vectors will give me a normal for that corner, but I suspect it won't be accurate for the entire quad. Should I take all of the normals and average them? Add them together and normalize? Is one in fact sufficient? Thanks in advance.

Share this post


Link to post
Share on other sites
If the quad is planar, then one normal is sufficient -- they'll all be the same, anyway. If, though, the quad is really composed of two non-coplanar triangles, then you'll want to average the two triangles' normals. In that case, it'd probably make sense to switch to rendering triangles.

Note that this only applies to per-poly normals. For per-vertex normals, you'd want to sample the normals for all polygons using each of the four vertices and average them together.

-jouley

Share this post


Link to post
Share on other sites
Quote:
Original post by jouley
If the quad is planar, then one normal is sufficient -- they'll all be the same, anyway. If, though, the quad is really composed of two non-coplanar triangles, then you'll want to average the two triangles' normals. In that case, it'd probably make sense to switch to rendering triangles.


If the quad is non-planar, it could be broken into two triangles in two different ways (i.e. along either diagonal).

But yeah, render triangles. It avoids these complications :)

Share this post


Link to post
Share on other sites
If a 'quad' isn't planar then it isn't a quad, and the solution is undefined. Could you tell us where the vertices came from and what you need the face normal for? Perhaps then we could propose an optimal triangulation from which to work.

Admiral

Share this post


Link to post
Share on other sites
The vertices are coming out of a .ply file that I believe is not of the typical format...because it's intended to be loaded and drawn with GL_QUAD_STRIPS (or the like). Are GL_QUADS necessarily composed of coplanar vertices? If that's the case perhaps I should try to break this into triangles...but that would invalidate the format =(

Share this post


Link to post
Share on other sites
From my experience with OpenGL, GL_QUADs would be rendered no matter what data you threw at the graphics card, but the results were ambiguous and driver-specific if the vertices didn't lie in roughly in a plane.

I suppose planarity is in the file-format's contract, so you shouldn't have to worry about accommodating non-degenerate tetrahedra. In this case, assuming non-collinearity, crossing any two ordered, non-parallel edge vectors will give you a satisfactory (and unique) face normal. If the input is invalid as we've discussed, then your results won't necessarily be well-defined, but that's not your problem. As they say, GIGO.

Admiral

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this