Matthew,
You can construct two vectors (Vector3d's in java) from the 3 points (A, B,
and C).  The normal is simply the cross product of these (normalized)
vectors.  Remember that the cross product of 2 vectors is a vector that is
perpendicular to both of these vectors.
    vector1 = new Vector3d(C.x - A.x, C.y - A.y, C.z - A.z);
    vector2 = new Vector3d(B.x - A.x, B.y - A.y, B.z - A.z);
    vector1.normalize();
    vector2.normalize();
    normal = new Vector3d();
    normal.cross(vector1, vector2);

If the normal turns out to face the wrong way, either negate it or reverse the
order of the cross product (i.e. normal.cross(vector2, vector1);).

Hope this helps,
-guillermo
[EMAIL PROTECTED]

Matthew Warren wrote:

> Hello,
>
> I have a situation where I need to calculate the normals of a surface for
> shading.
>
> The surface is represented as an [][] of hieght values, and because of this
> I believe I cannot use the triangulate and generatenormals classes as the
> triangulate class may not always return the surface I need.
>
> So, I can generate my own TriangleStripArray from the data but need to
> calculate the normal for each triangle. I have just made a quick search of
> the net and so far have only found lecture notes and papers etc. that talk
> about it a lot, but dont actually tell you how to do it...
>
> I imagine the code is quite simple, given 3 points determining a triangle.
>
> If someone could tell me the either the code to do it, or the math formula
> to compute the normal I would be very grateful.
>
> Thanks,
>
> Matthew.
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
begin:vcard
n:Gutierrez;Guillermo
tel;fax:407-984-6323
tel;work:407-984-6543
x-mozilla-html:TRUE
org:Harris Corporation;GCSD
adr:;;;;;;
version:2.1
email;internet:[EMAIL PROTECTED]
title:Software Engineer
x-mozilla-cpt:;-19648
fn:Guillermo Gutierrez
end:vcard

Reply via email to