circumcenter
package {
import flash.events.*;
import flash.geom.*;
import flash.display.*;
import flash.text.TextField;
public class Circle extends Sprite {
public function Circle() {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var p:Vector.<Particle> = new Vector.<Particle>(3);
for (var i:int = 0; i < 3; i++) {
addChild(p[i] = new Particle(
Math.random() * stage.stageWidth,
Math.random() * stage.stageHeight)
);
}
addEventListener(Event.ENTER_FRAME, function():void {
var a:Vector3D = new Vector3D(p[0].x, p[0].y);
var b:Vector3D = new Vector3D(p[1].x, p[1].y);
var c:Vector3D = new Vector3D(p[2].x, p[2].y);
var ab:Vector3D = b.subtract(a);
var bc:Vector3D = c.subtract(b);
var ca:Vector3D = a.subtract(c);
var c2:Number = ab.lengthSquared;
var a2:Number = bc.lengthSquared;
var b2:Number = ca.lengthSquared;
var s:Number = 2 / ab.crossProduct(bc).length;
var _a:Vector3D = a.clone();
var _b:Vector3D = b.clone();
var _c:Vector3D = c.clone();
_a.scaleBy(a2 * (b2 + c2 - a2));
_b.scaleBy(b2 * (c2 + a2 - b2));
_c.scaleBy(c2 * (a2 + b2 - c2));
var q:Vector3D = _a;
q.incrementBy(_b);
q.incrementBy(_c);
q.scaleBy(s * s / 16);
graphics.clear();
graphics.beginFill(0xff);
graphics.drawCircle(q.x, q.y, q.subtract(a).length);
graphics.endFill();
});
}
}
}
import flash.events.*;
class Particle extends flash.display.Sprite {
public function Particle(_x:Number, _y:Number){
x = _x;
y = _y;
graphics.beginFill(0,0.5);
graphics.drawCircle(0,0,8);
graphics.endFill();
addEventListener(MouseEvent.MOUSE_DOWN, function():void { startDrag() });
addEventListener(MouseEvent.MOUSE_UP , function():void { stopDrag() });
}
}