- Home /
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.
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.
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.
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.
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 :)
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.
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
andf'(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 ;)
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