# World to Local Space

This topic is 2650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So I have 2 Objects. ObjectA and ObjectB. I would like to convert ObjectB's position/orientation relative to ObjectA.
I have seen others use the transpose of ObjectA's world matrix to convert other objects into its local space. How does this work?

##### Share on other sites
[font="arial, verdana, tahoma, sans-serif"]

So I have 2 Objects. ObjectA and ObjectB. I would like to convert ObjectB's position/orientation relative to ObjectA.
I have seen others use the transpose of ObjectA's world matrix to convert other objects into its local space. How does this work?

Not at all (at least not in general). You need the inverse matrix instead.

A world matrix defines how to transform a vector given in local space to yield in the same vector but w.r.t. the global space. When using column vectors, this looks like[/font]
p[sub]W[/sub] := W * p
The inverse matrix hence defines how a vector given in global space is to be transformed to yield in the same vector but w.r.t. the local.space, because of
W[sup]-1[/sup] * p[sub]W[/sub] = W[sup]-1[/sup] * ( W * p ) = p

If W[sub]A[/sub] is the world matrix of object A, and similarly W[sub]B[/sub] is the world matrix of object B, then
W[sub]B[/sub] * [ 0 0 0 1 ][sup]t[/sup]
gives you the local origin of B w.r.t. the global space. Further then
W[sub]A[/sub][sup]-1[/sup] * W[sub]B[/sub] * [ 0 0 0 1 ][sup]t[/sup]
gives you the local origin of B w.r.t. the local space of A. In general,
M := W[sub][/sub][sup]-1[/sup] * W[sub]B[/sub]
transforms any vector given in local space of B into the local space of A.

Only in the special case that W is a pure rotation (i.e. ortho-normal) matrix you have the correspondence
W[sup]-1[/sup] == W[sup]t[/sup]

##### Share on other sites
Thanks haegarr! So if I want to move Object B into the local space of Object A, then I should do the following...

[color="#1c2837"]vecObjectBLocalSpacePosition = ObjectB.GetPosition() * ObjectA.GetWorldMatrixInverse();
[color="#1c2837"]

[color="#1c2837"]That would give me Object B's local space position realtive to Object A if Object A were centered at the origin correct? Thanks!

##### Share on other sites

[color="#1c2837"]That would give me Object B's local space position realtive to Object A if Object A were centered at the origin correct? Thanks!

That will depend how you math library is set up. Normally I'd expect to see :

[color="#1c2837"][source]vecObjectBLocalSpacePosition = ObjectA.GetWorldMatrixInverse() * ObjectB.GetPosition();[/source]

but that is down to your library i guess. There are quite few libraries where vec * matrix is not the same as matrix * vec. Definitely one you'd need to check with your lib ;)

1. 1
Rutin
67
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633416
• Total Posts
3011780
• ### Who's Online (See full list)

There are no registered users currently online

×