POV-Ray : Newsgroups : povray.general : Calculate normal vector? Server Time
1 Aug 2024 18:20:54 EDT (-0400)
  Calculate normal vector? (Message 11 to 14 of 14)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Thorsten Froehlich
Subject: Re: Calculate normal vector?
Date: 26 Sep 2008 02:12:58
Message: <48dc7d6a$1@news.povray.org>
B. Gimeno wrote:
> Greetings,
> I hope that no one feels annoyed about this repetitive question automatically
> translated, but I'm stuck at the point of finding the normal to a given
> triangle. I've read and re-read the answers given in this forum but I keep
> stopping with this.
> 
> A triangle whose vertex are generated by a nested while-loop. (v1,v2,v3)
> 
> I attempt to find the normal by normalizing the product of vectors:
> 
> #local N = vnormalize(vcross( (v2 - v1) , (v3 - v1) ))  ;
> 
> Then I apply the normal obtained to a smooth_triangle, and the result is uh....
> unsmoothed_triangles.
> 
> smooth_triangle {v1,N,v2,N,v3,N}

What do you expect if all normals are identical? - For a single triangle 
this will never be different...

	Thorsten


Post a reply to this message

From: alphaQuad
Subject: Re: Calculate normal vector?
Date: 26 Sep 2008 13:55:01
Message: <web.48dd20ef92437aab8ea364160@news.povray.org>
everyone has explained it, here's my 2 cents. I have had to do this twice but
not in pov script (yet)

the normal for the vertex is the addition of the normals of all triangles that
share it. but you want a condition that supports limiting to an angle variable,
ideally.

first the triangle normal

#macro normal_vector(A,B,C)
 #local result = vcross(C-B,A-B);
 result
 // 1
 // |
 // 2__ 3 vz points at you (neg) unless reverse y like pov, then
 //
 // 2__ 3
 // |
 // 1
#end

vcrossing 2 vectors is almost never a length of one, unless it is.
normalize for a length of 1.

pov renders 2-sided, so reverse normals are seldom an issue but do it right the
first time, if you want outside vectors, input is clockwise


Post a reply to this message

From: alphaQuad
Subject: Re: Calculate normal vector?
Date: 26 Sep 2008 14:40:01
Message: <web.48dd2b4d92437aab8ea364160@news.povray.org>
the angle function

#macro _clamp(a,n,m)
   #local result = a;
   #if (a < n) #local result = n;  #end
   #if (a > m) #local result = m;  #end
   result
#end

#macro radang2(A,B)
  #declare result =
    acos(_clamp(vdot(vnormalize(A),vnormalize(B)), -1.0, 1.0));
   result
#end
#macro radang3(A,B,C)
   // input is 3 points in 3D -- points to A and C, angle at B
   #declare result =
     acos(_clamp(vdot(vnormalize(A-B),vnormalize(C-B)), -1.0, 1.0));
   result
#end

 parameter range for acos() is -1 to 1, _clamp handles user input error.

angle of 2 vectors:
#if (degrees(radang2(nA,nB)) < "somenumber") add nB to tally for this vert(nA),
normalize.


Post a reply to this message

From: alphaQuad
Subject: Re: Calculate normal vector?
Date: 26 Sep 2008 14:50:00
Message: <web.48dd2e6592437aab8ea364160@news.povray.org>
angle of 2 vectors:
#if (degrees(radang2(nA,nB)) < "somenumber") add nB to tally for this vert(nA),
normalize.

nA was initialized to "this" triangle normal before comapring to adjacent
triangle/planes

AN important part of this variable angle logic, hope this helps in the long run.

nested triangle loops comparing all triangles for adjacency, 3 times for each
vert in ea triangle. If not compiled this would be slow for large objects.


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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