仅从CGAffineTransform获取缩放转换 [英] Get just the scaling transformation out of CGAffineTransform
问题描述
我发现了一个关于仅获得旋转的类似问题,但是据我了解,缩放和旋转在变换矩阵中的工作有所不同.
I found a similar question about getting just the rotation, but as I understand scaling and rotating work different in the transform matrix.
矩阵不是我的强项,所以如果有人提示我如何从CGAffineTransform中获得仅缩放,我将不胜感激.
Matrixes are not my strength, so if anybody would hint me how to get only the scaling out of a CGAffineTransform I'd greatly appreciate.
顺便说一句.我尝试在CGSize上应用CGAffineTransform,然后获取height x width以查看其缩放比例,但是height x width具有奇怪的值(取决于CGAffineTransform中的旋转程度,所以... hm不起作用)
btw. I tried applying the CGAffineTransform on a CGSize and then get the height x width to see how much it scaled, but height x width have strange values (depending on the rotation found in the CGAffineTransform, so ... hm that does not work)
推荐答案
假设变换是缩放,然后是旋转(可能有平移,但没有倾斜),则水平缩放因子为sqrt(a^2+c^2)
,垂直比例因子为sqrt(b^2+d^2)
,水平比例因子与垂直比例因子之比应为a/d = -c/b
,其中a
,b
,c
和d
是六个成员中的四个根据文档中的CGAffineTransform
(tx
和ty
仅代表翻译,这不会影响比例因子.
Assuming that the transformation is a scaling followed by a rotation (possibly with a translation in there, but no skewing) the horizontal scale factor is sqrt(a^2+c^2)
, the vertical scale factor is sqrt(b^2+d^2)
, and the ratio of the horizontal scale factor to the vertical scale factor should be a/d = -c/b
, where a
, b
, c
, and d
are four of the six members of the CGAffineTransform
, per the documentation (tx
and ty
only represent translation, which does not affect the scale factors).
| a b 0 |
| c d 0 |
| tx ty 1 |
这篇关于仅从CGAffineTransform获取缩放转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!