 |
|
3D Maths for CG
Index
Vectors Cross Product Dot Product Vector Projection
Lines Rays and Planes Lines and Rays Planes
Intersection Ray Sphere Intersecion Ray Triangle Intersection
Interpolation Catmull-Rom Spline
OpenGLTutorials @ Lighthouse3d.com
Led Shader
View Frustum Culling
GLSL Tutorial
Maths Tutorial
Billboarding Tutorial
Picking Tutorial
Terrain Tutorial
Display Lists Tutorial
GLUT Tutorial
|
|
 |
|
3D Maths for CG
Planes
A 3D plane can be defined in many ways, however all of them can be derived from the simple case where we have three points.
One of the most common ways to define a plane is with the following equation:
Ax + By + Cz + D = 0
Assuming three points p0, p1, and p2 the coefficients A, B, C and D can be computed as follows:
Compute vectors v = p1 - p0, and u = p2 - p0;
Compute n = v x u (cross product)
Normalize n
Assuming n = (xn,yn,zn) is the normalized normal vector then
To compute the value of D we just use the equation above, hence -D = Ax + By + Cz
From the above point, and replacing (x,y,z) for a point in the plane (for instance p0), we get D = - n . p0 (dot product).
The following figure presents all the intervenients in this process.
Distance from a point to a plane
Assuming that the equation Ax + By + Cz + D = 0 has been obtained as shown above then the distance from the plane to a point r can be obtained just by computing the left side of equation, or
n . r + D = 0
In fact the distance is the absolute value of dist, but the sign of dist (if it is zero is on the plane) also gives information as to which side of the plane is point r. If the sign is positive then the point is on the side that agrees with the normal n, otherwise it is on the other side.
Projecting a point to a plane
The projection of a point q on a plane defined by Ax + By + Cz + D = 0 is the point on the plane that is closest to q.
Assume that dist is the signed distance from q to the plane. Then the closest point p on the plane is:
p = q - dist * n
|