iPhoneSDK从CATransform3D计算旋转角度

标签 iphone core-animation catransform3d

如何通过将 CATransform3D 结构作为输入来计算围绕 Z 轴的弧度旋转?

基本上我需要的是CATransform3DMakeRotation的另一种方式。

最佳答案

这取决于您在哪个轴上进行旋转。

绕z轴旋转表示为:

a  = angle in radians
x' = x*cos.a - y*sin.a
y' = x*sin.a + y*cos.a
z' = z

( cos.a  sin.a  0  0)
(-sin.a  cos.a  0  0)
( 0        0    1  0)
( 0        0    0  1)

所以角度应该是a = atan2(transform.m12, transform.m11);

绕 x 轴旋转:

a  = angle in radians
y' = y*cos.a - z*sin.a
z' = y*sin.a + z*cos.a
x' = x

(1    0      0    0)
(0  cos.a  sin.a  0)
(0 -sin.a  cos.a  0)
(0    0     0     1)

绕 y 轴旋转:

a  = angle in radians
z' = z*cos.a - x*sin.a
x' = z*sin.a + x*cos.a
y' = y

(cos.a  0  -sin.a   0)
(0      1    0      0)
(sin.a  0  cos.a    0)
(0      0    0      1) 

关于iPhoneSDK从CATransform3D计算旋转角度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3565383/

相关文章:

iphone - 协作/构建大型 Phonegap 项目

ios - 如何在 UIScrollview 中重新排列和删除 UIView,就像在 iOS 主屏幕中重新排列应用程序一样

ios - 如何在 UITableView 标题上方添加具有视差效果的图像并保持标题粘性?

ios - NSOperationqueue有多少种调用方式?

javascript - 屏幕旋转后 screen.width/screen.height 不更新

ios - 创建自定义 CALayer 实现

xcode - 如何计算矩形到四边形的 3D 变换矩阵

core-animation - CATransform3D 等同于 CGPointApplyAffineTransform 和 friend

ios - 如何删除核心数据中的对象

cocoa-touch - CALayer 中的抗锯齿绘图