POV-Ray : Newsgroups : povray.general : Calculate normal vector? : Re: Calculate normal vector? Server Time
1 Aug 2024 20:14:56 EDT (-0400)
  Re: Calculate normal vector?  
From: alphaQuad
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

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