In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

ff [2]: Parabola through 3 points

Parabola through three points.
Explicit version, solved in Mathcad.
@author makc
Get Adobe Flash player
by makc3d 26 Mar 2011
// forked from makc3d's ff: Parabola through 3 points
// forked from makc3d's Parabola through 3 points
// forked from makc3d's Solving a system of linear equations
package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	/**
	 * Parabola through three points.
	 * Explicit version, solved in Mathcad.
	 * @author makc
	 */
	public class Test1 extends Sprite {
		public var a1:Anchor;
		public var a2:Anchor;
		public var a3:Anchor;
		public function Test1 () {
			addChild (a1 = new Anchor (r, r));
			addChild (a2 = new Anchor (r, r));
			addChild (a3 = new Anchor (r, r));

			addEventListener (Event.ENTER_FRAME, findParabola);
		}

		public function get r ():int {
			return 10 + Math.random () * 445;
		}

		public function findParabola (whatever:*= null):void {
			var x1:Number = a1.x;
			var y1:Number = a1.y;
			var x2:Number = a2.x;
			var y2:Number = a2.y;
			var x3:Number = a3.x;
			var y3:Number = a3.y;

			// handle ds == 0, right...
			var d1:Number = x1 * (x1 - x2 - x3) + x2 * x3;
			var d2:Number = x2 * (x2 - x1 - x3) + x1 * x3;
			var d3:Number = x3 * (x3 - x1 - x2) + x1 * x2;
			var d4:Number = x1 * (x1 - x3);
			var d5:Number = x3 * (x3 - x1);

			var A:Number = y1 / d1 + y2 / d2 + y3 / d3;
			var B:Number = - y1 * (x2 + x3) / d1 - y2 * (x1 + x3) / d2 - y3 * (x1 + x2) / d3;
			var C:Number = x1 * x3 * y2 / d2 - x1 * x3 * y1 * x2 * (x2 - x3) / (d2 * d4) - x1 * x3 * y3 * x2 * (x2 - x1) / (d2 * d5);

			graphics.clear ();
			graphics.lineStyle (1, 255 * 256 * 256);

			for (var i:int = 0; i < 465; i += 3) {
				graphics [(i < 1) ? "moveTo" : "lineTo"] (i,
					A * i * i + B * i + C
				);
			}
		}
	}
}

import flash.display.Sprite;
import flash.events.MouseEvent;
class Anchor extends Sprite {
    public function Anchor (x0:int, y0:int) {
        x = x0; y = y0;
        graphics.beginFill (0xFF7F00, 1);
        graphics.drawRect (-4, -4, 8, 8);
        graphics.drawRect (-2, -2, 4, 4);
        graphics.beginFill (0xFF7F00, 0);
        graphics.drawRect (-2, -2, 4, 4);
        useHandCursor = buttonMode = true;
        addEventListener (MouseEvent.MOUSE_DOWN, startDragMe);
        addEventListener (MouseEvent.MOUSE_UP, stopDragMe);
    }
    public function startDragMe (e:MouseEvent):void {
        startDrag ();
    }
    public function stopDragMe (e:MouseEvent):void {
        stopDrag ();
    }
}