Jump to content
  • Advertisement
Sign in to follow this  
serratemplar

Computing a normal for an arbitrary quad

This topic is 4270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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

Share this post


Link to post
Share on other sites
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)

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!