I'm working on an object collision engine for a game and I have run into a bit of a problem.
If I have 2 overlapping circles A and B, how far must A be moved in the direction of the normalized vector V so that the 2 circles are exactly touching?
Trigonometry is going to be your friend for that one.
The circles' radii will be two sides, while the distance between them will be the third. Then you need to do some math, and figure out the best way to push them apart.
Or even simpler, when circles are tangeant, the distance between their centers is the sum of each one's radius.
If it is smaller than that, there are in collision, and you need to get one back of the distance (radius1+radius2-distanceBetweenCenters) in the direction of the line between the centers
Also, I may not have been clear enough. The vector V is passed into the function as the direction that circle A is to be moved. I am not looking for the shortest distance out of the collision in any direction.
So you have circle A (coords Ax, Ay with radius Ar)
And circle B (Bx, By, Br)
You also have unit vector V (Vx, Vy)
A needs to be moved to a new position, C.
You need to find Cx and Cy, where C = A*V*dist
dist is unknown.
You know that the distance between C and B is equal to Ar+Br
You also know the distance between A and B because both center points are known.
You can form triangle ABC. You know the length of AB and BC. You also know the angle C (given vectors V and AB). You just need to find the length of AC (which == dist, which will tell you C's center point)
I'm pretty sure that given any 2 sides and at least one angle of a triangle you can get the length of the remaining side. But my geometry is pretty rusty.
EDIT:
Googling turned up this page which seems to be exactly what you need: