POV-Ray : Newsgroups : povray.windows : Computing normals for use in smooth_triangle : Re: Computing normals for use in smooth_triangle Server Time
28 Jul 2024 16:31:52 EDT (-0400)
  Re: Computing normals for use in smooth_triangle  
From: Johannes Hubert
Date: 10 May 1998 06:50:55
Message: <6j40rr$r06$1@oz.aussie.org>
Jim Kress wrote in message <35552876.2EC1244E@dccmail.com>...
>I have an object that isdescribed by a large number of triangles.  I
>have the x,y,z coordinates for each vertex of every triangle.  Can
>anyone explain how to calculate the normal vectors for me to use with
>the smooth_triangle function in POVray?
>


First, calculate the normal for each triangle. If the triangle has the tree
vertices v1, v2, v3, it is defined by the following cross-product:



Once you have the normal for each triangle, you then calculate the normal of
each vertex by calculating the average of the triangle-normals of all
triangles that use this vertex:
Simply add the normals of all triangles that use a vertex together and
normalize the resulting vector.

Note: In the cross-product the order of the vertices is important. You
should choose v1, v2, v3 in clockwise or counter-clockwise fashion for all
triangles in a mesh. Which one doesn't matter but to mix them can have
strange results. Why? Because the crossproduct gives you a vector pointing
in one direction or the same vector pointing in the opposite direction,
depending on the order of the vertices. And mixing normals that point to the
"inside" and the "outside" of the mesh when calculating the averaged normal
often gives strange results.

You can find a little bit more on this page (this is for OpenGL but the
theory applies here too):
(Note, this is a very strange URL. The whole stuff from "http" to "td=6" is
the URL, you need it all!)

http://heron.cc.ukans.edu/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/@
Generic__BookTextView/27318;cd=7;td=6

Also, there is a tool around by Nieminen Mika that does exactly this: Read
POV-Ray triangles, calculate the normals and output POV-Ray smooth
triangles. The URL used to be
http://www.iki.fi/warp/PovUtils/smooth.html
But it seems to be down now...

Johannes.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.