views:

425

answers:

3

I found a similar question about getting just the rotation, but as I understand scaling and rotating work different in the transform matrix.

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.

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)

+2  A: 

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).

Isaac
The first answer gets the mark. Both a vote up. Thanks for putting some light on that one
Ican Zilb
+1  A: 
andand
A: 

I have a similar problem trying to get the scaleX, scaleY, and rotation values out of a transformation. In my case, I have a UIImageView that I allow a user to scale, rotate, flip, in any order and multiple times. But I need to extract the scaleX, scaleY, and rotation values and store them in a database so the next time the user comes back, I can redraw the UIImageView in the same location with the same scale and rotation transformations that have been applied. If I just apply a transformation or two, I am successful, but once numerous transformations in random orders happen, the values get thrown off. Then I don't know which order to re-apply the transformations when I re-draw the object. Not sure if anyone else has any advice? Thanks.

Mike