I am writing a collision detection system in as3. It is intended to be simple: I have some moving rectangles and some static ones. When a moving rectangle collides with another rectangle, I would like to move the source (colliding) rectangle just outside of the collision area, but still as close as possible (based on the source's trajectory).
On every frame I update the positions of my moving rectangles and check for contact amongst all rectangles.
The below image represents the following:
a: Box #1 is moving at an angle of 45 degrees towards a static rectangle (#2).
b: After several 'ticks' we see Rectangle #1 move into the space of Rectangle #2 (the static one). This is the point at which impact is detected for the first time.
c: Now - what I would really like to do! - is move the source Rectangle #1 to the outskirts of Rectangle #2's collision area.
... So given the angle of movement of Rectangle #1 and, knowing the overall areas and positions of Rectangles #1 and #2, Is there a formula that provides the closest possible x and y co-ordinates for Rectangle #1 to be moved to (so that we are no longer in full collision, as we see in stage 'b').
Obviously I would like a solution that will work at any angle of movement and all sorts of rectangle shapes.

Thanks in advance for your time on this :)
