将 3D 多边形旋转到 xy 平面,同时保持方向
我有一个以任何方式定向并位于 3d 空间中任何位置的多边形。我需要将多边形转换为 xy 平面,以便可以在 2d 而不是 3d 中对其执行各种操作(特别是生成跨越多边形边界框的点网格),然后将其转换回来。
问题在于变换后的多边形的方向。如果我只想旋转到平面中,我可以获取多边形法线和 xy 平面之间的角度,并围绕与两者正交的轴旋转(叉积)。但是,我要求多边形的边界框的方向应使边界框的底部(最低 z 值)边缘与 xy 平面共面,无论是在变换之前还是之后。换句话说,边界框平齐地放置在与地面平行的一侧。变换后,该边将平行于 x 轴。这样,无论多边形的方向如何,我在表面上生成的点网格将始终具有与地面平行的行。
我的方法是进行两次轮换;首先绕 z 轴旋转多边形平面与 xy 平面的交线与 x 轴之间的角度。这可确保边界框的底部不会移出 xy 平面。然后,再次绕 x 轴旋转多边形(新)法线与 xz 平面之间的角度。步骤如下:
- 找到多边形平面的方程(从法线)。
- 找到多边形平面与 xy 平面的交点。这是 xy 平面上的一条线。
- 求该线与 x 轴之间的角度。
- 围绕 z 轴将多边形旋转此角度。
- 确定新常态。
- 求新法线与 xy 平面法线之间的角度。
- 将多边形绕 x 轴旋转此角度。
- 多边形现在应该位于 xy 平面内;使用最大/最小 x 和 y 值生成边界框,生成点网格等,然后将所有内容转换回其开始位置。
我意识到应该组合两次旋转来减少矩阵乘法的次数,但这是通用算法。
我不是图形专家;任何人都可以提供有关这项技术的建议吗?有更好的办法吗?我的方法听起来正确吗?我正在使用 Java 进行开发,并正在考虑使用 Transform3D 类进行旋转。
I have a polygon oriented any way and positioned anywhere in 3d space. I need to transform the polygon into the xy-plane so that I can perform various operations on it (in particular generating a grid of points across the bounding box of the polygon) in 2d rather than 3d, then transform it back.
The problem comes with the orientation of the transformed polygon. If I just wanted to rotate into the plane, I could take the angle between the polygon's normal and the xy-plane and rotate around an axis orthogonal to both (cross product). However, I require that the polygon's bounding box be oriented such that the bottom (lowest z-value) edge of the bounding box is coplanar with the xy-plane, both before and after transformation. In other words, the bounding box is resting flush on one side which is parallel to the ground. After transformation, this edge would be parallel to the x-axis. This is so that the grid of points I generate on the surface will always have rows running parallel to the ground, regardless of the polygon's orientation.
My approach is to perform two rotations; first rotate around the z-axis by the angle between the line formed by the intersection of the polygon's plane and the xy-plane, and the x-axis. This ensures that the bottom of the bounding box is not moving out of the xy-plane. Then, rotate again around the x-axis by the angle between the polygon's (new) normal and the xz-plane. Here are the steps:
- Find the equation for the polygon's plane (from the normal).
- Find the intersection of the polygon's plane and the xy-plane. This is a line in the xy-plane.
- Find the angle between this line and the x-axis.
- Rotate the polygon by this angle around the z-axis.
- Determine new normal.
- Find the angle between new normal and xy-plane's normal.
- Rotate the polygon by this angle around the x-axis.
- The polygon should now be in the xy-plane; generate bounding box using max/min x and y values, generate point grid, etc., then transform everything back to where it started.
I realize that two rotations should be combined to reduce the number of matrix multiplications, but this is the general algorithm.
I'm not a graphics expert; can anyone offer advice on this technique? Is there a better way? Does my approach sound correct? I am developing in Java and am looking at using the Transform3D class for the rotations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要处理 3D 多边形,通常会忽略映射的 Z 坐标(这会有效地将平面直接投影到 XY 平面),然后稍后恢复 Z 坐标。
唯一不起作用的情况是原始多边形垂直于 XY 平面,因为生成的贴图会退化为一条线。
To handle 3D polygons it's common to simply ignore the Z coordinate (which effectively projects the plane directly into the XY plane) for your mappings, then just reinstate the Z coordinates later.
The only time this doesn't work is if the original polygon is perpendicular to the XY plane, since the resulting mapping degenerates to a line.
您需要以下矩阵将顶点坐标从帧 x0,y0,z0 更改为 x1,y1,z1,并最终进行平移以使原点重合。
You need the following matrix to change vertex coordinates from frame x0,y0,z0, to x1,y1,z1 and eventually a translation to make origins coincide.