POV-Ray : Newsgroups : povray.general : Calculating normals Server Time
31 Oct 2024 21:30:57 EDT (-0400)
  Calculating normals (Message 1 to 7 of 7)  
From: Remco de Korte
Subject: Calculating normals
Date: 1 Jan 2000 09:25:15
Message: <386E0DD0.9753804C@xs4all.nl>
I thought I'd find this in a FAQ but I couldn't.
I know it's been discussed in the newsgroups more then once but I
couldn't find those threads either, so here it goes:

How do I calculate the normal for a triangle?

I know this isn't really very difficult and there are several ways. I'd
like to be able to understand this. How would I do it, without using the
POV-statements or a matrix?

Thanks in advance,

Remco


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Calculating normals
Date: 1 Jan 2000 09:39:41
Message: <386e11ad@news.povray.org>
In article <386E0DD0.9753804C@xs4all.nl> , Remco de Korte 
<rem### [at] xs4allnl>  wrote:

> I thought I'd find this in a FAQ but I couldn't.
> I know it's been discussed in the newsgroups more then once but I
> couldn't find those threads either, so here it goes:
>
> How do I calculate the normal for a triangle?
>
> I know this isn't really very difficult and there are several ways. I'd
> like to be able to understand this. How would I do it, without using the
> POV-statements or a matrix?

An easy way is using the following vector math, POV-Ray has all the
functions you need:

A triangle with the points P1,P2,P3.
Get two vectors, A and B where A = P2-P1 and B = P3-P1.
Now you can find the normal which is simply N = A x B.
You may want to normalise the vector with N0 = N : |N|

In POV-Ray this would look like this (not tested, insert your data):

#declare P1 = <...>;
#declare P2 = <...>;
#declare P3 = <...>;

#declare A = P2 - P1;
#declare B = P3 - P1;

#declare N = vcross(A, B);
#declare N0 = vnormalize(N);


    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Remco de Korte
Subject: Re: Calculating normals
Date: 1 Jan 2000 09:56:47
Message: <386E1535.F3FA99E2@xs4all.nl>
Thorsten Froehlich wrote:
> 
> In article <386E0DD0.9753804C@xs4all.nl> , Remco de Korte
> <rem### [at] xs4allnl>  wrote:
> 
> > I thought I'd find this in a FAQ but I couldn't.
> > I know it's been discussed in the newsgroups more then once but I
> > couldn't find those threads either, so here it goes:
> >
> > How do I calculate the normal for a triangle?
> >
> > I know this isn't really very difficult and there are several ways.
> I'd
> > like to be able to understand this. How would I do it, without using
> the
> > POV-statements or a matrix?
> 
> An easy way is using the following vector math, POV-Ray has all the
> functions you need:
> 
> A triangle with the points P1,P2,P3.
> Get two vectors, A and B where A = P2-P1 and B = P3-P1.
> Now you can find the normal which is simply N = A x B.
> You may want to normalise the vector with N0 = N : |N|
> 
> In POV-Ray this would look like this (not tested, insert your data):
> 
> #declare P1 = <...>;
> #declare P2 = <...>;
> #declare P3 = <...>;
> 
> #declare A = P2 - P1;
> #declare B = P3 - P1;
> 
> #declare N = vcross(A, B);
> #declare N0 = vnormalize(N);
> 
>     Thorsten

Wow, that's fast!
The first part is something I had sort of figured out by myself
(although I wasn't really sure). The second part I can understand, but
I'd like to know how to calculate them without using the POV-functions.
I've been trying to set up a macro in POV using this but it took days
(!) to parse, so now I'm trying to do it in an external program. After
that I might be able to find some shortcuts and get it back to a
POV-macro but I'm not too sure.
Thanks for yor help anyway, it might still do the trick (I know how to
calculate vcross, I'm not too sure about vnormalize for 3D-vectors...)

Best wishes,

Remco


Post a reply to this message

From: Nieminen Juha
Subject: Re: Calculating normals
Date: 1 Jan 2000 10:48:15
Message: <386e21bf@news.povray.org>
Remco de Korte <rem### [at] xs4allnl> wrote:
: Thanks for yor help anyway, it might still do the trick (I know how to
: calculate vcross, I'm not too sure about vnormalize for 3D-vectors...)

  Normalizing a 3D-vector is exactly like normalizing a 2D-vector: Divide its
components by the length of the vector.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Remco de Korte
Subject: Re: Calculating normals
Date: 1 Jan 2000 11:04:00
Message: <386E24EA.E3413CC1@xs4all.nl>
Nieminen Juha wrote:
> 
> Remco de Korte <rem### [at] xs4allnl> wrote:
> : Thanks for yor help anyway, it might still do the trick (I know how
> to
> : calculate vcross, I'm not too sure about vnormalize for
> 3D-vectors...)
> 
>   Normalizing a 3D-vector is exactly like normalizing a 2D-vector:
> Divide its
> components by the length of the vector.
> 
> --

I think I confused terms here.
I know how to normalize a vector (as you describe), i _don't_ know hot
to calculate VCROSS (I mistook it for caclulating the average).
So, again: how to calculate a normal?

Remco


Post a reply to this message

From: Nieminen Juha
Subject: Re: Calculating normals
Date: 1 Jan 2000 11:24:33
Message: <386e2a41@news.povray.org>
Remco de Korte <rem### [at] xs4allnl> wrote:
: I know how to normalize a vector (as you describe), i _don't_ know hot
: to calculate VCROSS (I mistook it for caclulating the average).
: So, again: how to calculate a normal?

  The cross-product of two vectors <x1,y1,z1> and <x2,y2,z2> can be
calculated this way:

|  i  j  k |
| x1 y1 z1 | = (y1*z2-y2*z1)i + (x2*z1-x1*z2)j + (x1*y2-x2*y1)k
| x2 y2 z2 |

ie:

  <y1*z2-y2*z1, x2*z1-x1*z2, x1*y2-x2*y1>

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Remco de Korte
Subject: Re: Calculating normals
Date: 1 Jan 2000 11:49:45
Message: <386E2FAB.E641FD10@xs4all.nl>
Nieminen Juha wrote:
> 
> Remco de Korte <rem### [at] xs4allnl> wrote:
> : I know how to normalize a vector (as you describe), i _don't_ know
> hot
> : to calculate VCROSS (I mistook it for caclulating the average).
> : So, again: how to calculate a normal?
> 
>   The cross-product of two vectors <x1,y1,z1> and <x2,y2,z2> can be
> calculated this way:
> 
> |  i  j  k |
> | x1 y1 z1 | = (y1*z2-y2*z1)i + (x2*z1-x1*z2)j + (x1*y2-x2*y1)k
> | x2 y2 z2 |
> 
> ie:
> 
>   <y1*z2-y2*z1, x2*z1-x1*z2, x1*y2-x2*y1>
> 
> --
> 

Thanks! 
Actually I already found the information I needed just a couple of
minutes ago.

Where?

In your mesh-smoother 8)

Remco


Post a reply to this message

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