What is the simplest way to create AffineTransform
which maps coordinates from one rectangle to another (float/double rectangles are given)?
UPD
To transform from [(a,b)-(c,d)] to [(e,f)-(g,h)] you can perform the following computation:
x' = e + (x - a) * (g - e) / (c - a);
y' = f + (y - b) * (h - f) / (d - b);
Here is the corresponding AffineTransform
code, where r1
is being transformed to r2
:
t = new AffineTransform();
t.translate(r2.getMinX(), r2.getMinY());
t.scale(r2.getWidth()/r1.getWidth(), r2.getHeight()/r1.getHeight());
t.translate(-r1.getMinX(), -r1.getMinY());