Of Planes and Triangles

Planes

A plane is a flat two-dimensional surface that extends infinitely in both directions. The well known standard plane is the Cartesian product , the points of the plane, or its elements, are of the form , where .

Two-Dimensional Subspaces

Now consider the standard three-dimensional Euclidean vector space equipped with the standard euclidean scalar product , i.e. for two vectors and , the scalar product is .

Linear Independence

Two vectors are called linearly independent if, and only if, the following holds:

or, in other words, if the only representation of the zero vector is trivial.

Obviously, an analogous definition is valid in arbitrary dimensions.

Geometrically speaking, linearly independent vectors are sufficient to completely describe an -dimensional space, i.e. two linearly independent vectors are sufficient to completely describe a plane. Just imagine a person describing the location of his favourite restaurant: “Go three kilometres to the east and four kilometres to the north from here.” The vectors east and north are linearly independent, thus completely sufficient to describe the position of every element in the entire plane. Such vectors are also called a generating system for the vector space, or a basis of the vector space.

The three vectors , and are obviously linearly independent and are the standard basis vectors for the standard three-dimensional vector space .

Orthogonality

Two vectors are said to be orthogonal, or perpendicular, if, and only if, .

Space Representations

Parametric Description

As two-dimensional subspaces of the three-dimensional Euclidean space, a plane can be described in various ways. The most common description is a parametric form using a point and two vectors: where , with and linearly independent, and (read is the set of all vectors in that can be written in the form , for certain real numbers and ). Basically speaking, is the position vector of an arbitrary, but fixed point on the plane and the vectors and are vectors with origin and pointing in different directions (recall the example from above: the linearly independent vectors and are sufficient to explain how to get to any location starting at the point ). The following image is taken from Wikipedia:

Normal Form

The preferred way to define a plane in a game engine, however, is analogous to how lines are described in two dimensions, namely using a point-slope form. In the three-dimensional space, planes have a natural description using a point in the plane and a vector orthogonal to it, its so-called normal vector, to indicate its inclination.

Let be the position vector of an arbitrary, but fixed point in space and be a normalized non-zero vector, then the plane defined by and consists of all the vectors , such that the vector , i.e. the vector joining the points defined by and , is perpendicular to the vector . Recalling that two vectors are perpendicular if, and only if, , where is the standard Euclidean scalar product, the above idea leads to the following equation for a plane: . Using the bilinearity of the scalar product, we find that the plane can be described as the set of all vectors solving the following equation: , where can be interpreted as the minimum distance between the plane and the origin of the Euclidean space.

The following figure is once again taken from Wikipedia:

Computing the normal vector of a plane

If a plane is given by its parametric form, , then the normal vector is the normalized outer product of the vectors and , written as , or . As above, let and denote the standard basis of , then the outer product can be computed as follows:

Or, if you don’t like tensors, you can cheat a little bit:

The Normal Vector of Triangles

Now why is this so important in games? Well, especially in a 3D engine, which we will eventually elaborate on later in these tutorials, most game objects are rendered using plenty of triangles. Modern GPUs love drawing triangles, and thus polygons are triangulated into triangles (sic!). What do triangles have to do with planes, however? Well, the three points defining a triangle are always in the same plane, i.e., a triangle is always guaranteed to lie on a single plane — at least in standard Euclidean geometry. Thus, knowing the vertices of a triangle, it is easily possible to compute the plane the triangle lies in, which then in return allows for an easy decision whether a given vector lies in the same plane as the triangle, or not.

Another significant application of the above theory becomes apparent when trying to approximate real-world physics by a discrete model, for example when trying to model how light is reflected from a surface. When attempting to reflect light from a surface, the normal vector of that surface must be known. Thus, knowing that game objects can be rendered using triangles, it is essentially important to be able to compute the normal vector of a triangle? Alas, since the three vertices of a triangle define a plane, the same technique as above can be used.

Let , and be the three vertices of a triangle, in clockwise ordering (we will talk about why the ordering is critical in another tutorial), and let be the vector from to and be the vector from to , then the normal vector of the triangle is . To get the equation of the plane the triangle lives in, all that is left to do is to compute the distance of the plane to the origin of the three-dimensional space, , where can be substituted by any of the three vertices of the triangle, or rather, their position vectors.

Example

As an example of the above theory, let , and be the three vertices of a triangle in the standard Euclidean space . To compute the normal vector of the triangle (or of the plane the triangle lives in), the vectors joining and as well as and must be computed first: and . Now we can compute the outer product of these two vectors: .

The normal vector is the normalized outer product of those two vectors: .

To compute the distance to the origin of the three-dimensional space, any one of the three vertices of the triangle can be used: , where is the position vector of the point . (Making a difference between vectors and points is just of cosmetic nature in this example.)

Finally, the normal-form equation of the plane the triangle lives in can be written as , which means that the triangle lies in the plane defined by all vectors which are perpendicular to the third base vector of the three-dimensional space, which is clearly correct, by construction.

References

• Game Programming Algorithms and Techniques, by Sanjay Madhav
• Lineare Algebra, by Prof. Dr. R. Scharlau
• Tricks of the Windows Game Programming Gurus, by André LaMothe
• Wikipedia