Jump to content
• Advertisement

# Troublesome transform

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

If you intended to correct an error in the post then please contact us.

## 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: 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

##### Share on other sites
Advertisement
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

##### Share on other sites
Quote:
 Original post by apatriarcaYou 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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5
• Advertisement

• 12
• 17
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632660
• Total Posts
3007697
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!