Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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:

transformation

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,

share|improve this question
    
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
1  
@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

1 Answer 1

See my answer to "Tranforming 2D outline into 3D plane". The transforms and 4 point to 4 point mapping described there should be just what you need.

share|improve this answer
    
I hope that helps. I will be AFK until later tonight. –  robjohn Sep 10 '11 at 21:00
    
+1, but curse you. Now I have to spend some time turning a rectangle in 3D-space (ok, in my mind) and trying to convince myself that I can find a projection mapping it to any 4-gon :-) –  Jyrki Lahtonen Sep 11 '11 at 4:52
    
Don't you need to assume that shape A is convex at least? –  Jyrki Lahtonen Sep 11 '11 at 4:54
1  
@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
    
@Jyrki: the points get mapped as advertised, but the edges may be strange (passing across the horizon, etc.) –  robjohn Sep 11 '11 at 7:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.