【问题标题】:extract and add rotation values to maya Matrix提取旋转值并将其添加到 Maya 矩阵
【发布时间】:2020-05-21 03:01:33
【问题描述】:

我正在尝试了解 Maya 3d 软件中 4x4 矩阵的基本数学运算,但我似乎找不到任何对我的场景足够具体的东西我能理解。

我基本上有一个像这样的矩阵的对象:

1 0 0 0
0 1 0 0
0 0 1 0 
0 0 0 1

我知道最下面一行代表平移,每一行的1是刻度值。

但是...如果我将 X 中的对象旋转 30*,那么我会得到一个这样的矩阵:

1  0      0    0
0  0.8    0.5  0
0  -0.5   0.8  0
0  0      0    1

首先,我将如何从仅知道矩阵的情况下数学计算旋转 x 值?

其次,如果只知道 3d 对象的旋转、平移和缩放,我将如何计算矩阵值?

【问题讨论】:

  • 读起来很复杂。有一个方程是:```rotation_matrix=rotation_around_x(ax)*rotation_around_y(ay)*rotation_around_z(az); ``` 但我把它读作 rotation_matrix = rx = 30, ry = 0 , rz = 0 rotation_matrix = (30,0,0) 这基本上是欧拉旋转值,我已经知道这些了。如果我阅读子线程有一些计算,但我有点迷失了它。我是否在欧拉角上使用 sin(rx)、sin(ry) 和 sin(rz),然后将结果应用到其他地方来计算新的矩阵值?
  • 没有每个绕轴旋转都有自己的矩阵(其中一些元素确实是你的角度的sin,cos)并且你基本上将矩阵乘以你想要的顺序的对象之一。请参阅Basic rotations... 每个操作都有自己的矩阵,您只需将其乘以对象矩阵(通常以单位矩阵开头)
  • 因此,如果您想从矩阵中提取欧拉角,请参阅Is there a way to calculate 3D rotation on X and Y axis from a 4x4 matrix,它基本上首先从已知的一组角度和结果矩阵中检测乘法顺序,然后简单地计算任何矩阵的角度(由相同的转换顺序)。平移和尺度提取很容易(基向量和原点向量的大小直接是平移)......
  • ex = 10 [deg], ey = 20 [deg], ez = 30 [deg] 代表欧拉旋转吗?在第 3 步中,我似乎无法弄清楚这些结果数字的来源。如果我犯了 ex '10' 的罪,我不会像示例中那样得到 0.173648,并且我不会从示例中矩阵的 x 行的任何组合值中得到该结果。 M[8] 是否代表 Matrix 值列表的八个值?我不太明白我是否需要这个计算,或者它是否是我正在寻找的其他东西。

标签: math matrix 3d maya


【解决方案1】:

当我们谈论 Autodesk Maya 时,我们可以使用 OpenMaya API:

import maya.cmds as cmds
import maya.api.OpenMaya as om

# An object of interest:
object = "pCube1"
# Get the transform matrix as a list of 16 floats
m_list = cmds.xform(object, query=True, matrix=True)
# Create the MMatrix object
m = om.MMatrix(m_list)
# Get the MTransformationMatrix
mt = om.MTransformationMatrix(m)
# Get the rotations
rot = mt.rotation()
# Rotations in radians (as if rotated in the xyz order):
print rot.x, rot.y, rot.z
# Rotations in degrees:
print om.MAngle(rot.x).asDegrees(), om.MAngle(rot.y).asDegrees(), om.MAngle(rot.z).asDegrees()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-13
    • 1970-01-01
    • 2016-04-06
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-28
    相关资源
    最近更新 更多