How can I draw an arrowed line between two circles, given:
I am using
As @andsens said, you're doing a simple vector manipulation.
This can be done much more cleanly if you wrap it in a decent library. For example, I use the nice Sylvester matrix and vector library.
What you're essentially calculating is:
Where v is the vector to the centre of the target, and vedge the vector to the edge of the target with radius r.
Which you can do easily:
// Assume source and target both have x and y properties
// Assume target has radius property
function path2TargetEdge(source, target){
// V is the vector from the source to the target's center
var V = $V([target.x-source.x, target.y-source.y]);
// Vt is the vector from the source to the edge of the target
var Vt = V.toUnitVector().multiply(V.modulus() - target.radius);
return {x: Vt.e(1), y: Vt.e(2) }; // Vectors are 1-indexed
}