iPhoneSDK从CATransform3D计算旋转角度 [英] iPhoneSDK calculate Rotation angle from CATransform3D

查看:179
本文介绍了iPhoneSDK从CATransform3D计算旋转角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过提供CATransform3D结构作为输入来计算Z轴周围的旋转?

How do I calculate the Rotation in Radians around Z-axis by giving a CATransform3D struct as the input?

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

basically what I need is the other way round of CATransform3DMakeRotation.

推荐答案

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

It depends on what axis you are doing the rotation on.

关于z轴的旋转表示为:

Rotation about the z-axis is represented as:

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计算旋转角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆