Posted on 2017/10/19 16:23, blog move

CGAffineTransformMake(a,b,c,d,tx,ty)

A d scaled, B C rotated, TX TY shifted

(x, y) -> (x’, y’)

x' = ax + cy + tx  
y' = bx + dy + ty
Copy the code

Matrix basics:

struct CGAffineTransform {
  CGFloat a, b, c, d;
  CGFloat tx, ty;
};
Copy the code

CGAffineTransform CGAffineTransformMake(CGFloat a, CGFloat b, CGFloat c, CGFloat d, CGFloat tx, CGFloat ty);

In order to unify the changes of two-dimensional graphics in a coordinate system, the concept of homogeneous coordinates is introduced, that is, a graph is represented by a three-dimensional matrix, in which the third column is always (0,0,1), used as the standard of the coordinate system. So all the changes are done by the first two columns.

The above parameters are expressed in the matrix as:

Operation principle: Set original coordinates as (X, Y, 1)

| a | b 0 (X, Y, 1) X | d | 0 = c (aX + cY + tx, bX + dY + ty, 1); | tx ty 1 |Copy the code

After matrix operation, the coordinates (aX + cY + tx, bX + dY + ty, 1) can be seen by comparison:

A =d=1, b=c=0

(aX + cY + tx , bX + dY + ty , 1) = (X + tx , Y + ty , 1)

So, in this case, the coordinates are shifted by the vector tx ty,

CGAffineTransform CGAffineMakeTranslation(CGFloat TX,CGFloat TY).

Second, the set b = c = tx = ty = 0

(aX + cY + tx , bX + dY + ty , 1) = (aX , dY , 1)

So, at this point, X is scaled by a, Y is scaled by D, a and D are the scaling coefficients of X and Y,

Is the function CGAffineTransform CGAffineTransformMakeScale (CGFloat sx, CGFloat sy) calculation principle.

A corresponds to Sx, d corresponds to SY.

Tx =ty=0, a=cosβ, b=sinβ, c=-sinβ, d=cosβ

(aX + cY + tx, bX + dY + ty, 1) = (Xcosβ -ysin β, Xsinβ + Ycosβ, 1)

So, in this case, beta is the Angle of rotation, positive counterclockwise, negative clockwise.

Is the function CGAffineTransform CGAffineTransformMakeRotation (CGFloat Angle) calculation principle.

Angle is the radian of beta.

Reference: developer.apple.com/library/ios…

Original text: justsee.iteye.com/blog/196993…