forked from: Rotation math
/**
* Copyright Good ( http://wonderfl.net/user/Good )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/5Hxd
*/
// forked from Good's Rotation math
package {
import flash.geom.Point;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.display.Sprite;
import flash.events.Event;
[SWF (width=465, height=465)]
public class M extends Sprite {
public function M () {
x = y = 465 / 2;
var tf:TextField = new TextField();
tf.autoSize = 'left';
tf.x = tf.y = -200;
addChild(tf);
tf.defaultTextFormat = new TextFormat('arial', 11, 0x333333, true);
var a:Point = new Point(Math.random() * 100, Math.random() * 100);
var b:Point = new Point(Math.random() * 100, Math.random() * 100);
addEventListener (Event.ENTER_FRAME, function (e:Event):void {
var c:Point = new Point( mouseX, mouseY );
var oabRad:Number = Math.atan2(a.x-b.x, a.y-b.y);
var oacRad:Number = Math.atan2(a.x-c.x, a.y-c.y);
var bacRad:Number = Math.PI - oabRad + oacRad;
var cx:Number = Math.cos(bacRad) * Point.distance(a,c);
var xx:Point = b.clone();
xx.offset(-a.x, -a.y);
xx.normalize(cx);
//var xx:Point = Point.polar(cx, -bacRad);
xx.offset(c.x, c.y);
graphics.clear ();
graphics.lineStyle (2);
graphics.moveTo (b.x, b.y);
graphics.lineTo (a.x, a.y);
graphics.lineTo(c.x, c.y);
graphics.lineTo(xx.x, xx.y);
var p:Point = Point.polar(50, bacRad-Math.PI)
graphics.moveTo (0,0);
graphics.lineTo (p.x, p.y);
tf.text = bacRad + '\n' + cx;
});
}
}
}