I bought a new book called “Math and Art“. Its very cool and gives you an indepth look on the Maths within some art.
–
The first chapter starts with Circle-Circle intersection. I wanted to know how this works and how you code it so i did some research and here is my result:
Drag the red dots to reposition the circles!
You need FlashPlayer 10 to view this!
–
The code responsible for detecting the intersections :
View CodeACTIONSCRIPT | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | private function calculateIntersection():void { distanceX = __pointB.x - __pointA.x; distanceY = __pointB.y - __pointA.y; var d2:Number = distanceX * distanceX + distanceY * distanceY; d = Math.sqrt( d2 ); if ( d > __radiusA + __radiusB || d < Math.abs( __radiusA - __radiusB ) ) { this.graphics.clear(); return; } a = ( ( __radiusA * __radiusA) - ( __radiusB * __radiusB) + d2 ) / ( 2 * d ); h = Math.sqrt( ( __radiusA * __radiusA ) - a * a ); x2 = __pointA.x + a * ( __pointB.x - __pointA.x ) / d; y2 = __pointA.y + a * ( __pointB.y - __pointA.y ) / d; intersectionCenterPoint = new Point( x2, y2 ); intersectPointA = new Point( x2 + h * ( __pointB.y - __pointA.y) / d, y2 - h * ( __pointB.x - __pointA.x) / d ); intersectPointB = new Point( x2 - h * ( __pointB.y - __pointA.y) / d, y2 + h * ( __pointB.x - __pointA.x) / d ); } |
Have fun!

The [AS3.0] Circle-Circle intersection by Script.it, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Netherlands License.

