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
3
Question by ozturkcompany · Dec 21, 2013 at 06:14 PM · transform.

What InverseTransformPoint does? Need Explanation pls

Hello, i need to know what kind of math is in the transform.InverseTransformPoint ? A little example would be;

 var A : Transform;
 var B : Transform;
 var output : Vector3;
 
 function Update ()
 {
      output = A.InverseTransformPoint(B.position)
      Debug.Log(output);
 }

I am looking at the output value and trying to understand what it does but cannot figure it out..Is there anyone there that does know what kind of math is going on in this?

Thanks.

Comment
Add comment · Show 10
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 robertbu · Dec 21, 2013 at 06:24 PM 0
Share

The function transforms a point from world space into the local space of a game object. You would probably get more help by describing the problem you are trying to solve.

avatar image ozturkcompany · Dec 21, 2013 at 06:34 PM 0
Share

i am just trying to shorten my code :) If i would have known what calculations it does then i would have do the same thing without creating 2 game objects and use their transform.Since it is a Vector3 output it should have do sth with the x,y and z values, multiply, add it together etc and give us the desired value.I need to know the math here.

avatar image Paparakas · Dec 21, 2013 at 06:46 PM 0
Share

I would think it simply adds up the position offset of the current transform with each successive parents until there are no more parents but thats just my guess and I'm probably wrong.

avatar image ozturkcompany · Dec 21, 2013 at 06:51 PM 0
Share

that is totally ok! :) i don't know what does it to either.I've researched the site but couldn't find a desired answer.I need to have sth like, the output value is Vector3(A.x * B.y +.... etc etc) sth like this :)

avatar image robertbu · Dec 21, 2013 at 06:52 PM 0
Share

If there are no rotations or scaling, you can just subtract the positions, but if the objects are rotated and scaled you need to account for both.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
15
Best Answer

Answer by Benproductions1 · Dec 23, 2013 at 12:07 PM

Hello,

InverseTransformPoint is, as the name suggests, the inverse of TransformPoint. As I've stated in multiple answers on previous questions, TransformPoint can be described as such:

 position + rotation*Vector3.Scale(lossyScale, point);

Using some logic and some maths we can derive the inverse:

First of course we negate the position, so:

 point - position
 

Next we must negate the rotation, which is done with the inverse of the rotation Quaternion:

 (point - position)*Quaternion.Inverse(rotation)

And lastly we negate the scaling. Like with scalar multiplication this is done by putting the value "under" 1 (or whatever the proper language is). Since Unity doesn't support dividing a scalar by a vector we have to do it manually:

 Vector3.Scale(Vector3(1/lossyScale.x, 1/lossyScale.y, 1/lossyScale.z),
               (point - position)*Quaternion.Inverse(rotation));

Now that we have an inverse function lets quickly prove that it's correct.
We know that for any function f:

f(f'(x)) == x
and
f'(f(x)) == x

Therefore:

 TransformPoint(InverseTransformPoint(point)) == point

So now we can prove our previous function:

 position + rotation*Vector3.Scale(
     lossyScale, 
     Vector3.Scale(
         Vector3(1/lossyScale, 1/lossyScale, 1/lossyScale),
         Quaternion.Inverse(rotation)*(point - position)
     )
 );
 
 //then we can simplify, since the scales cancel out
 position + rotation*Quaternion.Inverse(rotation)*(point - position)

 //then, since a quaternion times it's inverse is always 1
 position - position + point
 
 //which just leaves
 point

Therefore we have both derived and proven the found inverse function of TransformPoint.

Hope this helps,
Benproductions1

PS: I did this on the fly, I don't actually know the function off by heart ;)

Comment
Add comment · Show 1 · 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 CrazyRocksStudios · Nov 03, 2016 at 11:54 PM -1
Share

Hi @Benproductions1 !

I see, You are really good at matrix algebra ;) I need help with a certain inverse matrix transforms - maybe You or anyone here could help ?

The point is : I have some bone transformation matrix ( $$anonymous$$atrix4x4 m ) and I need to use it to temporarily transform a mesh vertex into skeletal space so I do this by simply multiplying vertex by matrix and weight:

pos += m..$$anonymous$$ultiplyPoint3x4(localPos) * weight; // this is just for one bone

Now after some changes to this vertex ( changing normals ) - I need to change it's position back to original one ( before transformation ).

So I create inverse matrix from "m" : $$anonymous$$atrix4x4 mInv = m.inverse;

but .....

multiplying : pos += mInv * weight - does not change vertex position to the previous one - this is because of multiplying by "weight".

If weight is 1 this works fine.

The question is: Do You know the way to transform a point by matrix "partially" and then go back to it's original position ?

Thanks !! Cheers,

Stan

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

21 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 avatar image avatar image

Related Questions

is it possible to make the player to transform into a differet object? 0 Answers

my object instantiates to much 1 Answer

Why is a parent object accessed through the transform? 2 Answers

My character isn't moving 0 Answers

How to remove decimals from Vector3.Distance 3 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