Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given 3 points, how do I calculate the normal vector?

Given three 3D points (A,B, & C) how do I calculate the normal vector? The three points define a plane and I want the vector perpendicular to this plane.

Can I get sample C# code that demonstrates this?

like image 499
DenaliHardtail Avatar asked Dec 27 '09 18:12

DenaliHardtail


People also ask

How do you calculate the normal vector?

Unit Normal VectorAny nonzero vector can be divided by its length to form a unit vector. Thus for a plane (or a line), a normal vector can be divided by its length to get a unit normal vector. Example: For the equation, x + 2y + 2z = 9, the vector A = (1, 2, 2) is a normal vector. |A| = square root of (1+4+4) = 3.

How do you find a normal vector from a given line?

The normal form of the equation of a line l in R2 is n · (x - p)=0, or n · x = n · p where p is a specific point on l and n = 0 is a normal vector for l. The general form of the equation of l is ax + by = c where n = [a b ] is a normal vector for l. Example 0.5. Let us find the vector form of the previous example.


2 Answers

It depends on the order of the points. If the points are specified in a counter-clockwise order as seen from a direction opposing the normal, then it's simple to calculate:

Dir = (B - A) x (C - A) Norm = Dir / len(Dir) 

where x is the cross product.

If you're using OpenTK or XNA (have access to the Vector3 class), then it's simply a matter of:

class Triangle {     Vector3 a, b, c;     public Vector3 Normal {         get {             var dir = Vector3.Cross(b - a, c - a);             var norm = Vector3.Normalize(dir);             return norm;         }     } } 
like image 98
Frank Krueger Avatar answered Sep 28 '22 05:09

Frank Krueger


Form the cross-product of vectors BA and BC. See http://mathworld.wolfram.com/CrossProduct.html.

like image 20
Steve Emmerson Avatar answered Sep 28 '22 04:09

Steve Emmerson