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
1
Question by angelpay · Feb 04, 2014 at 08:37 PM · c#quaternionsyntaxproduct

Quaternion multiplication

hey guys, I'm trying to figure out the syntax (C#) and the proper way to multiply two quaternions into an equation like this:

[v1, s1][v2,s2] = [s1v2+s2v1+v1 (cross) x2, s1s2 - v1 (dot) v2]

where v1 = omega (w), s1 = 0, v2 = xyz of q (which is quaternion), s2 = w of q

here is my syntax in c# to compute this:

 Quaternion quatprod = 0+q.w*w + (w*q), 0 - Vector3.dot(w,q);
 q = q + ((Time.deltaTime) / 2)* quatprod;

This seems very wrong to me. Also confusing. Any light that anyone can shed on this??

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 Wiki

Answer by gfoot · Feb 04, 2014 at 09:50 PM

It is simpler to construct a new quaternion for [v1, s1] and let Unity multiply them:

 Quaternion qw0 = new Quaternion(w.x, w.y, w.z, 0);
 Quaternion quatprod = qw0 * q;

qw0 is not normalized and I'm not sure how well Unity's Quaternion type caters for that. The reason I doubt this is that it lacks so many operators, such as addition, magnitude, and normalization. It smells like it only supports unit quaternions.

However, I tried it and it seems to work OK - it correctly stores qw0 and quatprod, without auto-normalizing them. So you might be OK.

The next step in your code will cause more problems as you need to multiply a quaternion by a scalar, and to add two quaternions together, neither of which is provided by Unity's Quaternion type. You can define them yourself though and it should work.

If on the other hand you do want to do all the maths yourself without using the Quaternion type, then you should be more explicit about breaking the input quaternion into a vector/scalar pair first:

 Vector3 qV = new Vector3(q.x, q.y, q.z);
 float qS = q.w;

Then calculate the result, as a vector/scalar pair:

 Vector3 quatprodV = qS * w + Vector3.Cross(w, qV);
 float quatprodS = -Vector3.Dot(w, qV);

Then integrate your (qV, qS) pair:

 qV += (Time.deltaTime / 2) * quatprodV;
 qS += (Time.deltaTime / 2) * quatprodS;

Although you didn't mention it, I think you would now normalize the quaternion.

 float magnitude = Mathf.Sqrt(qV.sqrMagnitude + qS * qS);
 qV /= magnitude;
 qS /= magnitude;

And now you can repack q from (qV, qS):

 q = new Quaternion(qV.x, qV.y, qV.z, qS);
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 gfoot · Feb 04, 2014 at 10:23 PM 0
Share

I edited this to remove some of the doubt about Unity's support for non-unit Quaternions, as it does seem to support them fairly well in practice.

avatar image angelpay · Feb 04, 2014 at 10:31 PM 0
Share

Thanks for your help. It has definitely shed some light on the quaternion object. I am wondering, however, where did you use the quatprod that you computed in the beginning in the end result?? is the full quatprod itself useless unless you break it up?

Thanks!!

avatar image gfoot · Feb 04, 2014 at 10:36 PM 0
Share

Sorry if it was unclear - the first code block was showing how to do the multiplication using Unity's built-in Quaternion.operator*, i.e. by converting (w,0) into a Quaternion first. That block is in isolation, and you'd need to go on to do your "q = q + ..." line afterwards.

The rest of the code blocks are an alternative sequence showing how to do it the opposite way - by first splitting q into (qV, qS) and doing the maths at that level.

avatar image angelpay · Feb 05, 2014 at 08:26 PM 0
Share

alright, got it! thanks.

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

19 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Lean main camera depending on input Axis (Horizontal) 1 Answer

Rotate a projectile on Z axis for a 2D Game played on X and Y axis? 1 Answer

Change rotation of child gameobject 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