如何在 3d 空间中的平面上投影平面多边形
我想将我的多边形沿着矢量投影到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设多边形的一个顶点是
(x0, y0, z0)
,方向向量是(dx,dy,dz)
。投影线上的点为:(x,y,z) = (x0 + t*dx, y0 + t*dy, z0 + t*dz)。
您想要找到这条线与平面的交点,因此将其代入平面方程
ax+by+cz+d = 0
并求解 t:然后您就得到了目标顶点: < code>x = x0+dx*t 等。
由于这是仿射变换,因此可以通过 4x4 矩阵来执行。您应该能够通过将 x、y、z 的三个方程写为 x0、y0、z0 的函数并获取系数来确定矩阵元素。
例如,对于 x:
其中
D = a*dx + b*dy + c*dz
是上面的分母。 y 和 z 的工作方式类似。结果矩阵:(
注意:在 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: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:
Where
D = a*dx + b*dy + c*dz
is 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).