分解2D变换矩阵 [英] Decompose 2D Transformation Matrix

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

问题描述

因此,我有一个Direct2D Matrix3x2F,用于存储几何图形上的转换.我希望这些转换是用户可编辑的,并且我不希望用户必须直接编辑矩阵.是否可以将3x2矩阵分解为缩放,旋转,倾斜和平移?

So, I have a Direct2D Matrix3x2F that I use to store transformations on geometries. I want these transformations to be user-editable, and I don't want the user to have to edit a matrix directly. Is it possible to decompose a 3x2 matrix into scaling, rotation, skewing, and translation?

推荐答案

这是我为Direct2D转换矩阵找到的解决方案:

This is the solution I found for a Direct2D transformation matrix:

  • 比例x = sqrt(M11 * M11 + M12 * M12)

比例y = sqrt(M21 * M21 + M22 * M22) * cos(shear)

旋转= atan2(M12, M11)

剪切(y)= atan2(M22, M21) - PI/2 - rotation

翻译x = M31

翻译y = M32

如果将这些值按scale(x, y) * skew(0, shear) * rotate(angle) * translate(x, y)的顺序相乘在一起,您将获得一个执行等效变换的矩阵.

If you multiply these values back together in the order scale(x, y) * skew(0, shear) * rotate(angle) * translate(x, y) you will get a matrix that performs an equivalent transformation.

这篇关于分解2D变换矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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