# Solve for Rotation/Translation/Scale

## Recommended Posts

I'm struggling to come up with a solution to this problem. Perhaps it's better demonstrated than explained. Here is a link to the video: Multi-Touch Gesture video Towards the end, the user rotates and zooms the map using two fingers, but it looks approximated. I want to do something similar. The basic question is, how to keep two OpenGL coordinates "glued" underneath the user's fingers? With just that concept, you can zoom in/out, and rotate. I think it's a very intuitive interface gesture when working with touch sensitive displays. Example: Given input in screen coordinate pairs pair 1 = (50, 50 and 100, 100) - start point pair 2 = (20, 20 and 90, 80) - end point how would you go about solving for a matrix that you can apply to pair 1 to produce pair 2? [Edited by - mfawcett on March 13, 2006 4:22:57 PM]

##### Share on other sites
wtf? i dont understand what you are saying.

##### Share on other sites
I am assuming that pair 1 is the initial position and pair 2 is the final position.

To keep things simple you should perform all transformations relative to one of the points( i.e 1st finger)

Basically construct 2 vectors, one for each pair of points.

Find the magnitude of the second vector and divide by the magnitude of the first vector. This will be your scaling factor.

v1 = pair1 vector;
v2 = pair2 vector;

scale factor = |v2| / |v1|;

To find the rotation angle just find the angle between the two vectors. Use either cross product or dot product, I forget which one, but its one of those.

To find translation

translation vector = pair2.point1 - pair1.point1;

That should take care of it. Hope that makes sense.

##### Share on other sites
Quote:
 Original post by Anonymous PosterI am assuming that pair 1 is the initial position and pair 2 is the final position.

Yes, sorry, I should have been more explicit. Your post makes a lot of sense, thank you. Login next time for a rate++ ;)

##### Share on other sites
Amasing. Absolutely astounding. Out of a sci-fi movie 4 sure.

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

• ### Forum Statistics

• Total Topics
628383
• Total Posts
2982372

• 10
• 9
• 15
• 24
• 11