Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

circleIntersection.as

1
2
3
4
5
6
7
8
9
10
11
12
circleIntersection = function (x1, y1, r1, x2, y2, r2) {
	var dx = x2 - x1;
	var dy = y2 - y1;
	var c = Math.sqrt(dx * dx + dy * dy);
	var ac = Math.acos((r1 * r1 + c * c - r2 * r2) / 2 * r1 * c) * ((x1 < x2) * 2 - 1);
	var a = Math.atan2(dy, dx);
	dx = a + ac;
	c = x1 + Math.cos(dx) * r1;
	if (isNaN(c)) return false;
	dy = a - ac;
	return [{'_x': c, '_y': y1 + Math.sin(dx) * r1}, {'_x': x1 + Math.cos(dy) * r1, '_y': y1 + Math.sin(dy) * r1}];
};