Let A be a point for which I have the 3D coordinates x, y, z and I want to transform them into 2D coordinates: x, y. The projection shall be orthogonal on a plane defined by a given normal. The trivial case, where the normal is actually one of the axes, it's easy to solve, simply eliminating a coordinate, but how about the other cases, which are more likely to happen?
If you have your target point P with coordinates r_P = (x,y,z)
and a plane with normal n=(nx,ny,nz)
you need to define an origin on the plane, as well as two orthogonal directions for x
and y
. For example if your origin is at r_O = (ox, oy, oz)
and your two coordinate axis in the plane are defined by e_1 = (ex_1,ey_1,ez_1)
, e_2 = (ex_2,ey_2,ez_2)
then orthogonality has that Dot(n,e_1)=0
, Dot(n,e_2)=0
, Dot(e_1,e_2)=0
(vector dot product). Note that all the direction vectors should be normalized (magnitude should be one).
Your target point P must obey the equation:
r_P = r_O + t_1*e_1 + t_2*e_2 + s*n
where t_1
and t_2
are your 2D coordinates along e_1
and e_2
and s
the normal separation (distance) between the plane and the point.
There scalars are found by projections:
s = Dot(n, r_P-r_O)
t_1 = Dot(e_1, r_P-r_O)
t_2 = Dot(e_2, r_P-r_O)
Example with a plane origin r_O = (-1,3,1)
and normal:
n = r_O/|r_O| = (-1/√11, 3/√11, 1/√11)
You have to pick orthogonal directions for the 2D coordinates, for example:
e_1 = (1/√2, 0 ,1/√2)
e_2 = (-3/√22, -2/√22, 3/√22)
such that Dot(n,e_1) = 0
and Dot(n,e_2) = 0
and Dot(e_1, e_2) = 0
.
The 2D coordinates of a point P r_P=(1,7,-3)
are:
t_1 = Dot(e_1, r_P-r_O) = ( 1/√2,0,1/√2)·( (1,7,-3)-(-1,3,1) ) = -√2
t_2 = Dot(e_2, r_P-r_O) = (-3/√22, -2/√22, 3/√22)·( (1,7,-3)-(-1,3,1) ) = -26/√22
and the out of plane separation:
s = Dot(n, r_P-r_O) = 6/√11