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 /
avatar image
0
Question by VyctonVivax · Jan 03, 2018 at 08:11 PM · rotationquaternionquaternions

Quaternions rotating the wrong way

Hello,

I'm making a physics simulation that uses quaternions to calculate the rotation of the objects involved. I've written the following method for constructing a quaternion:

    static Quaternion quatCons(Vector3 axis, float angle) {
         axis = axis.normalized;
         float s = Mathf.Sin(angle / 2f);
 
         Quaternion result = new Quaternion(s * axis.x, s * axis.y, s * axis.z, Mathf.Cos(angle / 2f));
         
         return result;
     }

Where axis is the axis around which the rotation takes place, and angle the angle/second at which the rotation happens (in radians).


When trying to simulate the rotation of earth, I use the following code:

         static Vector3 earthAx = new Vector3(0, 1, 0); 
         static Quaternion earthRot = quatCons(earthAx, Mathf.PI/43200f*Time.deltaTime);
         earthTrans.transform.rotation = earthRot * earthTrans.transform.rotation;

According to the rules of quaternion multiplication, this should result in the sphere rotating eastward right? Clockwise rotation when looking in the same direction the axis vector is pointing. The sphere rotates westward though (or anticlockwise), and I have no idea why. Does it have something to do with the way unity multiplies by quaternions? It doesn't really make sense to me.

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

2 Replies

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

Answer by Bunny83 · Jan 04, 2018 at 12:34 AM

Uhm, the usual rotation direction is counter clockwise. What makes you think the rotation should be clockwise? Keep in mind that Unity uses a left handed system, not a right handed system.

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 VyctonVivax · Jan 04, 2018 at 10:24 AM 0
Share

"The rotation is clockwise if our line of sight points in the same direction as u→" From https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation But if unity rotates counter clockwise I guess I'll just have to keep that in $$anonymous$$d, thanks!

avatar image Bunny83 VyctonVivax · Jan 04, 2018 at 12:51 PM 1
Share

The mathematical definition of most concepts uses a right handed system. In a left-handed system most concepts are inverted when compared to a right handed system. This even applies to the vector crossproduct. While you usually use the right-hand-rule, in a left handed system you have to use the left hand rule. C = Cross(A, B) --> A == thumb, B == index finger, C == middle finger.


ps: Unity already has a method to convert and angle and axis into a quaternion: Quaternion.AngleAxis. So there's no need to manually setup the quaternion. Note that AngleAxis takes an angle in degree, not in radians.

avatar image
0

Answer by OneCept-Games · Jan 03, 2018 at 09:09 PM

Rotating an object by the Quaternion directly is complex math. Why not use the Eular method of the Quaternion class and use Vector3 objects instead?

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

101 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use quaternions to apply an offset to a rotation to calibrate a controller 1 Answer

Get real compass direction 1 Answer

How can I instantiate a gameobject facing another gameobject 2D? 0 Answers

How to rotate object based on another rotation. 1 Answer

Make Quaternion affected by float 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