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
2
Question by minpu · Dec 08, 2013 at 08:45 AM · quaternionmatrix

How to muliply a quaternion with a matrix4x4?

I know that we can use matrix4x4.TRS() but I want to demonstrate about transformation order, so I use a quaternion for rotation and a translation matrix (4x4). But I do not know how to multiply it using "*" operator?

I also test to multiply a quaternion with a vector, then a translation matrix with a vector, but the result is different as testing with another tool.

Anybody help me, please?

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
3

Answer by Bunny83 · Dec 08, 2013 at 08:52 AM

To use a quaternion you have to convert it into a 3x3 rotation matrix. The multiply operator of a quaternion with a vector3 looks like this:

 //C# (taken from UnityEngine.dll)
 public static Vector3 operator *(Quaternion rotation, Vector3 point)
 {
     float num = rotation.x * 2f;
     float num2 = rotation.y * 2f;
     float num3 = rotation.z * 2f;
     float num4 = rotation.x * num;
     float num5 = rotation.y * num2;
     float num6 = rotation.z * num3;
     float num7 = rotation.x * num2;
     float num8 = rotation.x * num3;
     float num9 = rotation.y * num3;
     float num10 = rotation.w * num;
     float num11 = rotation.w * num2;
     float num12 = rotation.w * num3;
     Vector3 result;
     result.x = (1f - (num5 + num6)) * point.x + (num7 - num12) * point.y + (num8 + num11) * point.z;
     result.y = (num7 + num12) * point.x + (1f - (num4 + num6)) * point.y + (num9 - num10) * point.z;
     result.z = (num8 - num11) * point.x + (num9 + num10) * point.y + (1f - (num4 + num5)) * point.z;
     return result;
 }

As you can see they "kind of" generate a 3x3 matrix but without going through the Matrix4x4 class which would be wuite a bit overhead. However you can simply use this to create a Matrix4x4 out of the quaternion.

However it's probably way easier to use

     var rotation = Matrix4x4.TRS(Vector3.zero, yourQuaternion, Vector3.one);

Finally you can decide on your own in which order you multiply the matrices together.

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 derBroV · Jul 27, 2020 at 12:48 PM 0
Share

Why not directly multiply it with another quaternion got from $$anonymous$$atrix4x4.rotation? Quaternion has the character that it is multipliable.

avatar image Bunny83 derBroV · Jul 27, 2020 at 01:17 PM 0
Share

You haven't read the question desctiption, have you? ^^ He wants to combine different transformations and one of them is translation. Quaterions can only represent rotations. So I don't quite see what you mean. Of course you can mutlply quaternions to combine their rotations, that's their main point. However it can't represent any other transformations.


The issue he had was that Unity's TRS has a fix / hardcoded transformation order which I explained in this answer. He wanted a different order

avatar image derBroV Bunny83 · Jul 28, 2020 at 05:52 AM 0
Share

You're right I didn't quite got the meaning of the question. I also didn't notice that what I write was a relative new API considering the time of this question.

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

18 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

Related Questions

convert quaternion to matrix 0 Answers

Creating a Matrix4x4 from an Object's Transform 1 Answer

Quaternion to Matrix conversion failed, but I'm not doing anything with either?? 6 Answers

Change the roll of the rotation 0 Answers

Quaternion to Matrix Conversion Error - Camera Script 0 Answers


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