• 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 HauntedHotPocket · Aug 07, 2014 at 02:32 AM · eulerangles

When to use Quaternion vs Euler Angles?

T$$anonymous$$s is a 'best practices' question as well as a clarification one. I get that Euler angles are a way to read Quaternions as a vector3 value, but when would you ever want to use Euler Angles? Why not just use Quaternions all the time?

I'm hoping to get some examples from everyone on when to use each of them, in order to help wrap my head around it by seeing it in practice. The simpler/cleaner the example the better but anyt$$anonymous$$ng helps! Thank you!

Comment
Add comment
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

1 Reply

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

Answer by rutter · Aug 07, 2014 at 02:42 AM

Quaternions have some advantages when it comes to gimbal lock and smooth interpolation. Their main downside is that they rely on advanced math -- math that even experienced developers often find difficult and confusing.

From the scripting manual:

[Quaternions] are based on complex numbers and are not easy to understand intuitively. You almost never access or modify individual Quaternion components (x,y,z,w); most often you would just take existing rotations (e.g. from the Transform) and use them to construct new rotations (e.g. to smoothly interpolate between two rotations). The Quaternion functions that you use 99% of the time are: Quaternion.LookRotation, Quaternion.Angle, Quaternion.Euler, Quaternion.Slerp, Quaternion.FromToRotation, and Quaternion.identity. (The other functions are only for exotic uses.)

People very rarely interact with quaternions directly. As it turns out, it's almost always easier to manipulate them using other representations:

  • Angle-axis representation specifies a unit vector and a rotation about that vector (see ToAngleAxis and AngleAxis pages).

  • Euler angle representation specifies rotation about the Z, X, and Y axes, in that order (see eulerAngles and Euler pages).

The scripting manual suggests some of the most common tricks for manipulating or generating quaternions.

There are some scholarly articles around the net, if you'd like to understand more about the math be$$anonymous$$nd quaternions. If you plan on using them a lot, I $$anonymous$$ghly recommend at least skimming some.

I recommend using quaternion variables to represent two t$$anonymous$$ngs: an object's rotation, and/or a rotation w$$anonymous$$ch you'd like to apply to some object. Even when using them for that purpose, it's almost always easier to generate them using the methods described above, or by taking an existing quaternion and rotating it by some amount you just generated.

It's very rare that you need to actively examine or manipulate quaternions that you didn't create yourself. It's usually easier to use vector math to solve problems, including clever use of dot and cross products.

Comment
Add comment · Show 6 · 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 HauntedHotPocket · Aug 07, 2014 at 04:21 AM 1
Share

That was incredibly helpful. Thank you so much for the thoughtful response! I should have mentioned that yes, I have no intention in the immediate future of going 'inside' the quaternions - though maybe by Unity v16.0 I'll know how ; - D This definitely helps gives a much better vantage of the different methods and how/why to use them. Thank you!!!

avatar image Kiwasi · Aug 07, 2014 at 04:22 AM 2
Share

Use a quaterion to copy a rotation.

 Quaterion myQuaterion = transform.rotation;
 otherTransform.rotation = myQuaterion;

Use euler angles to change or set up a new rotation:

 rotation.eulerAngles = new Vector3(0, 30, 0);

By the time you have a PhD in mathematics to use quaternions directly you will no longer be interested in writing games.

Edit: Added example for euler angles

avatar image ZeRoHuK Kiwasi · Feb 24, 2016 at 09:56 PM 0
Share

Dude you made me laugh a lot ahahaha TY! :D

avatar image HauntedHotPocket · Aug 07, 2014 at 04:37 AM 0
Share

@BoredMorm, that looks like it would accomplish 99% of most jobs. Just curious when you might use a EulerAngle (if ever)?

avatar image Kiwasi · Aug 07, 2014 at 05:21 AM 0
Share

You use euler angles for something like this:

 rotation.eulerAngles = new Vector3(0, 30, 0);

Very difficult to set a specific angle with a quaterion

Both are different application. I tend to use eulerAngles far more often then I use quaternions.

avatar image robertbu · Aug 07, 2014 at 05:45 AM 1
Share

You cannot represent rotations of greater than 180 degrees with Quaternions, and when doing a Slerp() or MoveTowards() rotation with Quaternions, the rotation always take the shortest path. So if you need to rotate more than 180 degrees, often EulerAngles are a better choice. Note you can use Quaternions for doing rotations of more than 180 degrees, but you have to play games that can make the code more complicate.

Note I've read a couple of claims that there are smoothness issues with Quaternion interpolation. I visually don't see it, but smarter people have argued the fact.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Player Rotation while walking on wall 0 Answers

Euler Rotation for Imported Assets 1 Answer

Commands affecting rotation not working 1 Answer

I need help with the slerping of rotations. 1 Answer

I thought I was doing this right, but it gives me an error. 0 Answers


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