• 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
Question by MCorrin · Sep 08, 2012 at 07:48 PM · verticesmatrixmatrix4x4

Matrix rotation of a Vector3 around three planes of rotation

Hi all,

I have a Vector3 instance (v3_orig) that represents a point where a line segment has passed through a plane. In the application, the plane can have arbitrary rotation values (0 < x < 180, 0 < y <180, 0 < z < 180). After determining the point where the line segment crosses the plane, I want to rotate the point from its initial intersection position to a new position so that the point would be at the same position on the plane if the plane orientation had been normalized (Quaternion.identity). I do not want to use Transforms, as the Vector3 is part of a larger mesh object, and I simply want to rotate the vertex position.

I have solutions that work if the initial plane is only rotated in two of three axes (XY, YZ, or ZX) but I can't get it to work if all three axes have a value != 0.

Here is the original code (c#):

 Vector3 v3_orig = Vector3(4,3,5) // some point that intersects with plane
 Quaternion q = Quaternion.identity;
 q.eulerAngles = new Vector3(-20, -20, 40); // Corrected angles to virtually rotate plane
 Matrix4x4 m = Matrix4x4.TRS(Vector3.zero, q , Vector3.one);
 
 Vector3 v3_final = m.MultiplyPoint3x4(v3_orig);

I have tried several variants on this theme and will post if anyone thinks they can give me a hand with this problem. Would also be happy to post a few images that help explain the problem if my explanation is not adequate.

Thank you.

Comment
Jessy
CHPedersen

People who like this

0 Show 4
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 Jessy · Sep 08, 2012 at 09:04 PM 0
Share

Thumbs down for no crosslinks.

avatar image CHPedersen · Sep 08, 2012 at 09:16 PM 0
Share

I +1'ed it again for providing clear description text and for formatting code properly. I do not think this question deserves to be downvoted.

avatar image MCorrin · Sep 08, 2012 at 10:10 PM 0
Share

Hi, I'm new to this forum and certainly didn't want to break with the etiquette of the space. Just so I'm clear, when you ask me to provide cross-links are you referring to other related posts within unityAnswers or more of my own material? In what was likely also a bad move on my part, I threw this question up in UnityAnswers and on the Forum as I was pretty desperate to get an answer today (deadline looming).

avatar image Jessy · Sep 09, 2012 at 04:59 AM 1
Share

This is not Unity forum-specific etiquette. Imagine somebody reads a question of yours in one place, and answers it, despite it being answered somewhere else. If you're going to clutter up the internet with duplication, please try to be make others aware of the mess. Please value the time of others.

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by MCorrin · Sep 08, 2012 at 10:32 PM

Brian Stone posted this answer on the forum and it addresses my problem perfectly.

http://forum.unity3d.com/threads/150444-Matrix-rotation-of-a-Vector3-around-three-planes-of-rotation

Here is what he wrote:

If you have a matrix or quaternion which represents the orientation of the plane, then all you need to do is calculate the Inverse of that transform and multiply it to the point. This will transform the point to the World's identity orientation (X:<1,0,0>, Y<0,1,0>, Z<0,0,1>), because any matrix multiplied by its inverse is the identity matrix*.

 Matrix4x4 M; // set this to the plane's orientation
 Vector3 v3_orig; // some point that intersects with the plane
 Matrix4x4 Mi = M.inverse; 
 Vector3 v3_final = Mi * v3_orig;

  • implies that the matrix is square and non-singular.

And to demo with Quaternion:

 Quaternion qi = Quaternion.Inverse(plane.transform.rotation);
 Vector3 v3_final = qi * v3_orig;
Comment

People who like this

0 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 CHPedersen · Sep 08, 2012 at 10:33 PM 0
Share

That's the same as the answer I posted. There is literally zero difference.

avatar image MCorrin · Sep 08, 2012 at 10:40 PM 0
Share

Hi Christian, Small but subtle difference was that the Quaternion.Inverse call. I couldn't get the code to compile without an error when I used '-plane.transform.rotation'. Thanks though! Michael I hadn't seen your other correction below. Sorry. I appreciate it though!

avatar image CHPedersen · Sep 09, 2012 at 10:00 AM 0
Share

No worries. I've deleted my answer again, as I see no reason to have 2 identical answers to the same 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Using Matrix4x4.TRS to rotate Tilemap 1 Answer

Convention of matrices passed to shaders 1 Answer

GUI Matrix problem 1 Answer

How might I measure the total area of a mesh during displacement? 1 Answer

Can't set GUI.matrix... 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