Computing a normal for an arbitrary quad

Started by
5 comments, last by TheAdmiral 17 years ago
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.
Advertisement
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
Break it into a triangle and take the cross product of the triangle.

Normal for a triangle ->
p1 = v2 - v1
p2 = v3 - v1

Normal = CrossProduct(p1, p2)
The more applications I write, more I find out how less I know
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 :)
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
Ring3 Circus - Diary of a programmer, journal of a hacker.
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 =(
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
Ring3 Circus - Diary of a programmer, journal of a hacker.

This topic is closed to new replies.

Advertisement