Calculating relative transformations
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)
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...
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...
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)
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.
I'll be damned... I did a quick test and it worked:
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.
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.
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.
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
calculating X and Y coordinates w/ an angle and distance  ferum  13  18,440 
Jun 25, 2008 10:53 PM Last Post: rosenth 

Calculating direction of car from normal vector and angle  spinner  1  4,029 
Oct 21, 2006 10:43 AM Last Post: imikedaman 

how does Mac OS X handle relative file paths?  WhatMeWorry  7  8,188 
Aug 18, 2005 04:09 PM Last Post: OneSadCookie 

Trouble Calculating Height Field Normals  Nick  15  7,588 
Jul 21, 2005 07:27 AM Last Post: Nick 

Am I calculating the dotproduct correctly?  sealfin  8  5,212 
Jul 13, 2005 04:02 PM Last Post: Skorche 