//原作者:Robert Penner
//AS2.0改写:wiyiflash
//欢迎访问:http://www.wiyiflash.com/bbs
//-------------------------------------------------------
//ExtMath类扩展了Math类的功能
//AS2.0改写:wiyiflash
//欢迎访问:http://www.wiyiflash.com/bbs
//-------------------------------------------------------
//ExtMath类扩展了Math类的功能
class ExtMath extends Math { //实现静态成员的继承 private static var __proto__:Object; private static function init() { ExtMath.__proto__ = Math; _global.ASSetPropFlags(ExtMath, "__proto__,init", 7, 1); return true; } static var initFlag:Boolean = init(); //----------------------------------------------------------------- static function distance(x1:Number, y1:Number, x2:Number, y2:Number) { var dx = x2-x1; var dy = y2-y1; return Math.sqrt(dx*dx+dy*dy); } static function degreesToRadians(angle:Number) { return angle*(Math.PI/180); } static function radiansToDegrees(angle:Number) { return angle*(180/Math.PI); } static function sinD(angle:Number) { return Math.sin(angle*Math.PI/180); } static function asinD(ratio:Number) { return Math.asin(ratio)*(180/Math.PI); } static function cosD(angle:Number) { return Math.cos(angle*Math.PI/180); } static function acosD(ratio:Number) { return Math.acos(ratio)*(180/Math.PI); } static function tanD(angle:Number) { return Math.tan(angle*Math.PI/180); } static function atan2D(y:Number, x:Number) { return Math.atan2(y, x)*(180/Math.PI); } static function angleOfLine(x1:Number, y1:Number, x2:Number, y2:Number) { return atan2D(y2-y1, x2-x1); } //将角度修正为360度象限内 static function fixAngle(angle:Number) { return (angle %= 360)<0 ? angle+360 : angle; } //笛卡儿坐标转化为flash坐标 static function cartesianToFlash(o:Object) { o._y *= -1; o._rotation *= -1; } //flash坐标转化为笛卡儿坐标 static function flashToCartesian(o:Object) { return cartesianToFlash(o); } //极坐标转化为笛卡儿坐标 static function cartesianToPolar(p:Object) { //p={x,y}; var radius = Math.sqrt(p.x*p.x+p.y*p.y); var theta = atan2D(p.y, p.x); return {r:radius, t:theta}; } //笛卡儿坐标转化为极坐标 static function olarToCartesian(p:Object) { var x = p.r*cosD(p.t); var y = p.r*sinD(p.t); return {x:x, y:y}; } } |
[From 维艺--Flash论坛]