【发布时间】:2021-05-22 09:31:46
【问题描述】:
我一直试图找出在 Maya 中具有 XYZ 旋转值的 3D 对象的正交“顶”视图中的 2D 旋转值。也许另一种方式可以问这个问题:我想弄清楚 3D obj 方向的 2D 旋转。
这是一个简单的图像来说明我的问题:
我已经尝试过使用四元数(脚本粘贴在下面)获取对象的扭曲值等方法,我发现这篇文章:Component of a quaternion rotation around an axis。
如果我将四元数的 X 和 Z 值设置为零,则此方法会工作一半。即使 obj 在 X 轴和 Y 轴上都旋转,我也可以得到正确的 2D 旋转,但是当在所有 3 轴上旋转时,结果是错误的。
我对所有四元数和向量计算都很陌生,所以我一直难以理解它。
;)
def quaternionTwist(q, axisVec):
axisVec.normalize()
# Get the plane the axisVec is a normal of
orthonormal1, orthonormal2 = findOrthonormals(axisVec)
transformed = rotateByQuaternion(orthonormal1, q)
# Project transformed vector onto plane
flattened = transformed - ((transformed * axisVec) * axisVec)
flattened.normalize()
# Get angle between original vector and projected transform to get angle around normal
angle = math.acos(orthonormal1 * flattened)
return math.degrees(angle)
q = getMQuaternion(obj)
# Zero out X and Y since we are only interested in Y axis.
q.x = 0
q.z = 0
up = om2.MVector.kYaxisVector
angle = quaternionTwist(q, up)
【问题讨论】:
标签: math 3d rotation maya quaternions