如何从二维变换矩阵中提取旋转、缩放和平移值?我的意思是有一个二维变换
matrix = [1, 0, 0, 1, 0, 0]
matrix.rotate(45 / 180 * PI)
matrix.scale(3, 4)
matrix.translate(50, 100)
matrix.rotate(30 / 180 * PI)
matrix.scale(-2, 4)
现在我的矩阵有值 [a, b, c, d, tx, ty]
让我们忘记上面的过程,想象我们只有值 a、b、c、d、tx、ty
如何通过 a、b、c、d、tx、ty 找到总旋转和缩放值
对不起我的英语
感谢您的提前
编辑
我认为这应该是某个地方的答案......
我刚刚在 Flash Builder (AS3) 中尝试过这样的
var m:Matrix = new Matrix;
m.rotate(.25 * Math.PI);
m.scale(4, 5);
m.translate(100, 50);
m.rotate(.33 * Math.PI);
m.scale(-3, 2.5);
var shape:Shape = new Shape;
shape.transform.matrix = m;
trace(shape.x, shape.y, shape.scaleX, shape.scaleY, shape.rotation);
输出是:
x = -23.6
y = 278.8
scaleX = 11.627334873920528
scaleY = -13.54222263865791
rotation = 65.56274134518259 (in degrees)
最佳答案
并非 a、b、c、d、tx、ty 的所有值都会产生有效的旋转序列。我假设上述值是 2D 3x3 齐次旋转矩阵的一部分
| a b tx |
A = | c d ty |
| 0 0 1 |
将坐标[x, y, 1]
转换为:
[x', y', 1] = A * |x|
|y|
|z|
- 因此将转换设置为
[dx, dy]=[tx, ty]
- 比例尺为
sx = sqrt(a² + c²)
和sy = sqrt(b² + d²)
- 旋转角度为
t = atan(c/d)
或t = atan(-b/a)
,它们也应该相同。
否则你就没有有效的旋转矩阵。
<小时/>上述变换扩展为:
x' = tx + sx (x Cos θ - y Sin θ)
y' = ty + sy (x Sin θ + y Cos θ)
当顺序是旋转、缩放、平移时。
关于math - 从二维变换矩阵中提取旋转、缩放值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4361242/