将3d多边形旋转到xy平面中,同时保持方向 [英] Rotating a 3d polygon into xy-plane while maintaining orientation

查看:348
本文介绍了将3d多边形旋转到xy平面中,同时保持方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

问题来自于转换后的多边形的方向.如果我只想旋转到平面中,则可以采用多边形的法线和xy平面之间的角度,并绕正交于两者的轴旋转(叉积).但是,在变换之前和之后,我都需要对多边形的边界框进行定向,以使边界框的底部(z值最低)边缘与xy平面共面.换句话说,包围盒在与地面平行的一侧上齐平放置.转换后,此边缘将平行于x轴.这样一来,无论多边形的方向如何,我在曲面上生成的点的网格将始终具有平行于地面的行.

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.

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

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. 找到多边形平面的方程(从法线开始).
  2. 查找多边形平面和xy平面的交点.这是xy平面上的一条线.
  3. 找到这条线和x轴之间的角度.
  4. 围绕z轴以该角度旋转多边形.
  5. 确定新常态.
  6. 找到新法线与xy平面法线之间的角度.
  7. 围绕x轴以该角度旋转多边形.
  8. 现在多边形应位于xy平面中;使用max/min x和y值生成边界框,生成点网格等,然后将所有内容转换回其起点.

我意识到应该将两个旋转组合在一起以减少矩阵乘法的次数,但这是通用算法.

I realize that two rotations should be combined to reduce the number of matrix multiplications, but this is the general algorithm.

我不是图形专家;我不是图形专家.谁能提供有关这项技术的建议?有没有更好的办法?我的方法听起来正确吗?我正在用Java开发,正在考虑使用Transform3D类进行旋转.

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.

推荐答案

要处理3D多边形,通常会忽略映射的Z坐标(实际上将平面直接投影到XY平面中),然后恢复Z稍后再进行协调.

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.

这唯一不起作用的是原始多边形垂直于XY平面,因为生成的映射会退化为一条线.

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.

这篇关于将3d多边形旋转到xy平面中,同时保持方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆