Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Raikenkun · Mar 13, 2013 at 04:54 PM · quaternionorientationeulerpitchyaw

finding pitch/roll/yaw from Quaternions

I'm using YEI 3-Space Sensor which gives me x,y,z,w Quaternions. Converting that to Euler angles is done by assigning Quaternions to an object then you can see Euler angles. I thought I could use Euler format as pitch/roll/yaw, but since Euler is dependent on the sequence those rotations are applied.. I now have only "Pitch"(X) since it's the first applied rotation.

I've seen matrices to solve this but isn't there just a straight forward 1 or 2 equations to solve this?

I think I just need pointing to where i should be looking.

TL;DR: if you have Quaternions ,Euler Angles and pitch. How would you find pitch/roll/yaw?

Thanks!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Mar 13, 2013 at 04:59 PM 0
Share

the local euler angles are pitch, roll, yaw

I thought I could use Euler format as pitch/roll/yaw ... you can

4 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Raikenkun · Mar 13, 2013 at 11:53 PM

I guess I should avoid using Euler angles just because you may face gimbal lock issues. I solved it using these equations that use Quaternion(x,y,z,w):

 roll  = Mathf.Atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z);
 pitch = Mathf.Atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z);
 yaw   =  Mathf.Asin(2*x*y + 2*z*w);

source: http://www.tinkerforge.com/en/doc_v1/Software/Bricks/IMU_Brick_CSharp.html

although I have not understood why roll and pitch values range from 3.14 to -3.14 and yaw is 1.52~ to -1.52, but anyway it's working like a charm ! thanks for the help :)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Mar 14, 2013 at 12:08 AM 0
Share

I'm glad they work for your application. I saw them out there as a way to extract euler angles. One reference mention the angles not being what you expect with these equations but good enough for debugging, so I expected them to have similar problems to directly accessing eulerAngles.

avatar image djungelorm · Apr 20, 2014 at 12:45 PM 1
Share

The angles range between 3.14 and -3.14 because they're in radians. To convert them to degrees just multiply by 180/pi

avatar image ikriz · Feb 23, 2015 at 12:41 PM 1
Share

Note also that in unity the yaw is not the z axis but the y axis so in this case the roll should be the Asin call and not the yaw

avatar image sytelus · Oct 03, 2016 at 11:17 PM 0
Share

This doesn't look right. For roll and pitch there should be + ins$$anonymous$$d of -. It should be,

  roll  = $$anonymous$$athf.Atan2(2*y*w + 2*x*z, 1 - 2*y*y - 2*z*z);
  pitch = $$anonymous$$athf.Atan2(2*x*w + 2*y*z, 1 - 2*x*x - 2*z*z);
  yaw   =  $$anonymous$$athf.Asin(2*x*y + 2*z*w);

See equations in https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles

avatar image
1

Answer by ratneshpatel · Feb 14, 2020 at 08:07 AM

 Quaternion q = transform.rotation;
 float Pitch = Mathf.Rad2Deg * Mathf.Atan2(2 * q.x * q.w - 2 * q.y * q.z, 1 - 2 * q.x * q.x - 2 * q.z * q.z);
 float Yaw = Mathf.Rad2Deg * Mathf.Atan2(2 * q.y * q.w - 2 * q.x * q.z, 1 - 2 * q.y * q.y - 2 * q.z * q.z);
 float Roll = Mathf.Rad2Deg * Mathf.Asin(2 * q.x * q.y + 2 * q.z * q.w);

Pitch - yaw - Roll :: X - Y - Z If you want the values in Radians don't multiply with Mathf.Rad2Deg

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mjc33 · May 30, 2020 at 12:11 AM 0
Share

Thanks, this seems to work great for me

avatar image
0

Answer by robertbu · Mar 13, 2013 at 05:08 PM

There is a long post with the issues associated with getting pitch/roll/yaw from a Quaternion here:

http://forum.unity3d.com/threads/63498-roll-pitch-and-yaw-from-quaternion

There is some code at the bottom that works for that programmer's frame of reference.

Note you do not have to assign a Quaternion to an object to get euler angles. You can use Quaternion.eulerAngles.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Raikenkun · Mar 13, 2013 at 08:21 PM 0
Share

Thanks for the help!, yep local euler angles are doing the job, but then I run into gimbal lock problem where one of the axis just has 180 degree range ins$$anonymous$$d of the full 360 range, is there a way to solve this ? Thanks again

avatar image robertbu · Mar 13, 2013 at 08:37 PM 0
Share

Did look at the code at the bottom of the link I provided, and did you read the post? The code at the bottom of the page is going about is in a ugly fashion by creating and destroying game objects, but I think he has the right idea. You need to use the axis order and unwind the Quaternion. According to the post, the axis order is Z-X-Y. You can not depend on the Quaternion.eulerAngles to output angles that make sense for direct use for pitch/roll/yaw.

I don't have time at the moment to code up an example. If you don't get it fixed (and if someone else doesn't help you), I can work up example code tomorrow.

avatar image
0

Answer by kunqiyu · Mar 11, 2021 at 11:31 AM

since the method below are trans quaternions to eurler angle ,this may cause gimbal lock in some case

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotate on 2 different axes 1 Answer

Set the rotation reference to an direction 0 Answers

Problems getting PID system and rotations to work together. 0 Answers

Inverse Quaternion data from Kinect 1 Answer

Yaw, Pitch, Roll adjustments relative to object? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges