Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by RossGames · Apr 03, 2016 at 02:26 PM · euleranglesquaternionswhy

Why Quaternions?

Hello, I'm wondering why does Unity use Quaternions?
Since I'm almost every time use Euler angles (and I'm sure I'm not alone), why do we need Quaternions?

Thanks.

Comment
Add comment · Show 3
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 Fredex8 · Apr 03, 2016 at 02:40 PM 0
Share

Google it. Quaternions are essentially too complicated to understand without a decent grasp of maths, certainly too complicated for someone to explain easily on here. I mean I can't make it more than a few lines into the Wikipedia page on them without my eyes glazing over and none of the 'dumbed down' explanations I've read have enlighten me any. Granted I did spend large amounts of time in maths at school just shading in graph paper bored out of my $$anonymous$$d but I don't remember ever hearing the word 'Quaternion' before I used Unity.

They just work, that's all you need to know.

avatar image RossGames Fredex8 · Apr 04, 2016 at 02:26 PM 0
Share

No, they don't work. When making a Quaternion from Euler angles, even when I specify that rotation around Z should be 0, Quaternion is initialized and my character (slightly, st. around +/- 0.9) rotates around the Z axis.

avatar image Fredex8 RossGames · Apr 04, 2016 at 06:26 PM 0
Share

Right well this sounds more like an issue with floating point accuracy rather than quaternions themselves and you'd have probably been given a solution by now if you posted the problem rather than just asking 'Why Quaternions?'

Without seeing the code that rotates your object it is hard to help but setting localEulerAngles.z to 0 after your rotation rather than during probably will fix it.

For example: in my project I have an object which I want to track another object so it is using Quaternion.LookRotation and Quaternion.RotateTowards. Problem was that even if the objects were at exactly the same height the Y value would still end up being modified by small values. That's due to floats being inherently inaccurate.

The solution in this case was to put this after the Quaternion rotations:

 exampleObj.localEulerAngles = new Vector3(0,exampleObj.localEulerAngles.y, 0);
 

That causes the object to only rotate on the y axis and keeps x and z at exactly 0.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by meat5000 · Apr 04, 2016 at 01:29 PM

Quaternions were invented to overcome the Euler problem of Gimbal Lock.

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 RossGames · Apr 04, 2016 at 02:23 PM 0
Share

Hm, I don't see huge disadvantage, but I accept this as one possible answer.

avatar image meat5000 ♦ RossGames · Apr 05, 2016 at 12:21 PM 0
Share

The classic real world scenario of Gimbal Lock being a problem is in the rotational movement of spacecraft. The Gimbals become aligned and can never free themselves.

A Gimbal is a hoop mounted on an axis, basically. The other axes are mounted within the last Gimbal. It was made for Gyroscopy. This is basically the same way that the Axes behave in Unity so the same phenomenon occurs.

Theres a video that does a decent job of explaining it.

https://www.youtube.com/watch?v=zc8b2Jo7mno

avatar image
0

Answer by IgorAherne · Apr 03, 2016 at 05:16 PM

Quaternions are just 4-component vectors, with xyzw.

They are more expensive to create than matrices, but are much cheaper to update once created. They are only 4-float structure, whereas matrices are 16-float. This reduces the size of data during runtime.

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 RossGames · Apr 04, 2016 at 02:28 PM 0
Share

This is another part of the answer. I know that they're more efficient, but if you just store 3 floats, and then apply that rotation around gimbal (even that you can get "locked"), it will be, in my opinion, efficient too.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Quaternions to EulerAngles weird x-axis interaction 1 Answer

Get single axis from gyroscopic input (iOS) 0 Answers

Limit rotation within a volume 0 Answers

Is it possible to rotate 1 axis with Quaternions without using EulerAngles? 1 Answer

problem setting rotation 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