Couldn't i adapt the 'circle-method' to AS? No idea how i'd figure out the
equation of these circles, but it should be possible, since i've got their
centre and their radius.

Say P1 = (x1, y1) is the position of the first point and P2 = (x2, y2) the position of the second.
Say R1 is the distance from P1 and R2 the distance from P2.

You want Q = (x,y) such that (x-x1)(x-x1)+(y-y1)(y-y1) = R1*R1 and (x-x2)(x-x2)+(y-y2)(y-y2) = R2*R2

This is basically a pair of simultaneous equations, but it's a bit tricky. One way to simplify it slightly is to consider the point R which lies between P1 and P2. Its position is R=P1+t*(P2-P1), where t=R1/(R1+R2) [or, to put it more neatly, R = (R2*P1 + R1*P2) / (R1 + R2) ].

Now find the normal to (P2 - P1) [one normal of a vector (x,y) is the vector (-y,x)], and divide this by its length to get a unit vector N. Then you know Q must lie on the line starting at R with vector N: that is, Q = R + s*N, for some s. And you can find s by considering the right-angled triangle P1 R Q, which has hypotenuse R1, one side |R - P1| [ = R1 |P1-P2| / (R1+R2)] and the other side s. Using pythagoras, you can find s and thus Q.

In untested actionScript (although I'd recommend making or finding a vector object that handles all the boring vector functions for you!):

function findIntersection (p1, p2, r1, r2) {
// p1 and p2 should be points such as {x:1, y:2}
var p1p2 = vectorBetween(p2,p1)
var dist = mag(p1p2)
var sSquared = 1 - dist / (r1+r2)
if (sSquared<0) {return "no such point"}
var r = vectorSum(scalarMult(r2/(r1+r2),p1), scalarMult(r1/(r1+r2),p2))
var n = scalarMult(1/dist, normalVector(p1p2))
var s = r1 * math.sqrt(sSquared)
return vectorSum(r, scalarMult(s, n))
}

function vectorSum (a, b) {
return {x: a.x+b.x, y: a.y+b.y}
}

function scalarMult (t, v) {
return {x: t*v.x, y: t*v.y}
}

function mag (v) {
return Math.sqrt(v.x*v.x + v.y*v.y)
}

function vectorBetween (a, b) {
return {x:b.x - a.x, y: b.y - a.y}
}

function normalVector (v) {
return {x: -v.y, y:v.x}
}

HTH
Danny
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to