简体   繁体   English

Java中的javascript逗号运算符

[英]javascript comma operator in java

I'm trying to convert the following javascript to java 我正在尝试将以下javascript转换为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 comma after cos(lat1) does? 一切都很简单,只是我不确定cos(lat1)之后的逗号是什么? I read that in javascript it is used to assign the value after the coma to a variable while still evaluating the first expression, although in the above code the expression before the comma is not stored? 我读到它在javascript中用于将逗号后的值赋给变量,同时仍在评估第一个表达式,尽管在上面的代码中逗号前的表达式未存储?

Any help on converting this to java or understanding what the comma does? 将其转换为Java或了解逗号有什么帮助吗?

The original maths formula also has a comma 原始的数学公式也有一个逗号

φ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 . 它不是运算符,只是将两个参数分隔为atan2 It's exactly the same in Java. 在Java中完全相同

(Recall that atan2 takes the x and y components separately, in order to resolve rotational ambiguity.) (回想一下, atan2xy分量分开,以解决旋转歧义。)

Math.atan2 method accepts two arguments. Math.atan2方法接受两个参数。 Comma simply separates it. 逗号只是将其分开。

Math.atan2(y, x) 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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM