# 2D transformation

I have a math problem for some code I am writing. I don't have much experience with 2D transformations, but I am sure there must be a straight-froward formula for my problem.

I have illustrated it here:

My goal is to work out the co-ordinates of (Xp2, Yp2).

Shape A is a quadrilateral that exists that can exist anywhere in 2D space. Its four co-ordinates are known. It contains a point (Xp1, Yp1), which are also known.

Shape B is a rectangle with one corner at (0,0). The height and width are variable, but known.

Shape A needs to be transposed to Shape B so that the new position of the point inside can be calculated.

How do I work out the new co-ordinates of (Xp2, Yp2)?

Cheers,

-
The transformation cannot be linear, because a linear one would map a rectangle to a parallelogram. Therefore there may not be a unique natural transformation that would automatically suggest itself. But don't the texture mapping routines do exactly this type of transformations all the time? Even taking into account the projection from 3D world to the 2D screen (and thus finding a natural transformation). Have you looked at the descriptions of those for help/suggestions? – Jyrki Lahtonen Sep 10 '11 at 20:49
@Jyrki: there is a unique perspective transform that maps 4 points to 4 points, as long as no 3 points are collinear. – robjohn Sep 10 '11 at 22:56

@Jyrki: If mapping from a rectangle to a non-convex quadrilateral, one of the points of the rectangle will be behind the observer so that the image on the plane of projection is virtual (a result of dividing by a negative $z$ coordinate). – robjohn Sep 11 '11 at 6:58