转换3D 4x4的旋转矩阵为二维 [英] Convert 3d 4x4 Rotation Matrix into 2d
问题描述
假设我们有像这样索引的4x4矩阵:
Say we have a 4x4 matrix with indices like so:
00 01 02 03
10 11 12 13
20 21 22 23
30 31 32 33
一个人如何转换的旋转数据(忽略z轴,是否有帮助)包含在此基质成一个单一的二维旋转角度(弧度)?
How does one convert the rotation data (ignoring the z axis, if that helps) contained in this matrix into a single 2d rotational angle (in radians)?
背景:我有一个3D .dae动画从搅拌机出口到Collada的格式。该动画在技术上是2D,所有的Z轴值都为0。我想4×4矩阵转换成2D平移,旋转和缩放数据。
Background: I have a 3D .dae animation exported from Blender into the Collada format. The animation is technically 2d, all of the z axis values are 0. I'm trying to convert the 4x4 matrices into 2d translation, rotation and scale data.
推荐答案
比例矩阵取值
是这样的:
sx 0 0 0
0 sy 0 0
0 0 sz 0
0 0 0 1
翻译矩阵 T
是这样的:
1 0 0 0
0 1 0 0
0 0 1 0
tx ty tz 1
Z轴旋转矩阵研究
是这样的:
cos(a) sin(a) 0 0
-sin(a) cos(a) 0 0
0 0 1 0
0 0 0 1
如果你有一个变换矩阵 M
,它是众多研究
的乘法结果, T
和取值
矩阵。纵观 M
,这些乘法的顺序和数量不详。但是,如果我们假设 M = S * R *牛逼
,我们可以分解为单独的矩阵。首先让我们来计算 S * R *牛逼
:
If you have a transformation matrix M
, it is a result of a number of multiplications of R
, T
and S
matrices. Looking at M
, the order and number of those multiplications is unknown. However, if we assume that M=S*R*T
we can decompose it into separate matrices. Firstly let's calculate S*R*T
:
( sx*cos(a) sx*sin(a) 0 0) (m11 m12 m13 m14)
S*R*T = (-sy*sin(a) sy*cos(a) 0 0) = M = (m21 m22 m23 m24)
( 0 0 sz 0) (m31 m32 m33 m34)
( tx ty tz 1) (m41 m42 m43 m44)
因为我们知道这是一个2D转换,让翻译很简单:
Since we know it's a 2D transformation, getting translation is straightforward:
translation = vector2D(tx, ty) = vector2D(m41, m42)
要计算旋转和缩放,我们可以使用罪(一)^ 2 + COS(一)^ 2 = 1
:
To calculate rotation and scale, we can use sin(a)^2+cos(a)^2=1
:
(m11 / sx)^2 + (m12 / sx)^2 = 1
(m21 / sy)^2 + (m22 / sy)^2 = 1
m11^2 + m12^2 = sx^2
m21^2 + m22^2 = sy^2
sx = sqrt(m11^2 + m12^2)
sy = sqrt(m21^2 + m22^2)
scale = vector2D(sx, sy)
rotation_angle = atan2(sx*m22, sy*m12)
这篇关于转换3D 4x4的旋转矩阵为二维的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!