Sign in to follow this  
Promethium

Troublesome transform

Recommended Posts

I'm trying to align two points in space, while also rotating them so their local coordinates system match. This image illustrates what I'm trying to do: Free Image Hosting at www.ImageShack.us So, given two meshes (m1 and m2), two reference points (a1 and a2), and two local coordinate systems ([x1 y1 z1] and [x2 y2 z2]) I need to construct a matrix M that, when applied to m2, will move and rotate it so that a2 coincides with a1, and m2 is rotated opposite m1. This seems simple enough. What I have so far is
M = T(-a2) * R(x2, y2, z2) * R(-x1, y1, -z1) * T(a1)

(where T is a translation transformation, and R a rotation transformation). However, my problem is that this transformation only gives the desired result if z1 is aligned with the global Z axis. So, for example, given m1 and m2 centered on (0 0 0):
a1 = (0 50 -50)
x1 = (-1 0 0)
y1 = (0 1 0)
z1 = (0 0 -1)

a2 = (50 50 0)
x2 = (0 0 -1)
y2 = (0 1 0)
z2 = (1 0 0)

M = (  0 0    1 0
       0 1    0 0
      -1 0    0 0
       0 0 -100 0 )

which is the expected result, but swap a1, x1, y1, z1 for a2, x2, y2, z2 gives
M = (  0 0 1 0
       0 1 0 0
      -1 0 0 0
       0 0 0 0 )

which is not what I want. It seems to be the last rotation that is wrong. In the first example m2 (correctly) get the opposite rotation of m1, while in the second example m2 (incorrectly) get the same rotation as m1. So can anyone help me out here? Are my assumptions wrong? Am I missing a step? Am I barking up the completly wrong tree here?

Share this post


Link to post
Share on other sites
You first have to translate your point in the origin, than to ‘reset’ the current orientation of the point (R(x2, y2, z2)-1=R(x2, y2, z2)T). You can than rotate the coordinate frame and translate the point. If you are using row vectors:

M = T(-a2) * R(x2, y2, z2)T * R(-x1, y1, -z1) * T(a1)

Share this post


Link to post
Share on other sites
Quote:
Original post by apatriarca
You first have to translate your point in the origin, than to ‘reset’ the current orientation of the point (R(x2, y2, z2)-1=R(x2, y2, z2)T). You can than rotate the coordinate frame and translate the point. If you are using row vectors:

M = T(-a2) * R(x2, y2, z2)T * R(-x1, y1, -z1) * T(a1)


Man, I knew it was something simple... [smile] Actually, it was

M = T(-a2) * R(x2, y2, z2) * R(-x1, y1, -z1)T * T(a1)

Now it works beautifully!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this