as3 atan与atan2函数差别

更新时间:15-10-23 21:31 热度:297
 

as3里,横竖切atan2函数比横竖切atan函数(即角的对边比邻边)更为有用,它可以让我们做出对物体准确的旋转.请记取flash里的y轴 坐标与算术的是颠倒的.(上头演习所示),flash是以弧度来计算的!坐标上的刻度值位置不太准,没校正大家就约略移到相应的点的位置上就可以证验下边 的列表值

atan(val:number) atan2(y:number,x:number)

弧度角度换算公式:

弧度转为角度
degree = radians * 180 / pi

角度转为弧度
radians = degree * pi / 180

当用atan函数时(注意是近似商):[弧度\度]

math.atan(1/2)≈0.4636476090008061≈26.56505117707799°
math.atan(-1/2)≈-0.4636476090008061≈-26.56505117707799°
math.atan(-1/-2)≈0.4636476090008061≈26.56505117707799°
math.atan(1/-2)≈-0.4636476090008061≈-26.56505117707799°

当用atan2函数时(注意是近似商):[弧度\度]

math.atan2(1,2)≈0.4636476090008061≈26.56505117707799°
math.atan2(-1,2)≈-0.4636476090008061≈-26.56505117707799°
math.atan2(-1,-2)≈-2.677945044588987≈-153.43494882292202°
math.atan2(1,-2)≈2.677945044588987≈153.43494882292202°