howto中项目在三维空间上的平面上的平面多边形平面、多边形、项目、空间

2023-09-08 00:22:03 作者:劳资就是CEO

我想我的项目多边形沿着矢量到平面的三维空间。我想preferably使用一个转换矩阵要做到这一点,但我不知道如何建立这样的一个矩阵。

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.

由于的

在飞机上的参数(由+ CZ + D AX +), 在世界坐标我的多边形。正如标题所说,我的多边形横亘在另一架飞机的所有顶点。 沿项目我的多边形(当前多边形的平面的法向量)的方向向量

目标的 其执行所需的投影-a 4×4变换矩阵,

goal -a 4x4 transformation matrix which performs the required projection,

在如何构造一个一些见解本人

更新

感谢您的回答,它可以作为预期。

Thank you for the answer, it works as intended.

谨慎,以谁发现这个人的一句话:如果投影的正常的平面平行于投影矢量,分母Ð会变成(几乎)0,所以要避免发生奇怪的事情,某种处理的需要这种特殊情况。我通过检查解决它,如果D< 1E-5,如果是的话,只是翻译我多边形沿着费尽挤出矢量

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.

推荐答案

假设多边形的顶点之一(X0,Y0,Z0)和方向向量(DX,DY,DZ)

Suppose one of the polygon's vertices is (x0, y0, z0), and the direction vector is (dx,dy,dz).

在投影线上的点是:(X,Y,Z)=(X0 +​​ T * DX,Y0 + T * DY,Z0 + T * DZ)

您想找到这条线与面的交点,所以将其插入平面方程由+ CZ + D = 0 AX + 并解决在t:

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)

然后,你有你的目标顶点: X = X0 + DX * T

由于这是一个仿射变换,它可以由一个4×4矩阵执行。你应该能够通过写三个方程的x,y和z为X0,Y0,Z0的函数和服用的系数来确定矩阵元素

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.

例如,对于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

其中, D = A * DX + B * DY + C * DZ 从上面的分母。 y和z的工作类似。

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

结果矩阵:

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

(注:在Direct3D的这个矩阵应该调换,因为它使用的列向量的行向量代替)

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

 
精彩推荐