将 3d 4x4 旋转矩阵转换为 2d [英] 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 轴,如果有帮助)转换为单个 2d 旋转角度(以弧度为单位)?
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)?
背景:我有一个从 Blender 导出为 Collada 格式的 3D .dae 动画.动画在技术上是 2d,所有 z 轴值都是 0.我正在尝试将 4x4 矩阵转换为 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.
推荐答案
Scale matrix S
看起来像这样:
Scale matrix S
looks like this:
sx 0 0 0
0 sy 0 0
0 0 sz 0
0 0 0 1
翻译矩阵T
看起来像这样:
Translation matrix T
looks like this:
1 0 0 0
0 1 0 0
0 0 1 0
tx ty tz 1
Z 轴旋转矩阵 R
看起来像这样:
Z-axis rotation matrix R
looks like this:
cos(a) sin(a) 0 0
-sin(a) cos(a) 0 0
0 0 1 0
0 0 0 1
如果你有一个变换矩阵 M
,它是 R
、T
和 S 多次相乘的结果
矩阵.查看 M
,这些乘法的顺序和数量是未知的.但是,如果我们假设 M=S*R*T
我们可以将其分解为单独的矩阵.首先让我们计算S*R*T
:
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)
计算旋转和缩放,我们可以使用sin(a)^2+cos(a)^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 旋转矩阵转换为 2d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!