根据matlab中的法线旋转3d物体
我有 3d 主体(三角形网格)和一个垂直于其中一个面的表面。我想旋转身体,使 Z 轴平行于法线。如何求旋转矩阵?
I have 3d body (triangle mesh) and a surfuce normal to one of the faces. I want to rotate the body such that the Z axis would be parallel to the normal. How to find the rotation matrix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果将主体作为 hgtransform 对象的父级,则可以使用 makehgtform 命令为该对象创建变换矩阵。最简单的方法是使用 makehgtform 的这种形式:
axisrotate 选项允许您围绕任意轴旋转。在本例中,[ax ay az] 是一个垂直于要旋转的平面的向量。该平面穿过您要在其间旋转的两个向量。因此,您可以使用 Z 轴和法线的叉积。这给出了一个垂直于两个向量的向量,并且定义了穿过这两个向量的平面的方向。
现在您需要计算出旋转角度。值 r 是您想要绕该轴旋转的角度(以弧度为单位)。有几种方法可以实现这一点。如果你的两个向量被归一化,那就最简单了。那么叉积的大小等于角度的sin,点积的大小等于角度的cos。这有道理吗?
If you parent the body to an hgtransform object, then you can use the makehgtform command to create a transform matrix for that object. The simplest way is to use this form of makehgtform:
The axisrotate option lets you rotate around an arbitrary axis. In this case, [ax ay az] is a vector which is normal to the plane you want to rotate in. That's the plane which passes through the two vectors you're trying to rotate between. So you use the cross product of the Z axis and the normal. That gives you a vector which is normal to both of your vectors, and that defines the orientation of a plane which passes through both of them.
Now you need to figure out the rotation angle. The value r is the angle you want to rotate around that axis in radians. There are a couple of ways to get that. It's simplest if your two vectors are normalized. Then the magnitude of the cross product is equal to the sin of the angle, and the magnitude of the dot product is equal to the cos of the angle. Does that make sense?
您可以轻松地自己实现。一般旋转的矩阵可以在维基百科中找到。您只需要知道角度的 cos() 和 sin() 函数即可。如果你的表面法向量n是单位长度的向量(即|n|=1),那么你已经知道相应的cos()。
You can easily implement it by yourself. The matrix for general rotations can be found at wikipedia. You just need to know cos() and sin() functions for the angles. If your surface normal vector n is a vector of unit length (i.e. |n|=1), then you already know the corresponding cos().