如何在 3d 空间中的平面上投影平面多边形

发布于 2024-08-26 09:29:43 字数 499 浏览 4 评论 0原文

我想将我的多边形沿着矢量投影到 3d 空间中的平面。我最好使用单个变换矩阵来执行此操作,但我不知道如何构建这种类型的矩阵。

给定

  • 平面的参数(ax+by+cz+d),
  • 我的多边形的世界坐标。正如标题中所述,我的多边形的所有顶点都位于另一个平面上。
  • 投影多边形的方向向量(当前多边形平面的法线向量)

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

  • 了解如何自己构建一个变换

矩阵更新

谢谢您的回答,它按预期工作。

给发现这一点的人一个警告:如果投影平面的法线与投影向量平行,则分母 D 将变为(几乎)0,因此为了避免发生奇怪的事情,需要对这种特殊情况进行某种处理是需要的。我通过检查 D < 是否解决了这个问题1e-5,如果是这样,只需沿 hte 挤压矢量平移我的多边形即可。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等待圉鍢 2024-09-02 09:29:43

假设多边形的一个顶点是(x0, y0, z0),方向向量是(dx,dy,dz)

投影线上的点为:(x,y,z) = (x0 + t*dx, y0 + t*dy, z0 + t*dz)。

您想要找到这条线与平面的交点,因此将其代入平面方程 ax+by+cz+d = 0 并求解 t:

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

然后您就得到了目标顶点: < code>x = x0+dx*t 等。

由于这是仿射变换,因此可以通过 4x4 矩阵来执行。您应该能够通过将 x、y、z 的三个方程写为 x0、y0、z0 的函数并获取系数来确定矩阵元素。

例如,对于 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 的工作方式类似。

结果矩阵:(

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 上,应转置该矩阵,因为它使用行向量而不是列向量)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文