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) )
It'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:
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));