POV-Ray : Newsgroups : povray.general : Calculating the normals of a triangle : Re: Calculating the normals of a triangle Server Time
5 Aug 2024 12:19:41 EDT (-0400)
  Re: Calculating the normals of a triangle  
From: Warp
Date: 11 Sep 2002 08:40:51
Message: <3d7f39d3@news.povray.org>
Marcus Fritzsch <m### [at] fritschyde> wrote:
> i wrote a simple triangulation algo for a noise program to generate 
> something like a hieghtfield, and i wanted to use this with 
> smooth_triangles, does anybody knows how to calculate the normals of the 
> three points from the known triangle?

  There are basically two ways:

  1. If you know the function which was used to generate the mesh and you
can derive the function with respect to x, y and z (or x and y in the
case of a heightfield function f(x,y)), then you can use the gradient
of the function (ie. <df(x,y)/dx, df(x,y)/dy>) to calculate the normal
vector at any point of the function.

  2. If you don't know the function, or the function is not differentiable
(or it's just too difficult to do so), then you can use an approximation
which works quite well for (almost) any mesh: The normal vector at a vertex
point is the sum of all the normal vectors of the triangles sharing that
vertex.
  (The normal vector of a triangle can be calculated with the cross-product
of two of its edges. According to empirical tests, *not* normalizing these
normals gives the best result in the sum described above (because the
dot-product of the two edges of a triangle gives a normal vector which
length is equal to the area of the triangle, and not normalizing this
vector means that a larger triangle has more effect in the normal of the
vertex than other smaller triangles sharing that same vertex, which
reportedly gives better results).)

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

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