将 3D 多边形旋转到 xy 平面,同时保持方向

发布于 2024-11-08 03:32:00 字数 840 浏览 1 评论 0原文

我有一个以任何方式定向并位于 3d 空间中任何位置的多边形。我需要将多边形转换为 xy 平面,以便可以在 2d 而不是 3d 中对其执行各种操作(特别是生成跨越多边形边界框的点网格),然后将其转换回来。

问题在于变换后的多边形的方向。如果我只想旋转到平面中,我可以获取多边形法线和 xy 平面之间的角度,并围绕与两者正交的轴旋转(叉积)。但是,我要求多边形的边界框的方向应使边界框的底部(最低 z 值)边缘与 xy 平面共面,无论是在变换之前还是之后。换句话说,边界框平齐地放置在与地面平行的一侧。变换后,该边将平行于 x 轴。这样,无论多边形的方向如何,我在表面上生成的点网格将始终具有与地面平行的行。

我的方法是进行两次轮换;首先绕 z 轴旋转多边形平面与 xy 平面的交线与 x 轴之间的角度。这可确保边界框的底部不会移出 xy 平面。然后,再次绕 x 轴旋转多边形(新)法线与 xz 平面之间的角度。步骤如下:

  1. 找到多边形平面的方程(从法线)。
  2. 找到多边形平面与 xy 平面的交点。这是 xy 平面上的一条线。
  3. 求该线与 x 轴之间的角度。
  4. 围绕 z 轴将多边形旋转此角度。
  5. 确定新常态。
  6. 求新法线与 xy 平面法线之间的角度。
  7. 将多边形绕 x 轴旋转此角度。
  8. 多边形现在应该位于 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:

  1. Find the equation for the polygon's plane (from the normal).
  2. Find the intersection of the polygon's plane and the xy-plane. This is a line in the xy-plane.
  3. Find the angle between this line and the x-axis.
  4. Rotate the polygon by this angle around the z-axis.
  5. Determine new normal.
  6. Find the angle between new normal and xy-plane's normal.
  7. Rotate the polygon by this angle around the x-axis.
  8. 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 技术交流群。

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

发布评论

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

评论(2

末蓝 2024-11-15 03:32:00

要处理 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.

﹉夏雨初晴づ 2024-11-15 03:32:00

您需要以下矩阵将顶点坐标从帧 x0,y0,z0 更改为 x1,y1,z1,并最终进行平移以使原点重合。

     // F0 changes x0,y0,z0 to world X,Y,Z            
     F0[0, 0] = X0.X;
     F0[0, 1] = X0.Y;
     F0[0, 2] = X0.Z;
     F0[1, 0] = Y0.X;
     F0[1, 1] = Y0.Y;
     F0[1, 2] = Y0.Z;
     F0[2, 0] = Z0.X;
     F0[2, 1] = Z0.Y;
     F0[2, 2] = Z0.Z;
     F0[3, 3] = 1.0;

     // F1 changes world X,Y,Z to x1,y1,z1            
     F1[0, 0] = X1.X;
     F1[0, 1] = Y1.X;
     F1[0, 2] = Z1.X;
     F1[1, 0] = X1.Y;
     F1[1, 1] = Y1.Y;
     F1[1, 2] = Z1.Y;
     F1[2, 0] = X1.Z;
     F1[2, 1] = Y1.Z;
     F1[2, 2] = Z1.Z;
     F1[3, 3] = 1.0;

     matrix = F1*F0

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.

     // F0 changes x0,y0,z0 to world X,Y,Z            
     F0[0, 0] = X0.X;
     F0[0, 1] = X0.Y;
     F0[0, 2] = X0.Z;
     F0[1, 0] = Y0.X;
     F0[1, 1] = Y0.Y;
     F0[1, 2] = Y0.Z;
     F0[2, 0] = Z0.X;
     F0[2, 1] = Z0.Y;
     F0[2, 2] = Z0.Z;
     F0[3, 3] = 1.0;

     // F1 changes world X,Y,Z to x1,y1,z1            
     F1[0, 0] = X1.X;
     F1[0, 1] = Y1.X;
     F1[0, 2] = Z1.X;
     F1[1, 0] = X1.Y;
     F1[1, 1] = Y1.Y;
     F1[1, 2] = Z1.Y;
     F1[2, 0] = X1.Z;
     F1[2, 1] = Y1.Z;
     F1[2, 2] = Z1.Z;
     F1[3, 3] = 1.0;

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