I'm trying to convert the following javascript to java
var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) +
Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1),
Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));
it's all fairly simple except I'm unsure what the ma after cos(lat1) does? I read that in javascript it is used to assign the value after the a to a variable while still evaluating the first expression, although in the above code the expression before the ma is not stored?
Any help on converting this to java or understanding what the ma does?
The original maths formula also has a ma
φ2 = asin( sin(φ1)*cos(d/R) + cos(φ1)*sin(d/R)*cos(θ) )
λ2 = λ1 + atan2( sin(θ)*sin(d/R)*cos(φ1), cos(d/R)−sin(φ1)*sin(φ2) )
I'm trying to convert the following javascript to java
var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) +
Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1),
Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));
it's all fairly simple except I'm unsure what the ma after cos(lat1) does? I read that in javascript it is used to assign the value after the a to a variable while still evaluating the first expression, although in the above code the expression before the ma is not stored?
Any help on converting this to java or understanding what the ma does?
The original maths formula also has a ma
φ2 = asin( sin(φ1)*cos(d/R) + cos(φ1)*sin(d/R)*cos(θ) )
λ2 = λ1 + atan2( sin(θ)*sin(d/R)*cos(φ1), cos(d/R)−sin(φ1)*sin(φ2) )
Share
Improve this question
edited Jan 14, 2013 at 14:12
Danilo Valente
11.4k8 gold badges54 silver badges70 bronze badges
asked Jan 14, 2013 at 14:11
drunkmonkeydrunkmonkey
1,1911 gold badge17 silver badges27 bronze badges
3 Answers
Reset to default 11It's not an operator, it's simply separating the two arguments to atan2
. It's exactly the same in Java.
(Recall that atan2
takes the x
and y
ponents separately, in order to resolve rotational ambiguity.)
Math.atan2
method accepts two arguments. Comma simply separates it.
Math.atan2(y, x)
Returns the arctangent of the quotient of its arguments.
Reference:
- https://developer.mozilla/en-US/docs/JavaScript/Reference/Global_Objects/Math/atan2
The only change required is to give the variables a type.
double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / R) +
Math.cos(lat1) * Math.sin(d / R) * Math.cos(brng));
double lon2 = lon1 + Math.atan2(Math.sin(brng) * Math.sin(d / R) * Math.cos(lat1),
Math.cos(d / R) - Math.sin(lat1) * Math.sin(lat2));
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745630548a4637082.html
评论列表(0条)