A: 

This is a math problem, not programming ..

you need to define a set of equations (your transformation matrix, my guess is 3 equations) and then solve it for the 4 transformations of the corner-points.

I've only ever described this using German words ... so the above will sound strange ..

lexu
+1  A: 

I'm confused. Is this a 2d or a 3d problem?

The way I understand it, you have a flat rectangle embedded in 3d space, and you're looking at two 2d "pictures" of it - one of the original version and one based on the transformed version. Is this correct?

If this is correct, then there is not enough information to solve the problem. For example, suppose the two pictures look exactly the same. This could be because the translation is the identity, or it could be because the translation moves the rectangle twice as far away from the camera and doubles its size (thus making it look exactly the same).

Alex319
It is a 3d problem. The first picture is a reference picture of the rectangle on a 1:1 scale. The second can be regarded as a picture of the rectangle taken by a camera.I understand your point that there are more solutions (more transformation matrices) to a particurlar case. If this is the case, I am happy to pick either of them. (In the situation you describe, I would be happy with either the identity matrix or any matrix that gives the same result)
dwergkees
A: 

Based on the information you have, this is not that easy. I will give you some ideas to play with, however. If you had the 3D coordinates of the corners, you'd have an easier time. Here's the basic idea.

  1. Move a corner to the origin. Thereafter, rotations will take place about the origin.
  2. Determine vectors of the axes. Do this by subtracting the adjacent corners from the origin point. These will be a local x and y axis for your world.
  3. Determine angles using the vectors. You can use the dot and cross products to determine the angle between the local x axis and the global x axis (1, 0, 0).
  4. Rotate by the angle in step 3. This will give you a new x axis which should match the global x axis and a new local y axis. You can then determine another rotation about the x axis which will bring the y axis into alignment with the global y axis.

Without the z coordinates, you can see that this will be difficult, but this is the general process. I hope this helps.

A: 

The solution will not be unique, as Alex319 points out.

If the second image is really a trapezoid as you say, then this won't be too hard. It is a trapezoid (not a parallelogram) because of perspective, so it must be an isosceles trapezoid.

Draw the two diagonals. They intersect at the center of the rectangle, so that takes care of the translation.

Rotate the trapezoid until its parallel sides are parallel to two sides of the original rectangle. (Which two? It doesn't matter.)

Draw a third parallel through the center. Scale this to the sides of the rectangle you chose.

Now for the rotation out of the plane. Measure the distance from the center to one of the parallel sides and use the law of sines.

If it's not a trapezoid, just a quadralateral, then it'll be harder, you'll have to use the angles between the diagonals to find the axis of rotation.