Here we present several basic methods for representing planes in 3D space, and how to compute the distance of a point to a plane.
Planes
A surface is that which has length and breadth only. [Book I, Definition 5] The extremities of a surface are lines. [Book I, Definition 6] A plane surface is a surface which lies evenly with the straight lines on itself. [Book I, Definition 7]
If two straight lines cut one another, they are in one plane, and every triangle is in one plane. [Book XI, Proposition 2]
If two planes cut one another, their common section is a straight line. [Book XI, Proposition 3]
From the same point two straight lines cannot be set up at right angles to the same plane on the same side. [Book XI, Proposition 13] [Euclid, 300 BC]
Although Euclid defined a plane in Book I as the third primitive after the point and line, he did not prove anything about planes until much later in Book XI. And even then, he did not appeal to the definition from Book I in his proofs of Propositions in Book XI [Heath, 1956]. In modern times, [Coxeter, 1989a] has given a more exact definition of a plane as:
Definition. If A, B, C are three noncollinear points, the plane ABC is the set of all points collinear with pairs of points on one or two sides of the triangle ABC.
which is used to prove properties of incidence in a plane. Nevertheless, Euclid's Propositions XI.2 and XI.13 make it clear the Greeks knew that a plane is uniquely determined by any of the following data:
 by three noncollinear points,
 by two straight lines meeting one another,
 by a straight line and a point not on that line, and
 a point and a line perpendicular to the plane.
Plane Equations
Implicit Equation
Thus, there are many ways to represent a plane P. Some methods work in any dimension, and some work only in 3D. In any dimension, one can always specify 3 noncollinear points , , as the vertices of a triangle, the most primitive planar object. In 3D, this uniquely defines the plane of points satisfying the implicit equation:
represented as a determinant.
Normal Implicit Equation
In 3 dimensions, another popular and useful representation for a plane P is the normal form that specifies an origin point V_{0} on P and a “normal” vector n which is perpendicular to P . This representation is useful for computing intersections, resulting in compact and efficient formulas. But, this representation only works in 3D space. In a higher ndimensional space, this representation defines an (n–1)dimensional linear subspace. We will not pursue this further here except to say that many of the results for planes in 3D carry over to hyperplanes of nD space (see [Hanson, 1994] for further information).
In 3D, a normal vector n for P can be computed from any triangle of points on P as the crossproduct . Then, any point P on the plane satisfies the normal implicit equation:
For , and d = –(n · V_{0}), the equation for the plane is:
So, the xyzcoefficients of any linear equation for a plane P always give a vector which is perpendicular to the plane. Also, when d = 0, the plane passes through the origin 0 = (0,0,0).
It is often useful to have a unit normal vector for the plane which simplifies some formulas. This is easily done by dividing n by n. Then, the associated implicit equation is said to be “normalized”. Further, when n = 1, the coordinates of n are also the direction cosines of the angles that the vector n makes with the xyzaxes. Additionally, d is then the perpendicular distance from the origin 0 to the plane, as we will show in the next section.
Parametric Equation
Also in any dimension, similar to the parametric line equation, one can replace either or both of the two specified points V_{1} and V_{2} by direction vectors and . Then, given one point V_{0} on P and two nonparallel line direction vectors u and v, there is a natural parametric equation for ponts on the plane P ; namely:
where s and t are real numbers which are coordinates within the plane relative to the origin V_{0} and the basis vectors u and v. And, when , , and , then is inside the triangle T = .
The pair of parameters (s,t) is referred to as the parametric coordinate of relative to T. The point P is on an edge of T whenever one of the conditions s = 0, t = 0, or s + t = 1 is true (each condition corresponds to one edge). And, the vertices of T are given by: , , and .
Barycentric Coordinates
A similar representation is given by the barycentric coordinates [Coxeter, 1989b] of a point P relative to the triangle T = . This method associates a triple (b_{0},b_{1},b_{2}) with the centroid of three masses b_{0}, b_{1}, and b_{2} located at the triangle's three vertices. Negative numbers are treated as negative masses (like helium balloons). This gives:
The triple (b_{0},b_{1},b_{2}) is called a “homogeneous barycentric coordinate” for points P relative to the triangle T. The normalized triple (a_{0},a_{1},a_{2}) satisfying is called the “areal barycentric coordinate” of P. Clearly when , and thus any triple (a_{0},a_{1},a_{2}) which sums to 1 is a valid areal coordinate. Further, there is a onetoone correspondence between areal coordinates and all points on the plane P . This can be seen by noting the equivalence of areal barycentric and parametric coordinate representations gotten by setting: a_{0} = (1–s–t), a_{1} = s, and a_{2} = t.
Areal coordinates have a number of useful properties with respect to the triangle T. For example, the point P lies inside T only when all components of its areal barycentric coordinate are nonnegative, that is , , and . Further interesting properties, especially ones related to area ratios, are given by [Coxeter, 1989b].
Representation Conversions
One can convert from any of these representations to another when convenient. For example, given two direction vectors for lines on a plane, their crossproduct gives a normal vector. Conversely, given a normal vector, one can easily find two other independent vectors perpendicular to it. For example, given with , then u = (–b, a, 0) and v = (–c, 0, a) are perpendicular to n since both n · u = 0 and n · v = 0. Further, three noncollinear points on the plane are: V_{0}, V_{0 }+ u, and V_{0 }+ v. Most other conversions are at least as easy as these. But, one conversion is a bit more difficult; namely, finding the parametric or barycentric coordinates relative to a given triangle.
Barycentric Coordinate Computation
We want to find the parametric or barycentric coordinates (defined above) of a given 3D point relative to a triangle T = in the plane. We start by putting and as before, as well as . Then, we find the parametric coordinates (s, t) of P as the solution of the equation: . This solution exists and is unique whenever P lies in the plane of T. Further, the areal barycentric coordinates of are: a_{0 }= (1–s–t), a_{1 }= s, and a_{2} = t which satisfy: .
To solve the equation , we first define a 3D generalization of Hill's “perp operator” [Hill, 1994].
Definition. Given a 2D plane P embedded in 3D space with a unit normal vector n, and given any vector v in the plane (that is, v satisfies n · v = 0), define the “generalized perp operator” on P by: .
Then, is another vector in the plane P (since ), and it is also perpendicular to v (since ). Additionally, this embedded perp operator is linear for vectors in P ; that is, where v and w are vectors in P, and a and b are scalar numbers. Also, if P is the 2D xyplane (z = 0) with n = (0,0,1), then our 3D perp operator is exactly the same 2D perp operator given by [Hill, 1994]; since we have: .
We will now solve the equation: for s and t. First, take the dot product of both sides with to get , and solve for s. Similarly, taking the dot product with , we get: , and solve for t. Then we have:




and




The denominators are nonzero whenever the triangle T is nondegenerate (that is, has a nonzero area). When T is degenerate, it is either a segment or a point, and in either case does not uniquely define a plane.
Altogether we have used 3 cross products (one to compute ) which is a lot of computation. But, we can simplify this with the formula for left association of the cross product; namely, for any three 3D vectors a, b, and c, then . [Note: the cross product is not associative, and so there is a different (but similar) formula for right association]. Applying this formula results in the simplifications:
We can now compute the solutions for s and t using only dot products as:
with 5 distinct dot products. The two denominators are the same and only need to be calculated once.
Distance of a Point to a Plane
The distance d(P_{0},P) from an arbitrary 3D point to the plane P given by , can be computed by using the dot product to get the projection of the vector onto n as shown in the diagram:
which results in the formula:
When n = 1, this formula simplifies to:
showing that d is the distance from the origin 0 = (0,0,0) to the plane P .
This formula gives a signed distance which is positive on one side of the plane and negative on the other. So, one has to take the absolute value to get an absolute distance. Otherwise, the distance is positive for points on the side pointed to by the normal vector n. Because of this, the sign of d(P_{0},P) can be used to simply test which side of the plane a point is on. For example, if is a finite line segment, then it intersects P only when the two endpoints are on opposite sides of the plane; that is, if . Conversely, when , there cannot be an intersection. Also, if , then at least one of the endpoints is on P. When both points are on P , the whole segment lies in the plane.
To compute the distance to a plane P , we did not calculate the base point of the perpendicular from the point P_{0} to P , which some authors do. If one just wants the distance, then directly computing it without going through an intermediate calculation is fastest.
Nevertheless, there are situations where one wants to know the orthogonal (perpendicular) projection of P_{0} onto P . It can be computed by taking a line through P_{0} that is perpendicular to P (that is, one which is parallel to n), and computing it's intersection with the plane. The simplest such line is given by: . This line intersects P when P(s) satisfies the equation of the plane; namely, . Solving this for s at the intersection point, we get:
And the base of the perpendicular is the intersection point:
For the special case when P_{0 }= 0 = (0,0,0), one has as the orthogonal projection of the origin onto the plane. Then , and when n is a unit normal .
Implementations
Here are some sample "C++" implementations of these algorithms.
// Copyright 2001 softSurfer, 2012 Dan Sunday // This code may be freely used and modified for any purpose // providing that this copyright notice is included with it. // SoftSurfer makes no warranty for this code, and cannot be held // liable for any real or imagined damage resulting from its use. // Users of this code must verify correctness for their application.
// Assume that classes are already given for the objects: // Point and Vector with // coordinates {float x, y, z;} // operators for: // Point = Point ± Vector // Vector = Point  Point // Vector = Scalar * Vector (scalar product) // Plane with a point and a normal vector {Point V0; Vector n;} //===================================================================
// dot product (3D) which allows vector operations in arguments #define dot(u,v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z) #define norm(v) sqrt(dot(v,v)) // norm = length of vector #define d(P,Q) norm(PQ) // distance = norm of difference
// dist_Point_to_Plane(): get distance (and perp base) from a point to a plane // Input: P = a 3D point // PL = a plane with point V0 and normal n // Output: *B = base point on PL of perpendicular from P // Return: the distance from P to the plane PL float dist_Point_to_Plane( Point P, Plane PL, Point* B) { float sb, sn, sd;
sn = dot( PL.n, (P  PL.V0)); sd = dot(PL.n, PL.n); sb = sn / sd;
*B = P + sb * PL.n; return d(P, *B); } //===================================================================
References
Donald Coxeter, "Planes and Hyperplanes" in Introduction to Geometry (2nd Edition) (1989)
Donald Coxeter, "Barycentric Coordinates" in Introduction to Geometry (2nd Edition) (1989)
Euclid, The Elements, Alexandria (300 BC)
Andrew Hanson, "Geometry for NDimensional Graphics" in Graphics Gems IV (1994)
Thomas Heath, The Thirteen Books of Euclid's Elements, Vol 1 (Books I and II) (1956)
Thomas Heath, The Thirteen Books of Euclid's Elements, Vol 3 (Books XXIII) (1956)
Francis Hill, "The Pleasures of 'Perp Dot' Products" in Graphics Gems IV (1994)
