This is theory, may not work. Pardon my bad drawing.
1. Let's say you have you image and points set up like this (this method should work for any set-up). First, find the distance between A and B.
2. Get the slope of AB by using deltay/deltax. You can get the angle to rotate by using arctan( slope AB ) or getangle( deltax , deltay ). The slope of CD is -deltax/deltay or -1 / tan( angle ). (The dashed corner is not at A, I just suck at drawing on the computer.)
3. The green axis helps us draw an angle, theta. Theta = arctan( slope of CD ). We can then reposition the image's top point at A by:
making x = A.x - cos( theta ) * ||CD||â€*
making y = A.y
â€* Note: ||v|| is vector notation for magnitude. I'm using it as distance. ||CD|| is the image's height.
4. Finish up by stretching the image.
stretchx = ||AB|| * cos( rotationangle )
stretchy = ||AB|| * sin( rotationangle ) ‡
‡ Note: it may be -sin() because of Graal's upside-down axes, but I'm not positive...
Voila!