Search code examples
javajava-2dmatrix-transform

Transform a rectangle to a specific shape using java


Is there a way to transform a rectangle to a shape that is shown in the image..? Transformation

I have tried every way I can using AffineTransform to do this. But I couldn't get the the expected result. I want to make sure is this a impossible task or is there a way to do this..


Solution

  • Affine transformation by definition preserves points, straight lines and planes.

    So you can at best transform your rectangle to a rotated parallelogram at best (Opposite lines will remain parallel).

    To achieve more complex shapes, you need more general transformation like Projective transformation (also known as Homography) (affine transformation is a special kind of projective transformation).