NAN value and computing angle in equatorial plane with great
I am developping a small code with which I need to compute the difference of angles in equatorial plane (ie the difference of longitudes) as a function of the angles difference in a great circle plane (parameterized by a given latitude).
I used the following formula from this wikipedia link :
d(sigma) = arcos (sin(phi1).sin(phi2) + cos(phi1).cos(phi2).cos(d(lambda))
The goal is to compute d(lambda)
difference of angle. In my code, input parameters are :
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.
local angle theta
in great circle plane starts from 0
and is incremented by 0.01 step
.
Knowing phi1
, phi2
, distance
and theta
, I can express d(lambda)
as (in Javascript language) :
var distance = radius*Math.abs(theta);
var deltaLambda = Math.acos(Math.cos(distance/radius) / Math.cos(angleTheta));
where angleTheta
is the latitude of starting point (identified by coordTorus
THREE.Vector3) and equal to :
var angleTheta = Math.atan(coordTorus.y / Math.sqrt(coordTorus.x * coordTorus.x + coordTorus.z * coordTorus.z));
My issue is that for an initial value of angleTheta
equal to 0
, an initial theta
value equal to 0
, then the computing of deltaLambda
is good but not in other cases :
Let's take for example an initial value of angleTheta = PI/4
and theta = 0
, then I have an NAN value
for deltaLambda
because in the above formula, I get :
var deltaLambda = Math.acos(Math.cos(0.5/50) / Math.cos(Math.PI/4));
So I get Math.acos(sqrt(2)) = NAN
How could I circumvent this issue and find a trick with which the value inside Math.accos
remains into [-1,1]
interval ?
I saw on above link there were others formulas for computing great-circle distance but I need to isolate the d(lambda)
variable with these formulas, I mean a symbolic expression of d(lambda)
as a function of others parameters.
If someone could give another consistent formula or find a way to avoid NAN value error
, this would be nice.
Thanks in advance.
It impossible that for lat1=0, lat2=45 great circle distance is 1/100 of radius! Minimal possible d is Sqrt(2)/2 * R
. So you take illegal starting data for calculations.
Another issue - wrong formula to get latitude from Cartesian coordinates. Right one:
lat = Arccos(z/R)
or
lat = atan(Sqrt(x^2+y^2) / z)
链接地址: http://www.djcxy.com/p/14880.html
上一篇: 使用三边测量应用的二维三边测量
下一篇: NAN值和赤道平面上的计算角度很大