Friday 15 June 2012

java - How to calculate the angle of the direction from two GPS coordinates -


I have found a great way to calculate the direction angle from two coordinates, and I tried to solve the solution in Excel It worked fine when I almost typed the coordinates, but if I implemented the code in Java, then I got different results on the DCS (angle) double variable. The coordinates are fine, I checked them. :)

  Double loan 1 = (double) Math area (long latitude double * 1000000) / 1000000; Double latte 1 = (double) Math area (latitude double * 1000000) / 1000000; Double loan 2 = 1 9.05 5 54 54; Double Lot 2 = 47.569331; **************************************************************************************************** **************************************************************************************************** **************************************************************************************************** *********** Double DX = Mathematics (Math.PI / 180 * LAT1) * (lon2-lon1); Double dxy = Math.atan2 (dy, dx); Double degree = 180 / math PI * DXI;    

The reason for wandering excellence with your program code is that the use of the best argument logic Does: X, Y while programming languages ​​are like Java Usage Orders (Y, X) For this, see Doku.

In addition, in you and some other positions, the mathematical angles (moving toward east = 0 counterclockwise) and in the degree confuse geographical directions (compass rose): answer = 0, clockwise). Angle counts mathematical angles after you have to convert into geo directions, but:

You use incorrect formula, your formula works for cartesian coordinates (like screen numbers, pixels) Not for spherical (latitude, long) The effect between the two coordinates

atan2 for search here at [-pi, pi] One delivers value. But the geo direction is 0-360.

By right answer:

The effect / title / course from Lite 1, lon1 to lat, lon2 = 122.0402

So the formula is partially nonsense:
gives your code -32.04
1. then you first from-point and to-point ; An angle is measured from P1 to P2. (Mathematical vs Geo angle)

So you are messing up your own numbers. Compared to Java, you have typed in another number, or have posted the wrong number: Your Java code result-32.04 is using these numbers:

  double lon1 = 19.053143; Double latte 1 = 47.570518; Double loan 2 = 1 9.05 5 54 54; Double Lot 2 = 47.569331;    

No comments:

Post a Comment