## Calculating relative transformations

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
Let's say I have two objects, a & b, both of which have transformations in the global coordinate space described as 4x4 matrices.

How can I get the transformation of 'b' relative to 'a', e.g., such that:

(pseudocode warning)
Code:
`a.globalTransform * b.transformRelativeToA = b.globalTransform`

So you can understand the context, I need to perform some hierarchical transformations on objects which only have transforms in the global coordinate space ( owing to the physics engine ODE, which only has global transformations ).

The best approach I can come up with off the top of my head is to create three unit axis vectors for 'b', determine their orientation in the coordinate space of 'a', and then create a new matrix from them. But I imagine there's a better way...
Sage
Posts: 1,487
Joined: 2002.09
Post: #2
It's been a while since I've taken linear algebra, but wouldn't it just be a simple matter of multiplying B by the inverse of A? That should work just fine with homogenous coordinates right?

EDIT: Correction. The inverse of A times B. (not commutative, whoops)

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Sage
Posts: 1,199
Joined: 2004.10
Post: #3
I'll be damned... I did a quick test and it worked:

Code:
```mat4 a = mat4::rotationAboutX( 30 ) * mat4::translation( 2,2,2 ); mat4 b = mat4::rotationAboutY( 10 ) * mat4::translation( -1,-1,1 ); mat4 a2b = a.inverse() * b; mat4 bp = a * a2b; printf( "a  : %s\n", toString( a ).c_str() ); printf( "b  : %s\n", toString( b ).c_str() ); printf( "a2b: %s\n", toString( a2b ).c_str() ); printf( "bp : %s\n", toString( bp ).c_str() );```

A quick examination of 'b' & 'bp' and they're the same!

Thanks, skorche. It's times like this that I wish I had taken the higher math courses at college. Being as I was an art major and all.
Sage
Posts: 1,487
Joined: 2002.09
Post: #4
Heh, for once a technical question that I can answer correctly on the first try.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.