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 ROMgame · Jun 09, 2015 at 03:43 AM · vector3matrixmatrix4x4

InverseTransformPoint via Matrices?

I wish to convert a point from a world space to a local space without having to create and delete a GameObject each time to do it. I therefore wanted to do via matrices. Instead of doing:

 GameObject joint = new GameObject("TempJoint");
 joint.transform.localPosition = jointData1.JointPosition;
 joint.transform.localRotation = jointData1.JointRotation;
 joint.transform.localScale = jointData1.JointScale;

 joint.InverseTransformPoint( pointToTransform );

I hoped that I would be able to do:

 Matrix4x4 matrix4x4 = Matrix4x4.TRS( jointData1.JointPosition, jointData1.JointRotation, jointData1.JointScale );
 matrix4x4.inverse.MultiplyPoint( pointToTransform );

However - they come out with completely different kinds of values. Is anyone able to give me a hint as to what I might be doing wrong?

Thanks!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by NathanJSmith · Oct 20, 2018 at 10:50 AM

Quick code for future reference:

 Matrix4x4 matrixTrans = Matrix4x4.identity;
 matrixTrans.SetTRS(m_GameObject.transform.position, m_GameObject.transform.rotation, Vector3.one);
 
 //Matrix4x4 version of Transform.InverseTransformDirection
 Vector3 localDirection = matrixTrans.inverse.MultiplyVector(worldDirection);
 
 //Matrix4x4 version of Transform.InverseTransformPoint
 Vector3 localPosition = matrixTrans.inverse.MultiplyPoint3x4(worldPositon);
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
0

Answer by Bunny83 · Jun 10, 2015 at 12:19 PM

I've seen this question yesterday but had no time to answer ^^.

The way you presented your problem i can't see anthing wrong here. However you might mix up the different spaces you're working in. You said you want to convert "a world" space (position) into a local space (position). There's usually only one world space. Every other space are different local spaces.

Your two examples are exactly the same as long as your "TempJoint" has no parent and therefore is located in world space. As soon as a parent is involved it get's tricky as a sub localSpace can't necessarily be correctly defined with a simple translation / rotation / scale depending on the parents values. The scale is what makes problems in the first place. If everything is scaled uniformly (or not at all) the end space can be represented with a world position + rotation + scale.

That's also the reason why Unity doesn't have a "scale" (world-scale) property but only a lossyScale property.

Anyways, since your code doesn't seem to involve any kind of parent information (even though the name "joint" suggests some kind of hierarchy) your two approaches work exactly the same.

If this is just abstracted pseudo code, post your actual setup. In what space are your JointPosition, JointRotation and JointScale ?

What do you actually want to calculate (in respect to your setup, which we don't know)?

ps.: Even i know it should work exactly the same i actually did setup a test, calculated the same incoming position in those two ways and placed a cube at the according position and they always match perfectly, no matter what i do to the incoming "space parameters". Even using a parent and using position, rotation and lossyScale both produce exactly the same (approximated) result.

So if you need further help, be more specific about your setup and what spaces you actually talk about.

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to get translation from matrix? 1 Answer

Set shader builtin matrices by script 0 Answers

Can't set GUI.matrix... 1 Answer

How to get the Quaternion Rotation from a Matrix4x4 2 Answers

Setting the camera projection matrix does nothing 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