Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
66 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

Contents
 Vectors
 Vector Operations
 Planes

 Printable version
 Discuss this article
 in the forums


The Series
 Introduction
 Vectors and Planes

What is a Plane?

A plane is like a huge piece of paper. Each triangle making up our models lies in its own plane.

ax + by + cz + d = 0

The above equation describes our plane. The < a, b, c > triplet describes the normal of our plane. The normal is the vector which is perpendicular to all of the points which lie on the plane. We learned how to calculate the normal when we were learning about the cross product. The d component is a scalar value which represents the distance from the plane to the origin < 0x, 0y, 0z >. The triplet < x,y,z > is the point which solves the equation. You will understand this in a moment.


Figure 7. Example of plane

In this diagram, the normal points away from the origin, so the distance is negative. If the normal pointed toward the origin, the distance would be a positive value. Obviously if the plane goes through the origin then the distance would be equal to zero.

Constructing a Plane

// global variables
Vector norm;
float  distance;

void ConstructPlane( Vector &p0, Vector &p1, Vector &p2 )
{
  norm = CrossProduct( SubVect(p2 ,p1), SubVect( p0,p1) ); 
  norm = Normalize(norm);
  distance = -DotProduct( norm, p1 );
}

Not too complicated; all we are doing here is performing a cross product on the two vectors which are made up of the three points. We do this to find the normal and then we make it unit length. To find the distance we calculate the negative dot product of the normal with the point of your choice.

Defining the location of a point in relation to a plane

Defining the location of a point in relation to a plane is one of the most common operations we can do with planes. There are three possible cases when perfoming this operation. They are: front of the plane, back of the plane, and coplanar with the plane. So, how do we tell the difference between the front of the plane and the back of the plane? The front is defined as the side which the normal sticks out of, so obviously the back of the plane is the opposite side.


Figure 8. Point Classification

V ● N + D

Looking at Figure 8, we can see that vector V is at the back of the plane. How did we come to this conclusion? We find the dot product of our vector V with the normal and add the distance. If we get a negative value returned then the point is behind the plane and if we get a positive value, the point is in front of the plane. If the point lies on the plane then it is coplanar.

The returned value is the distance from the plane. Remember that if that value is equal to zero than we are indeed coplanar with the plane.

Conclusion

If you have made it this far then well done. Compared to what we have ahead of us this stuff is relatively simple but those who haven’t studied vector math before may find it a little confronting. Don’t worry to much, once you start using this stuff more everything will fall into its place. Next time we dwelve into the mysteries of the matrix. Well I guess this is goodbye, I’ll see you next time.

Love me? Hate me? Questions? Suggestions? How about you e-mail me here.