2012-02-28 4 views

答えて

22

そのオイラー角よりもクォータニオンを使用することをお勧めし....ロール、ピッチ、ヨーの値がこれらの式を使用してクォータニオンから派生することができます。

roll = atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z) 
pitch = atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z) 
yaw = asin(2*x*y + 2*z*w) 

radianstoDegreesは、プリプロセッサディレクティブが実装され
CMQuaternion quat = self.motionManager.deviceMotion.attitude.quaternion; 
myRoll = radiansToDegrees(atan2(2*(quat.y*quat.w - quat.x*quat.z), 1 - 2*quat.y*quat.y - 2*quat.z*quat.z)) ; 
myPitch = radiansToDegrees(atan2(2*(quat.x*quat.w + quat.y*quat.z), 1 - 2*quat.x*quat.x - 2*quat.z*quat.z)); 
myYaw = radiansToDegrees(asin(2*quat.x*quat.y + 2*quat.w*quat.z)); 

それはとして実装することができます

#define radiansToDegrees(x) (180/M_PI)*x 

これは、数式で与えられたラジアン値を度に変換するために行われます。

変換の詳細については、 tinkerforgeここではConversion between Quaternions and Euler anglesです。

+1

私は興味があります。「オイラー角よりもクォータニオンを使う方が良い」理由は何ですか? – Jacksonkr

+0

ありがとうございます。それはうまくいく。 motionManager.deviceMotion.attitude.pitch/roll/yawは本当に不安定です。Appleがなぜそれらを修正しないのか不思議です。 –

1

ピッチ、ヨー、マトリックスからロール。どのように私はそれを行うことができる任意のアイデア?

どの順番でですか?一般にオイラー角と呼ばれるピッチ、ヨー、ロールは、回転を明白に表現しません。個別の副回転を実行する順序に応じて、完全に異なる回転行列で終わります。

私の個人的な勧告:オイラー角はまったく使用しないでください。行列(すでに行っている)または四元数を使用します。

-1

は自分自身をそれを見つけた:

CMAttitude *currentAttitude = motionManager.deviceMotion.attitude;  

     if (currentAttitude == nil) 
     { 
      NSLog(@"Could not get device orientation."); 
      return; 
     } 
     else { 
      float PI = 3.14159265; 
      float yaw = currentAttitude.yaw * 180/PI; 
      float pitch = currentAttitude.pitch * 180/PI; 
      float roll = currentAttitude.roll * 180/PI; 

     } 
+1

'M_PI'はpiのより正確な表現で、変数を保存します; –

関連する問題