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也是一樣的效果。