现在的位置: 首页 > 综合 > 正文

Android文档里java.lang.Math.atan2的一个错误

2013年08月20日 ⁄ 综合 ⁄ 共 833字 ⁄ 字号 评论关闭

Android文档里对Math.atan2这样解释的:

double java.lang.Math.atan2(double x, double y)

public static double atan2 (double x, double y)
Since: API Level 1
Returns the closest double approximation of the arc tangent of y/x within the range [-pi..pi]. This is the angle of the polar representation of the rectangular coordinates (x,y). The returned result is within 2 ulps (units in the last place) of the real result.

 

这里说的是 返回的结果相当于 (第一个参数x,第二个参数y)点对应的角度,对应y/x的值。

 

但是用了下怎么都不对。尤其是当x,y符号不同时更明显。

 

对照了一下JDK1.6的文档说明,原来是这样的,返回的结果相当于 (第二个参数,第一个参数)对应的角度。

 

double java.lang.Math.atan2(double y, double x)
public static double atan2(double y, double x)
Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi. Special cases:
If either argument is NaN, then the result is NaN.

 

按JDK中这样改就对了。

 

Android文档里竟然有这样的错误,用Android2.2 SDK也是一样的效果。

抱歉!评论已关闭.