iPhoneSDK从CATransform3D计算旋转角度

发布于 2024-09-15 14:05:37 字数 98 浏览 8 评论 0原文

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇俏 2024-09-22 14:05:37

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

绕 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) 

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

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)

so angle should be a = atan2(transform.m12, transform.m11);

Rotation about x-axis:

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)

Rotation about y-axis:

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) 
錯遇了你 2024-09-22 14:05:37

如果变换附加到图层,那么您可以获取旋转的值,如下所示:

CGFloat angle = [(NSNumber *)[layer valueForKeyPath:@"transform.rotation.z"] floatValue];

文档

Core Animation 扩展了键值编码协议,允许通过键路径获取和设置图层 CATransform3D 矩阵的公共值。表4描述了层的transform和sublayerTransform属性符合键值编码和观察的关键路径

If the transform is attached to a layer, then you can get the value of the rotation like follows:

CGFloat angle = [(NSNumber *)[layer valueForKeyPath:@"transform.rotation.z"] floatValue];

From the documentation:

Core Animation extends the key-value coding protocol to allow getting and setting of the common values of a layer's CATransform3D matrix through key paths. Table 4 describes the key paths for which a layer’s transform and sublayerTransform properties are key-value coding and observing compliant

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文