如何使用Apple的SIMD库围绕Y旋转arkit 4x4矩阵? [英] How do I rotate an arkit 4x4 matrix around Y using Apple's SIMD library?

查看:216
本文介绍了如何使用Apple的SIMD库围绕Y旋转arkit 4x4矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于ARKit演示来实现一些代码,其中有人使用此辅助功能放置了航路点

I am trying to implement some code based on an ARKit demo where someone used this helper function to place a waypoint

let rotationMatrix = MatrixHelper.rotateAboutY(
    degrees: bearing * -1
)

如何使用SIMD库而不是GLKit实现.rotateAboutY函数?为了简化起见,我可以从起点开始.

How can I implement the .rotateAboutY function using the SIMD library and not using GLKit? To make it easier, I could start from the origin point.

我对矩阵数学不太方便,因此更基本的解释会有所帮助.

I'm not too handy with the matrix math so a more basic explanation would be helpful.

推荐答案

围绕Y矩阵的旋转是:

| cos(angle) 0 sin(angle)|
|      0    1    0       |
|-sin(angle) 0 cos(angle)|

围绕Y逆时针旋转:

|cos(angle) 0 -sin(angle)|
|    0      1       0    |
|sin(angle) 0  cos(angle)|

因此,我们可以使用simd( Accelerate Framework )轻松构建矩阵:

So, we can easily construct the matrix using simd (Accelerate Framework):

func makeRotationYMatrix(angle: Float) -> simd_float3x3 {
    let rows = [
        simd_float3(cos(angle), 0, -sin(angle)),
        simd_float3(0, 1, 0),
        simd_float3(-sin(angle), 0, cos(angle))
    ]

    return float3x3(rows: rows)
}

这里的角度以弧度为单位.更多信息此处.

The angle here is in radians. More info here.

这篇关于如何使用Apple的SIMD库围绕Y旋转arkit 4x4矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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