最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript comma operator in java - Stack Overflow

matteradmin3PV0评论

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
Add a ment  | 

3 Answers 3

Reset to default 11

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:

  • 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));
Post a comment

comment list (0)

  1. No comments so far