开发者

I keep coming up with the wrong calculation when using the vincenty formula

开发者 https://www.devze.com 2023-01-26 06:26 出处:网络
I\'m trying to use the formula from (www.movable-type.co.uk/scripts/latlong.html) to return a destination point giving a starting point, distance and bearing. These are my values:

I'm trying to use the formula from (www.movable-type.co.uk/scripts/latlong.html) to return a destination point giving a starting point, distance and bearing. These are my values:

int radius_km = 6371;
double d = 74.02;
double st_lat = 39.4450;
st_lat = Math.toRadians(st_lat); 
double bearing = 106.1607;
bearing = Math.toRadians(bearing);

double end_lat = Math.asin( Math.sin(st_lat)*Math.cos(d/radius_km) +
          Math.cos(st_lat)*Math.sin(d/radius_km)*Math.cos
          (bearing) );

end_lat = Math.toDegrees(end_lat);

When I enter the d, st_lat and bearing at the website, I get this: 39°33′28″N. When I use the above code (that I copied from the website) I get this: 39.25679699255662.

I looked around more a开发者_Python百科nd somebody said the division may not return the decimal amount, so I replaced the division with:

BigDecimal distance = new BigDecimal("74.02");
BigDecimal strradius = new BigDecimal("6371");
BigDecimal d2 = distance.divide(strradius, 6, RoundingMode.HALF_EVEN);
double d = d2.doubleValue();

and changed the formula to:

end_lat=Math.asin(Math.sin(st_lat)*
 Math.cos(d)+Math.cos(st_lat)*Math.sin(d)*Math.cos(bearing));

The answer I get now is 39.25680143864117. I'm sure I'm missing something but I'm not able to go through each step of the calculation to see where I'm off at. Does anybody have step-by-step instructions on how to do this? I would greatly appreciate it. Thanks.


Are you sure you are doing the correct conversion from minutes/seconds to decimals?

There are 60 minutes in a degree, 60 seconds in a minute. If the starting latitude is 39.4450; assuming that positive means north of the equator. If the bearing of 106.1607 is assumed to be measured from north going clockwise; would mean you are traveling southeast.

You said the website is telling you the answer is 39°33′28″N, but if I convert this to decimal, that is equal to 39+(33+28/60)/60 = 39.5578. This result is greater than your starting point, i.e., you are traveling southeast, but ending up north of your point.

I haven't looked at the math in your code yet, but off hand I would say your problem lies in the conversion from minutes/seconds to decimals and back.

0

精彩评论

暂无评论...
验证码 换一张
取 消