2016-11-09 70 views
0

我正在開發一個小碼,我需要計算赤道平面中的角度差(即經度差)作爲角度差的函數一個大圓平面(由給定的緯度參數化)。大圓距離的赤道平面的NAN值和計算角

我用下面的公式從this wikipedia link

d(sigma) = arcos (sin(phi1).sin(phi2) + cos(phi1).cos(phi2).cos(d(lambda)) 

的目標是計算角度的d(lambda)差。在我的代碼,輸入參數是:

radius = 50 phi1 = 0 phi2 = initial latitude describe below d(sigma) = (distance/theta) where theta is the local angle in great circle plane and distance is the perimeter of this great circle.

在大圓面局部角度theta0開始,由0.01 step遞增。

知道phi1phi2distancetheta,我可以表達d(lambda)如(在Javascript語言):

var distance = radius*Math.abs(theta); 
var deltaLambda = Math.acos(Math.cos(distance/radius)/Math.cos(angleTheta)); 

angleTheta哪裏是起始點(由coordTorus THREE.Vector3標識)的緯度和等於:

var angleTheta = Math.atan(coordTorus.y/Math.sqrt(coordTorus.x * coordTorus.x + coordTorus.z * coordTorus.z)); 

我的問題是,等於的angleTheta的初始值,初始theta值等於0,那麼deltaLambda的計算是好的,但不是在其他情況下:

讓我們例如angleTheta = PI/4theta = 0的初始值,然後我有deltaLambdaNAN value因爲在上述公式,我得到:

var deltaLambda = Math.acos(Math.cos(0.5/50)/Math.cos(Math.PI/4)); 

所以我得到Math.acos(sqrt(2)) = NAN

我怎麼能繞過這個問題,並找到一個竅門與內部值保持進入[-1,1]區間?

我在上面的鏈接看到有其他計算大圓距離的公式,但我需要用這些公式隔離d(lambda)變量,我的意思是d(lambda)作爲其他參數的函數的符號表達式。

如果有人可以給出另一個一致的公式或找到一種方法來避免NAN value error,這將是很好的。

在此先感謝。

回答

0

對於lat1 = 0,lat2 = 45,大圓距不可能是半徑的1/100!最小可能的d是Sqrt(2)/2 * R。所以你採取非法的起始數據進行計算。

另一個問題 - 從笛卡爾座標獲取緯度的錯誤公式。Right one

lat = Arccos(z/R) 
or 
lat = atan(Sqrt(x^2+y^2)/z) 
+0

OK,這個問題似乎來自於THETA起始角(進入大圓面),但我不知道在這方面採取局部平面和赤道平面成相應角度的參數值。 – youpilat13