• 【设为首页】
  • 【收藏闪客居】
当前位置:主页>FLASH AS 编程>AS进阶篇>文章内容
  • 补全的myMath类
  • 来源:网络 作者:不详 2006-06-20 【
补全的myMath类
class myMath{
/*用角度制*/
 static function sinD(angle:Number):Number {
 return Math.sin (angle * (Math.PI / 180));
}

static function cosD(angle:Number):Number {
 return Math.cos (angle * (Math.PI / 180));
}

static function tanD(angle:Number):Number {
 return Math.tan (angle * (Math.PI / 180));
}

static  function asinD(ratio:Number):Number {
 return Math.asin (ratio) * (180 / Math.PI);
}

 static function acosD(ratio:Number):Number{
 return Math.acos (ratio) * (180 / Math.PI);
}

static function atanD(ratio:Number):Number {
 return Math.atan (ratio) * (180 / Math.PI);
}

static function atan2D(y:Number, x:Number):Number {
 return Math.atan2 (y, x) * (180 / Math.PI);
}
/*求两点间距离*/
 static function distance(x1:Number, y1:Number, x2:Number, y2:Number):Number{
        var dx:Number = x2 - x1;
 var dy:Number = y2 - y1;
 return Math.sqrt (dx*dx + dy*dy);
}
/*计算两点间连线的倾斜角*/
static function angleOfLine(x1:Number, y1:Number, x2:Number, y2:Number):Number {
 return atan2D (y2 - y1, x2 - x1);
}
/*度转换为弧度*/
static function degreesToRadians(angle:Number):Number {
 return angle * (Math.PI / 180);
}
/*弧度转换为度*/
static function radiansToDegrees(angle:Number):Number {
 return angle * (180 / Math.PI);
}
/*将一个角度转化为在0~360度之间*/
static function fixAngle(angle:Number):Number {
 angle %= 360;
 return (angle < 0) ? angle + 360 : angle;
}
/*将笛卡尔坐标系转化为极坐标系,p为点对象*/
static function cartesianToPolar (p:Object):Object {
 var radius:Number = Math.sqrt (p.x*p.x + p.y*p.y);
 var theta:Number = atan2D (p.y, p.x);
 return {r:radius, t:theta}
}
/*将极坐标系转化为笛卡尔坐标系*/
static function polarToCartesian(p:Object):Object{
 var x:Number = p.r * cosD (p.t);
 var y:Number = p.r * sinD (p.t);
 return {x:x, y:y}
}
}





上一篇:Flash中发送E-mail方法详解   下一篇:基于事件的程序设计
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)
FLASH源文件

Copyright © 2006-2008 flashas.net All Rights Reserved.
网站内容咨询: admin#flashas.net (#为@) 联系QQ:40777822 浙ICP备06033001号
(本网站最佳浏览解析度为1024*768, 建议使用IE 6.0或以上版本浏览器。)