LoginSignup
0
0

More than 1 year has passed since last update.

iOS + Swift + クオータニオンで角度の差の計算

Last updated at Posted at 2022-07-12

角度の差を速く正しく計算するためには、クオータニオンを使うと良い。

角度の差 を計算してオイラー角に変換する

import Foundation
import SpriteKit
import SceneKit

struct QuaternionToEullerAngleDifferential{
    static func handle(base : simd_quatf, target: simd_quatf) -> SCNVector3{

        return convertToEuller(simdq: 
simd_normalize( target * base.inverse) // 角度の差
)
    }
    
    static func convertToEuller(simdq: simd_quatf) -> SCNVector3{
        let n = SCNNode()
        n.simdOrientation = simdq
        return n.eulerAngles // オイラー角にする
    }
    
}

コードの解説
もとの行列に逆行列をかけると、角度の差がでる
ScineKit にオイラー角への変換ライブラリがあるのでそれでオイラー角にする。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0