This looks like a linear transformation to me. We know this because any line in the original graph is also a line in the transformed graph (this is not always true of the demo you gave, but will be true if you follow the directions you gave in your question and not allow concave vertices). I do believe that AS3 has built-in support for transformation matrix manipulations. If not, you can implement them yourself.
[ x' ] = [ a b ] x [ x ]
[ y' ] [ c d ] [ y ]
These are matrices. The first is a vector (your final point), and that equals a certain 2x2 matrix multiplied by a vector (your original point)
If you're not familiar with matrix multiplication, this can be simplified out to be:
x' = a*x + b*y
y' = c*x + b*y
Any linear transformation can be represented by that two-by-two matrix of a, b, c, and d. Pick numbers for each of them, and you get a linear transformation. So how do you find the values of a, b, c, and d that will give you yours?
For four unknowns, you need four equations. If you look at the equations above, you'll see that one point ("vector") and its transformation will give you two equations. So...we need two points. As you'll see later, it'll be useful to pick points in the un-transformed form (m,0) and (0,n) (ie, one along your x axis, and the other along your y axis).
In your example, these are easy to find! They are B and D (if A or C is your origin)!
I'll be using a bit different notation: "primes" for transformed versions of points.
B => B'
B_x => B'_x
B_y => B'_y
If you know the before and the after coordinates of B and D, you can find your transformation matrix a,b,c,d.
Setting up your equations:
B'_x = a * B_x + b * B_y
B'_y = c * B_x + d * B_y
D'_x = a * D_x + b * D_y
D'_y = c * D_x + d * D_y
Now, let's say that B is your x-axis point, in form (B_x,0). Say D is your y-axis point, in form (0,D_y). If this is opposite, switch them. Here, we assume that your origin is A = (0,0), like in most Flash apps.
Setting B_y = 0 and D_x = 0, we get:
B'_x = a * B_x + b * 0
B'_y = c * B_x + d * 0
D'_x = a * 0 + b * D_y
D'_y = c * 0 + d * D_y
Using the powers of algebra, we find:
a = B'_x / B_x
c = B'_y / B_x
b = D'_x / D_y
d = D'_y / D_y
So, in short:
If you know original points: (the vertices on the original x and y axis)
M = (M_x, 0)
N = (0 , N_x)
and their transformed/distorted points
M' = (M'_x, M'_y)
N' = (N'_x, N'_y)
(so that M => M' and N => N')
then calculate and store these four variables:
a = M'_x / M_x
b = N'_x / N_y
c = M'_y / M_x
d = N'_y / N_y
and finally:
(x, y) => ( a*x + b*y , c*x + d*y )
edit: Okay, I ran through a few of your arbitrary-corner-handle transformation, and realized that I jumped to conclusions when I assumed that your transformation was linear. The equations above will only be linear under two conditions:
- Your new grid is the shape of some rotated parallelogram (and you original is a square, 'normal' grid)
- The position of your (0,0) origin point does not change.
Now, I'm not sure what degrees of freedom you are allowing your handles to be positioned by, but perhaps you can restrain them so that your gridspace always follows the form of a rotated parallelogram.