从2D转换矩阵中提取旋转比例值 [英] extract rotation, scale values from 2d transformation matrix

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

问题描述

如何从2d变换矩阵中提取旋转,缩放和平移值?我的意思是进行2D转换

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.

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

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