I have a grid in a 2D system like the one in the before image where all points A,B,C,D,A’,B’,C’,D’ are given (meaning I know the respective x- and y-coordinates).
I need to calculate the x- and y-coordinates of A(new), B(new), C(new) and D(new) when the grid is distorted (so that A’ is moved to A'(new), B’ is moved to B'(new), C’ is moved to C'(new) and D’ is moved to D'(new)).
The distortion happens in a way in which the lines of the grid are each divided into sub-lines of equal length (meaning for example that AB is divided into 5 parts of the equal length |AB|/5 and A(new)B(new) is divided into 5 parts of the equal length |A(new)B(new)|/5).
The distortion is done with the DistortImage class of the Sandy 3D Flash engine. (My practical task is to distort an image using this class where the handles are not positioned at the corners of the image like in this demo but somewhere within it).
Let (u,v) represent “texture” coordinates. Your handles stay at the same texture coordinates regardless of grid distortions.
So, in texture space, A=(0,0) B=(1,0) C=(1,1) D=(0,1) A’=(au,av) B’=(bu,bv) …
We can convert from texture space to pixel space.
P(u,v) = A*(1-u)(1-v) + Bu*(1-v) + Cuv + D*(1-u)*v
(u,v are texture coordinates, and A, B, C, D refer to pixel coordinates)
So, if your handle A’ is defined to have texture coordinate (.35,.15), then the position of A’ in pixel space is given by P(.35,.15).
Now, say the user drags handle A’. We need to solve for the new location of A. B,C,D remain fixed. It’s just simple algebra.
Not too bad. The same process gets formulas for the other handles. Here is my C# code. It gets called when any of the 8 “Thumbs” get dragged:
video of my demo app:
http://screencast.com/t/NDU2ZWRj
This doesn’t answer your exact question about repositioning 4 handles at the same time. Is that what you really want? Also, let me know if your handles’ texture coordinates aren’t predetermined. You can convert from pixel to texture coordinates, but it is more complicated.