Getting rotation and size of a UIImageView based on its transformation matrices

If I have the original transformation matrix of a rectangular UIImageView, and this image is scaled and rotated, and by the end I can read the final transformation matrix of the same view, how can I calculate how much the scale is scaled and rotated?

I believe that somehow these matrices contain these two information. The problem is how to extract it ...

any clues?

Thanks for any help.

+3
source share
1 answer

A little matrix algebra and trigonometric identities will help you solve this problem.

, , , , .

Sx ( X) Sy ( Y) :

⎡Sx  0 ⎤
⎣0   Sy⎦

, R-, :

cos(R)   sin(R)⎤
⎣-sin(R)  cos(R)⎦

, :

⎡Sx.cos(R)   Sx.sin(R)⎤
⎣-Sy.sin(R)  Sy.cos(R)⎦

, , , ( , , ).

A CGAffineTransform a, b, c, d, :

⎡a  b⎤
⎣c  d⎦

Sx, Sy R. :

tan(A) = sin(A) / cos(A)

, , :

tan(R) = Sx.sin(R) / Sx.cos(R) = b / a    and therefore    R = atan(b / a)

R, , :

a = Sx.cos(R)    and therefore    Sx = a / cos(R)
d = Sy.cos(R)    and therefore    Sy = d / cos(R)

, Sx, Sy R.

+9

Source: https://habr.com/ru/post/1716905/


All Articles