【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结

1. 2D效果 CGAffineTransform  ( view.transform )


transform自定义方法 有6个参数

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

【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第1张图片

x : a*x0 + c*y0 +  tx; (像素点宽)

y : b*x0 + d*y0 + ty; (像素点高)

原画


【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第2张图片


旋转;

x : cos(θ)*x0 - sin(θ)*y0;

y : sin(θ)*x0 + cos(θ)*y0;

//偏转加倾斜

CGFloatjd = -M_PI_4;

CGFloat scaleX = 0.5;

CGFloat scaleY = 1;

self.imageView.transform=CGAffineTransformMake(scaleX*cosf(jd),scaleY*sinf(jd),scaleX*-sinf(jd),scaleY*cosf(jd),0,0);

【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第3张图片


2. 3D效果 CATransform3D  ( view.layer.transform )


structCATransform3D

{

CGFloatm11, m12, m13, m14;

CGFloatm21, m22, m23, m24;

CGFloatm31, m32, m33, m34;

CGFloatm41, m42, m43, m44;

};

我找了一张课件的截图


【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第4张图片


CATransform3D doctorTran = CATransform3DIdentity;

CGFloat jd = M_PI_4;


(1)旋转 rotate


绕Z轴

cos(θ)  ,-sin(θ)  ,0  ,0

sin(θ)   , cos(θ)  ,0  ,0

 0        ,0          , 1  ,0

 0        ,0          ,0   ,1

}

doctorTran.m11 = cosf(jd);

doctorTran.m12 = -sinf(jd);

doctorTran.m21 = sinf(jd);

doctorTran.m22 = cosf(jd);


【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第5张图片

绕Y轴

{

cos(θ)  ,0  ,sin(θ)  ,0

0         ,1  ,0         ,0

-sin(θ) ,0  ,cos(θ)  ,0

0         ,0  ,0          ,1

}

doctorTran.m11=cosf(jd);

doctorTran.m13=sinf(jd);

doctorTran.m31= -sinf(jd);

doctorTran.m33=cosf(jd);


【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第6张图片

绕X轴

{

1  ,0          ,0         ,0

0  ,cos(θ)  ,-sin(θ)  ,0

0  ,sin(θ)   ,cos(θ)  ,0

0  ,0         , 0         ,1

}

doctorTran.m22=cosf(jd);

doctorTran.m23= -sinf(jd);

doctorTran.m32=sinf(jd);

doctorTran.m33=cosf(jd);


【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第7张图片

(2)切变 shear



沿X轴

{

1  ,k  ,0  ,0

0  ,1  ,0  ,0

0  ,0  ,1  ,0

0  ,0  ,0  ,1

}

doctorTran.m12=1;


【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第8张图片

沿Y轴

{

1  ,0  ,0  ,0

k  ,1  ,0  ,0

0  ,0  ,1  ,0

0  ,0  ,0  ,1

}

doctorTran.m21=1;


【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第9张图片

(3)镜像


基于Y-X平面

{

1  ,0  ,0  ,0

0  ,1  ,0  ,0

0  ,0  ,-1 ,0 

0  ,0  ,0  ,1

}

基于X-Z平面

{

1  ,0  ,0   ,0 

0  ,-1  ,0  ,0

0  ,0  ,1   ,0

0  ,0  ,0   ,1

}

基于Z-Y平面

{

-1  ,0  ,0  ,0

0  ,1   ,0  ,0

0  ,0   ,1  ,0

0  ,0   ,0  ,1

}

doctorTran.m11= -1;


【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第10张图片

(4)透视投影

m34 = -1/d;

d值决定了观察点的位置,d为正无穷大的时候,观察点在无穷远处,此时投影线垂直于投影平面,CATransform3D中m34的默认值为0,即观察点在无穷远处。m14,m24同理。

- (CATransform3D) get3DTransform {

CATransform3D transform = CATransform3DIdentity;

transform.m34 = 1.0 / -2000;

return transform;

}

【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第11张图片

旋转Y轴时 锚点默认(0.5,0.5)

//doctorTran.m14 = 1.0/-300.0;//x

 doctorTran.m24 = 1.0/-300.0;//y

//doctorTran.m34 = 1.0/-300.0;

doctorTran.m11=cosf(jd);

doctorTran.m13=sinf(jd);

doctorTran.m31= -sinf(jd);

doctorTran.m33=cosf(jd);


【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第12张图片


旋转Z轴时 让视角离得更近

//doctorTran.m14 = 1.0/-300.0;//x

doctorTran.m24=1.0/-100.0;//y

//doctorTran.m34 = 1.0/-300.0;

doctorTran.m11=cosf(jd);

doctorTran.m12= -sinf(jd);

doctorTran.m21=sinf(jd);

doctorTran.m22=cosf(jd);


【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结_第13张图片

你可能感兴趣的:(【IOS】CGAffineTransform、CATransform3D (m11~m44)自定义参数总结)