I'm trying to figure out a particular formula. I have a polygon that has a polygon within it. I want to transform the outer polygon so that it the inner polygon takes on the original points. like so:

I want to transform a2, b2, c2, and d2, so that a,b,c,d are at the 400x400 square.

Each outer polygon is a square is 400x400. The inner polygon is always variable. I want to know how to stretch the outer polygon so that the inner polygon always fills up the 400x400 square.

I've wracked my head around this for days .. and I still can't figure it out.

My original formula works, but only for squares --

a2.x = 400 / (distance between a/b) * -a

OR

outer new point is:

400 / inner polygon side distance * distance to edge

Any help?