Matrix transformations in iOS development

Source: Internet
Author: User

Recently in the study Coretext read a lot of examples of which many of them are not specifically understood so the internet collected the iOS matrix conversion principle to record

This article was reproduced from: http://blog.csdn.net/lamp_zy/article/details/8474818

Cgaffinetransformmake (A,b,c,d,tx,ty)

Ad scaling BC rotational tx,ty displacement, base 2D matrix

Formula

X=ax+cy+tx
Y=bx+dy+ty

1. Basic knowledge of matrices:

struct Cgaffinetransform

{
CGFloat A, B, C, D;
CGFloat tx, Ty;
};

Cgaffinetransform Cgaffinetransformmake (CGFloat a,cgfloat b,cgfloat c,cgfloat d,cgfloat tx,cgfloat ty);

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

The above parameters are represented in the matrix as:

|a b 0|

|c D 0|

|tx Ty 1|

Operation principle: The original coordinates are set to (x,y,1);

|a b 0|

[X, Y, 1] |c d 0| = [AX + CY + tx BX + DY + ty 1];

|tx Ty 1|

After the matrix operation coordinates [AX + CY + tx BX + DY + ty 1], let's compare the following:

The first kind: set a=d=1, b=c=0.

[AX + CY + tx BX + DY + ty 1] = [X + tx Y + ty 1];

Visible, at this time, coordinates are translated according to the Vector (Tx,ty), which is actually the function

The computational principle of Cgaffinetransform cgaffinemaketranslation (cgfloat tx,cgfloat ty).

The second type: set b=c=tx=ty=0.

[ax + CY + tx BX + DY + ty 1] = [ax-dy 1];

Visible, at this time, coordinates x is scaled according to a, Y is scaled by D, a,d is the scale factor of x, Y, which is actually the function

Cgaffinetransform Cgaffinetransformmakescale (cgfloat sx, cgfloat sy) Calculation principle. A corresponds to the sx,d corresponding to the SY.

The Third Kind: set Tx=ty=0,a=cos?,b=sin?,c=-sin?,d=cos?

[AX + CY + tx BX + DY + ty 1] = [Xcos?-Ysin? Xsin?  + Ycos? 1];

Visible, this time, is the angle of rotation, counterclockwise is positive, clockwise is negative. Actually, that's the function.

Cgaffinetransform cgaffinetransformmakerotation (cgfloat angle) calculation principle. The radian of angle is.

Matrix transformations in iOS development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.