Mail Archives: djgpp/1997/05/14/09:47:21
From:  Shawn Hargreaves <shawn AT talula DOT demon DOT co DOT uk>

To:  djgpp AT delorie DOT com

MMDFWarning:  Parse error in original version of preceding line at punt2.mail.demon.net

Subject:  Re: cross_product()  Allegro

Date:  Wed, 14 May 1997 09:06:13 +0100

MIMEVersion:  1.0

MessageID:  <863609349.097651.0@[194.129.18.166]>

KaRNaGE writes:
> i was wondering how i could use cross_product() to get the normal of a
> vector (x, y, z)...and the normal of a face (triangle)...thankz...
A vector doesn't have a normal, or rather it has an infinite number of
them. Think about it: a normal is just a line at right angles to something
else, and in 3d there are a lot of different ways to arrange two lines so
they are perpendicular!
The cross product returns a vector that is perpendicular to both of two
input vectors. If you have a triangle, use two of its edges as the input
vectors, eg. for the triangle x1,y1,z1, x2,y2,z2, x3,y3,z3, the normal is:
fixed xnormal, ynormal, znormal;
cross_product(x2x1, y2y1, z2z1,
x3x2, y3y2, z3z2,
&xnormal, &ynormal, &znormal);
And there you have your normal. There are obviously two possible results
for any single polygon: which one you get will be determined by whether
your vertices were stored in a clockwise or anticlockwise direction (to get
the other normal, just negate the output vector).

Shawn Hargreaves  shawn AT talula DOT demon DOT co DOT uk  http://www.talula.demon.co.uk
Beauty is a French phonetic corruption of a short cloth neck ornament
 Raw text 