Get just the scaling transformation out of CGAffineTransform Get just the scaling transformation out of CGAffineTransform objective-c objective-c

Get just the scaling transformation out of CGAffineTransform


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 |


- (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);}


That is an old question, but I still add more information in case someone needs.

For me, the good answer and sample code for getting scale, rotation of transformation and for reproducing it are from article:

http://www.informit.com/articles/article.aspx?p=1951182