从二维变换矩阵中提取旋转、缩放值 [英] extract rotation, scale values from 2d transformation matrix

查看:47
本文介绍了从二维变换矩阵中提取旋转、缩放值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从二维变换矩阵中提取旋转、缩放和平移值?我的意思是有一个二维转换

how can i extract rotation, scale and translation values from 2d transformation matrix? i mean a have a 2d transformation

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]

now my matrix have values [a, b, c, d, tx, ty]

让我们忘记上面的过程,假设我们只有值 a, b, c, d, tx, ty

lets forget about the processes above and imagine that we have only the values a, b, c, d, tx, ty

如何通过 a、b、c、d、tx、ty 找到总旋转和缩放值

how can i find total rotation and scale values via a, b, c, d, tx, ty

对不起我的英语

感谢您的提前

编辑

我认为它应该是某个地方的答案...

I think it should be an answer somewhere...

我刚刚尝试过这样的 Flash Builder (AS3)

i just tried in Flash Builder (AS3) like this

   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 均匀旋转矩阵的一部分

Not all values of a,b,c,d,tx,ty will yield a valid rotation sequence. I assume the above values are part of a 3x3 homogeneous rotation matrix in 2D

    | 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) 也应该相同.
    • Thus set the traslation into [dx, dy]=[tx, ty]
    • The scale is sx = sqrt(a² + c²) and sy = sqrt(b² + d²)
    • The rotation angle is t = atan(c/d) or t = atan(-b/a) as also they should be the same.
    • 否则您没有有效的旋转矩阵.

      Otherwise you don't have a valid rotation matrix.

      以上变换扩展为:

      x' = tx + sx (x Cos θ - y Sin θ)
      y' = ty + sy (x Sin θ + y Cos θ)
      

      当顺序是旋转,然后是缩放,然后是平移.

      when the order is rotation, followed by scale and then translation.

      这篇关于从二维变换矩阵中提取旋转、缩放值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆