Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 perceivereality · Jul 12, 2012 at 10:34 AM · rotationvector3quaternionmagnitude

Quaternion changes Vector3 magnitude?

Hello,

I've been having some trouble with quaternions and rotations in Unity. I think I must be missing something in the documentation, but I can't seem to figure out what.

I want to rotate 2 unit Vector3s around an axis perpendicular to both of them. This should not change the magnitude of the vector. According to the documentation, quaternions should do the job. But no matter what I do, I don't get the results I want.

Here's an example of what I'm doing:

 Debug.Log ("vector1: " + vector1); //start vectors that I want to rotate
 Debug.Log ("vector2: " + vector2); 
 Debug.Log("angle: " + angle); //rotation angle in radians, arbitrary in this example

 Vector3 rotationAxis = Vector3.Cross(vector1, vector2);
 Debug.Log ("rotation axis: " + rotationAxis); 

 Quaternion rotationQuat = Quaternion.AngleAxis(Mathf.Rad2Deg * startanglelaunch, rotationAxis)
 Debug.Log ("rotation quaternion: " + rotationQuat);

 Vector3 rotatedVector1 = rotationQuat * vector1;
 Vector3 rotatedVector2 = rotationQuat * vector2;

 Debug.Log ("rotatedVector1: " + rotatedVector1);
 Debug.Log ("rotatedVector2: " + rotatedVector2);

And this is the debug output from this code (slightly edited for clarity):

 vector1: (1.0, 0.0, 0.0)
 vector2: (0.0, 1.0, 0.0)
 angle: -1.792298
 rotation axis: (0.0, 0.0, 1.0)
 rotation quaternion: (0.0, 0.0, -0.8, 0.6)
 rotatedVector1: (-0.2, -1.0, 0.0)
 rotatedVector2: (1.0, -0.2, 0.0)

So as you can see, I start with unit vectors, get a perpendicular unit vector with the cross product as expected, but the confusion starts when I build the quaternion. I expected the quaternion to simply rotate the vectors and not change their magnitude, but that's not what happens. I get similar unexpected results no matter how I construct the quaternion.

The Quaternion reference page (http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.html) is very clear and what I am doing here should work. I must be missing something simple, but I've been over it many times and I don't know what I should be doing.

Are negative angles not allowed? Do I also have to somehow specify a point to rotate around, as well as an axis? Is this actually the expected behaviour, and if so what should I be doing? I can't find an answer in the documentation.

Any help is appreciated.

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
2
Best Answer

Answer by Kryptos · Jul 12, 2012 at 01:09 PM

Your vectors are still unit vectors. But the default display for Vector3 might be wrong.

Try using a formatted output:

 Debug.Log("rotatedVector1: " + rotatedVector1.ToString("F4")); // will show 4 digits

And to check the magnitude of the vector use sqrMagnitude which is more correct:

 Debug.Log("rotatedVector1: " + rotatedVector1.sqrMagnitude);
Comment
Add comment · Show 3 · 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 · Jul 12, 2012 at 01:54 PM 1
Share

Yes, Unity round the values to one decimal digit when you use the default ToString

avatar image perceivereality · Jul 13, 2012 at 09:57 AM 0
Share

I tried this and it works, problem solved. I was unaware that Unity handled printing vectors this way, although it makes sense now that I know. Thanks for your help.

avatar image Kryptos · Jul 13, 2012 at 09:59 AM 0
Share

Yes it is a bit disturbing at first. I think it should show more digits by default.

Anyway, now I always use the formatted output.

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

6 People are following this question.

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

Related Questions

Rotate vector towards another vector around perpendicular vector 1 Answer

LookRotation Vector3 is Zero, Yet Slerp Still Rotates? 2 Answers

Instantiate GameObject towards player 0 Answers

Transform a Vector by a Quaternion 1 Answer

Random.insideUnitCircle seems to reproduce similar vectors 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