I am trying to find the parallel projection matrix to project a 3D arbitrary point to an plane of equation ax+by+cz+d=0. I would like to project my 3D points to the plane, parallel to the normal of the plane. I know how to do it in a classical way but I heard about homogeneous matrix. I found a lot of information on perspective projection matrix but I am a little bit lost, and don't know how to apply that to my problem..
Any help ?
thanks
Although you'll be starting with the plane equation in the form Ax + By + Cz + D = 0
, you'll first want to define a local coordinate system that allows you to use a parametric equation of the plane.
The parametric equation of the plane we're interested in requires you to write it in the form of some origin Q
(any point on the plane) plus the coordinate u
times some vector U
in the plane, plus the coordinate v
times some vector V
also in the plane, but not colinear with U
plus the coordinate n
times the normal vector N
= (A,B,C)
.
Q + uU + vV + nN
If you had these u,v,n
coordinates, you would perform your operation of projecting all points in space onto the plane by simply setting their n
coordinate to zero and keeping their u
and v
coordinates as is.
So we will start with a matrix that can transform from the local coordinate system (local to the plane) in u,v,n
to the global coordinate system in x,y,z
coordinates. This is really straightforward to write as a 4x4 homogeneous matrix.
[ Ux Vx Nx Qx ] G = [ Uy Vy Ny Qy ] [ Uz Vz Nz Qz ] [ 0 0 0 1 ]
(Reminder that Nx = A
Ny = B
and Nz = C
.)
Call this matrix G
(for "global"). The inverse G⁻¹
would transform from global back to local coordinates.
Our matrix F
(for "flatten") that squashes the n
coordinate to zero is simply:
[ 1 0 0 0 ] F = [ 0 1 0 0 ] [ 0 0 0 0 ] [ 0 0 0 1 ]
So now we can construct your matrix M
that begins by transforming from global to local coordinates with G⁻¹
, then flattening it to the plane with F
, then transforming from local to global coordinates with G
. (Remember the order is reversed for matrices because the vector goes on the right.)
M = GFG⁻¹
That's a 4x4 matrix formed by G
multiplied by F
multiplied by G⁻¹
.
There were two steps I skipped.
Q
in the plane.U
and V
We can choose any origin for the parametric definition of the plane because we won't be using the u
or v
coordinates.
To find a point Q
in the plane to use as its origin, we can find where the plane intersects either the X, Y or Z axis. (It will hit one of those). Simply use any non-zero coordinate of the normal vector. This is like substituting the point (0,0,z)
into the plane equation Ax + By + Cz + D = 0
and solving for z
. There are three potentially appropriate points depending on which coordinate was non-zero.
(0, 0, -D/C)
(0, -D/B, 0)
(-D/A, 0, 0)
To choose vectors for U
and V
(they don't actually have to be unit vectors) you just have to choose vectors that are in the plane that are not colinear.
To choose a U
vector, we can take any vector and take the cross product of that vector and the normal. The result will be a vector in the plane. We just have to make sure this cross product does not result in a zero-length vector. In other words, the "any vector" we choose must not be colinear with the normal. We can select one of:
X̂ = (1, 0, 0)
Ŷ = (0, 1, 0)
Ẑ = (0, 0, 1)
e.g.: U = N × X̂
One of the above choices will be appropriately not colinear with the normal vector. Check that the cross product is not zero-length before carrying on.
Then, to get the V
vector, we simply take V = N × U
(cross product). Again, none of these vectors have to be unit vectors because we don't care about the u
and v
coordinates and we don't care about the magnitude of the n
coordinate because we're just going to squash it to zero anyway.
So it's a few steps to construct the matrix, but hopefully this outlines all the work you have to do to get it. Then you can just multiply any point P
by the matrix to project it onto the plane.
eg.: P' = MP
Hopefully you're comfortable enough using a 4x4 matrix, and of course, supplying your vectors that you want to transform in homogenous form, which is a 4-vector with coordinates (x,y,z,1)
.