Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get just the scaling transformation out of CGAffineTransform

Tags:

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)

like image 837
Marin Todorov Avatar asked Apr 22 '10 11:04

Marin Todorov


2 Answers

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 | 
like image 67
Isaac Avatar answered Oct 26 '22 18:10

Isaac


- (CGFloat)xscale {     CGAffineTransform t = self.transform;     return sqrt(t.a * t.a + t.c * t.c); }  - (CGFloat)yscale {     CGAffineTransform t = self.transform;     return sqrt(t.b * t.b + t.d * t.d); } 
like image 34
everconfusedGuy Avatar answered Oct 26 '22 18:10

everconfusedGuy