Computing a normal to triangle

1.7k Views Asked by At

The normal to surface is just a vector that is prependicular to the surface in particular point, right? So normale to the triangle is a vector perpendicular to his plane?

I have a triangle, for example

A(1, 1, 1), B(4, 2, 1), C(3, 1, 5).

And I have a formulas to compute the normal, but I do not understand them, I haven't intuition about it. Can someone explain those formulas to me, or give some hints?

a_dx = B.x - A.x

a_dy = B.y - A.y

a_dz = B.z - A.z

b_dx = C.x - A.x

b_dy = C.y - A.y

b_dz = C.z - A.z

ab_1 = a_dy * b_dz - a_dz * b_dy

ab_2 = a_dz * b_dx - a_dx * b_dz

ab_3 = a_dx * b_dy - a_dy * b_dx

Length = sqrt(ab_1^2 + ab_2^2 + ab_3^2)

normal.x = ab_1 / Length

normal.y = ab_2 / Length

normal.z = ab_3 / Length 

normalAzimuth = atan2(normal.y, normal.z);
normalElevation = atan2(normal.x, normal.z);

atan2 - arc tangent.

1

There are 1 best solutions below

0
On BEST ANSWER

The code is computing the normal by calculating the cross product of the vectors (B-A) x (C-A), then dividing by the length to make sure it has a length of 1.