POV-Ray : Newsgroups : povray.general : Normal of a triangle Server Time
30 Jul 2024 00:17:33 EDT (-0400)
  Normal of a triangle (Message 1 to 8 of 8)  
From: MadKairon
Subject: Normal of a triangle
Date: 26 Mar 2010 11:25:00
Message: <web.4bacd18395b6e9475e975f010@news.povray.org>
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

Thanks in advance


Post a reply to this message

From: clipka
Subject: Re: Normal of a triangle
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

From: MadKairon
Subject: Re: Normal of a triangle
Date: 26 Mar 2010 12:25:00
Message: <web.4bacdebb49dbd585e975f010@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
>
> * 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 ;-)

Well... my macro still generates some "insane" triangles but yeah, already
working on fixing it. THANKS A LOT FOR THE HELP!!


Post a reply to this message

From: Warp
Subject: Re: Normal of a triangle
Date: 26 Mar 2010 12:45:25
Message: <4bace4a4@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> * Normalize the result to get a unit-length vector:

>      #declare N = vnormalize(C);

  Actually if you are specifying a normal vector for a triangle in povray,
you don't necessarily have to normalize it.

-- 
                                                          - Warp


Post a reply to this message

From: Charles C
Subject: Re: Normal of a triangle
Date: 26 Mar 2010 14:30:01
Message: <web.4bacfca349dbd58cac4259f0@news.povray.org>
"MadKairon" <nomail@nomail> wrote:
> clipka <ano### [at] anonymousorg> wrote:
> > Also make sure your triangles are all "sane", i.e. all vertices are at
> > different coordinates. But you probably guessed this constraint already ;-)
>
> Well... my macro still generates some "insane" triangles but yeah, already
> working on fixing it. THANKS A LOT FOR THE HELP!!

In your sanity checks I suggest also checking for non-co-linearity. VAngleD(A,B)
Charles


Post a reply to this message

From: Warp
Subject: Re: Normal of a triangle
Date: 26 Mar 2010 16:16:31
Message: <4bad161e@news.povray.org>
Charles C <nomail@nomail> wrote:
> In your sanity checks I suggest also checking for non-co-linearity. VAngleD(A,B)

  The cross-product itself checks for colinearity: If the points are
colinear, the result will be a zero vector.

-- 
                                                          - Warp


Post a reply to this message

From: Charles C
Subject: Re: Normal of a triangle
Date: 26 Mar 2010 22:20:00
Message: <web.4bad6a2949dbd58cac4259f0@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:

>   The cross-product itself checks for colinearity: If the points are
> colinear, the result will be a zero vector.


Good point.
Charles


Post a reply to this message

From: MadKairon
Subject: Re: Normal of a triangle
Date: 27 Mar 2010 19:20:01
Message: <web.4bae923249dbd585e975f010@news.povray.org>
"Charles C" <nomail@nomail> wrote:
> Warp <war### [at] tagpovrayorg> wrote:
>
> >   The cross-product itself checks for colinearity: If the points are
> > colinear, the result will be a zero vector.
>
>
> Good point.
> Charles

Thanks all, I already have a macro working which will translate a vector until
it collides with a solid and then get the normal of the surface where the
collision ocurred... now I need stuff to point to my normal :P I have a macro
for that too but no good. Check my newest thread please!!


Post a reply to this message

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