POV-Ray : Newsgroups : povray.general : Normal of a triangle : Re: Normal of a triangle Server Time
30 Jul 2024 00:21:24 EDT (-0400)
  Re: Normal of a triangle  
From: clipka
Date: 26 Mar 2010 12:09:02
Message: <4bacdc1e$1@news.povray.org>
MadKairon schrieb:
> I have 3 vectors (V1,V2 and V3)
> 
> I can use them to draw a triangle:
> 
> triangle {V1,V2,V3 pigment { rgb <0,1,0> } }
> 
> Now I need to find the normal of that triangle. I suck at maths so help will be
> appreciated :S

* Take two arbitrary vectors along the triangle plane - the edges are 
ideally suited for this purpose ;-):

     #declare A = V2-V1;
     #declare B = V3-V1;

* Compute the cross product, which will give you a vector perpendicular 
to the two vectors (its length will depend on the length of the vectors 
and the angle between them):

     #declare C = vcross(A,B);

* Normalize the result to get a unit-length vector:

     #declare N = vnormalize(C);

* Voila!

Make sure that the three vertices of the triangle are in the right 
order, as this will determine whether the resulting vector will point 
inwards or outwards.

Also make sure your triangles are all "sane", i.e. all vertices are at 
different coordinates. But you probably guessed this constraint already ;-)


Post a reply to this message

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