I want to project my Polygon along a vector to a plane in 3d Space. I would preferably use a single transformation matrix to do this, but I don’t know how to build a matrix of this kind.
Given
- the plane’s parameters (ax+by+cz+d),
- the world coordinates of my Polygon. As stated in the the headline, all vertices of my polygon lie in another plane.
- the direction vector along which to project my Polygon (currently the polygon’s plane’s normal vector)
goal
-a 4×4 transformation matrix which performs the required projection,
or
- some insight on how to construct one myself
UPDATE
Thank you for the answer, it works as intended.
A word of caution to the people who found this: If the Plane of projection’s normal is parallel to the projection vector, the Denominator D will become (almost) 0, so to avoid strange things from happening, some kind of handling for this special case is needed. I solved it by checking if D < 1e-5, and if so, just translate my polygon along hte extrusion vector.
Suppose one of the polygon’s vertices is
(x0, y0, z0), and the direction vector is(dx,dy,dz).A point on the line of projection is:
(x,y,z) = (x0 + t*dx, y0 + t*dy, z0 + t*dz).You want to find the intersection of this line with the plane, so plug it into the plane equation
ax+by+cz+d = 0and solve for t:And then you have your target vertex:
x = x0+dx*t, etc.Since this is an affine transformation, it can be performed by a 4×4 matrix. You should be able to determine the matrix elements by writing the three equations for x,y,z as a function of x0,y0,z0 and taking the coefficients.
For example, for x:
Where
D = a*dx + b*dy + c*dzis the denominator from above. y and z work similarly.Result matrix:
(Note: On Direct3D this matrix should be transposed, because it uses row vectors instead of column vectors).