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
9
Question by eyal · Nov 15, 2011 at 09:16 AM · quaternion

multiply quaternion by vector

Hi all, I have seen in Unity's third person tutorial (and in other scripts) the multiplication of quaternion by vector, that is quaternion*vector3. I don't understand what it means multiply quaternion by vevtor? After all to rotate a point via quaternion one need to do quaternion***vector3*inverse quaternion

thank u in advance

Comment
Add comment · Show 2
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 syclamoth · Nov 15, 2011 at 09:27 AM 1
Share

The '*' operator between a quaternion and a Vector3 rotates the vector3 by the quaternion.

avatar image eyal · Nov 15, 2011 at 10:03 AM 0
Share

Thank u for your answer. Do u mean thar the vector3 aligned with the rotation represented by quaternion?

3 Replies

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

Answer by aldonaletto · Nov 15, 2011 at 10:01 AM

In the quaternion world, multiplication is the way to apply the rotation to something - when you multiply quaternion by vector3, you're actually rotating the vector. For instance:

   var rot = Quaternion.Euler(0, 45, 0); // rot = 45 degrees rotation around Y
   var v45 = rot * Vector3.forward; // rotate vector forward 45 degrees around Y

I didn't understand your question about point rotation - maybe a typo, but what we can read is a quaternion ** vector3 Quaternion.Inverse(quaternion), what makes no sense (this sequence isn't even allowed: Vector3 must be at the right of the quaternions).
In practice, multiplying a quaternion by a point rotates this point relative to the origin (0,0,0).
Finally, Quaternion.Inverse(quaternion) returns the inverse rotation (same rotation, but to the opposite side).

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 eyal · Nov 15, 2011 at 10:14 AM 0
Share

thank you for your answer.Does the rotation tskes place in world or local coordinate system? say in your example

thank you in advance

avatar image aldonaletto · Nov 15, 2011 at 04:50 PM 0
Share

The vector will be rotated in the world space. The quaternion actually represents a single rotation of some angle around an arbitrary axis (not necessarily XYZ), but this axis is relative to the world. If a more complex rotation is specified - like Euler(15, 45, 60), for instance - Unity converts it to a single rotation: the equivalent axis and angle are calculated and encoded in the quaternion format.

avatar image dogzerx2 · Sep 04, 2013 at 09:45 PM 0
Share

This was extremely helpful. THAN$$anonymous$$ YOU!!

avatar image kubajs · Oct 23, 2018 at 09:45 PM 0
Share

Thank you, very helpful answer!

avatar image
6

Answer by m16a · Mar 17, 2014 at 06:18 PM

Hi, I had the same problem too. I figured out that notation quaternion * vector uses overloaded multiply operator which incapsulate mathematical multiplying quaternion * vector * quaternion^(-1) similar question

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

Answer by kubajs · Oct 23, 2018 at 09:29 PM

I know this is quite old post but I believe this visualisation might help a lot to those who are still struggling, just play with it a bit, it's intuitive. I had similar problems with Quaternions and then hpjohn sent me his sample code (https://forum.unity.com/threads/compare-rotation-of-matrix-with-initial-direction.572440/#post-3811600) I played with a bit and added local rotations, now I can understand that much better:

 using UnityEngine;
 
 public class RotationTest : MonoBehaviour
 {
     Quaternion currentState;
     private void Start()
     {
         //store initial state
         currentState = Quaternion.identity;
     }
 
     private void Update()
     {
         //draw axes tripod in viewport for demo
         Debug.DrawRay(Vector3.zero, currentState * Vector3.up, Color.green);
         Debug.DrawRay(Vector3.zero, currentState * Vector3.right, Color.red);
         Debug.DrawRay(Vector3.zero, currentState * Vector3.forward, Color.blue);
     }
 
     private void OnGUI()
     {
         RotateOnGlobalAxis();
         RotateOnLocalAxis();
         CompareCurrentPositionWithInitialState();
     }
 
     private void RotateOnGlobalAxis()
     {
         GUILayout.BeginArea(new Rect(100, 100, 200, 100));
         if (GUILayout.Button("Rotate around global X"))
         {
             currentState = Quaternion.Euler(90, 0, 0) * currentState;
         }
         if (GUILayout.Button("Rotate around global Y"))
         {
             currentState = Quaternion.Euler(0, 90, 0) * currentState;
         }
         if (GUILayout.Button("Rotate around global Z"))
         {
             currentState = Quaternion.Euler(0, 0, 90) * currentState;
         }
         GUILayout.EndArea();
     }
 
     private void RotateOnLocalAxis()
     {
         GUILayout.BeginArea(new Rect(350, 100, 200, 100));
         if (GUILayout.Button("Rotate around local X"))
         {
             currentState = currentState * Quaternion.Euler(90, 0, 0);
         }
         if (GUILayout.Button("Rotate around local Y"))
         {
             currentState = currentState * Quaternion.Euler(0, 90, 0);
         }
         if (GUILayout.Button("Rotate around local Z"))
         {
             currentState = currentState * Quaternion.Euler(0, 0, 90);
         }
         GUILayout.EndArea();
     }
 
     private void CompareCurrentPositionWithInitialState()
     {
         GUILayout.BeginArea(new Rect(225, 200, 200, 20));
         if (GUILayout.Button("Check State"))
         {
             Vector3 currentUp = currentState * Vector3.up;
             if (Vector3.Dot(currentUp, Vector3.up) > 0.9f)
             {
                 Debug.Log("Current State has up pointing up");
             }
             else
             {
                 Debug.Log("Current State has up pointing somewhere else");
             }
         }
         GUILayout.EndArea();
     }
 }
 

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 Bunny83 · Oct 23, 2018 at 11:20 PM 3
Share

Actually the OP did already know quaterions. He was confused why we only need to multiply the quaternion with the vector (q v) and why we do not explicitly need to multiply by the complex conjugate afterwards as usual (q v qc). This is because Unity's quaterion struct already does this implicitly when you multiply with a vector3. So the quaterion quaterion multiplication looks different from the quaterion * vector multiplication. If you have no idea what i just said you may want to watch this numberphile video on quaterions (recommend to watch the extra footage as well).


So what the OP wanted to know is the "hph*" that is missing in Unity. So when you do "q v" in Unity you actually do "q v q*" (where q* is the complex conjugate of q)

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

11 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

Related Questions

[SOLVED]How to change Quaternion by 180 degrees? 5 Answers

Rotation based player Rotation and Camera Rotation 0 Answers

Efficiency of transform.forward, up, and right 2 Answers

unwanted rotation on the y and z axes 1 Answer

getting AI to look Left, then Right, then resume path 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