Howto project a planar polygon on a plane in 3d-space
Asked Answered
T

1

7

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 4x4 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.

Thy answered 23/3, 2010 at 14:4 Comment(0)
H
14

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 = 0 and solve for t:

t = (-a*x0 - b*y0 - c*z0 - d) / (a*dx + b*dy + c*dz)

And then you have your target vertex: x = x0+dx*t, etc.

Since this is an affine transformation, it can be performed by a 4x4 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:

x = x0 - (a*dx*x0 + b*dx*y0 + c*dx*z0 + d*dx) / D
x = (1 - a*dx/D)*x0 - (b*dx/D)*y0 - (c*dx/D)*z0 - d*dx/D

Where D = a*dx + b*dy + c*dz is the denominator from above. y and z work similarly.

Result matrix:

1-a*dx/D    -b*dx/D    -c*dx/D   -d*dx/D
 -a*dy/D   1-b*dy/D    -c*dy/D   -d*dy/D
 -a*dz/D    -b*dz/D   1-c*dz/D   -d*dz/D
    0          0          0         1

(Note: On Direct3D this matrix should be transposed, because it uses row vectors instead of column vectors).

Hideout answered 23/3, 2010 at 14:35 Comment(6)
Thank you for the complete solution. I'll try this right awayThy
I have implemented your solution. However, i have run into trouble as my direction vector is (1|0|0) and the plane is at an 45° angle: Side View: '| ----> /' where | is the Polygon and / is the plane to prject on. In this case, a*dx/D = 1, where the other two entrys in the first column are 0 (dy = dzt = 0). this leads to the entire coumn being 0, effectivly scaling my polygon to 0. My application doesn't like that. Do you know of a workaround for this?Thy
@sum1: The first column being zero means that the x coordinate of the original vertices will be ignored. This is expected since your projection direction is parallel to the x axis. It won't scale your polygon to 0.Hideout
I guess the problem is my application, then. I'll look into that.Thy
I'm trying to create a plane from my planar polygon and project a non-planar polygon onto that plane. Both the planar and non-planar polygons need to be projected on the plane for intersection purposes, would the equation be any different for my situation, mainly I'm thinking a, b, c (plane normal) and dx, dy, dz (also plane normal)?Mesmerism
@Knownasilya: That should work, it doesn't matter if the polygon is planar or not.Hideout

© 2022 - 2024 — McMap. All rights reserved.