从轴承和距离计算纬度和长度 [英] calculating Lat and Long from Bearing and Distance
问题描述
我很难将头部缠绕在一些三角函数上。我试图从起始纬度和对数以及距离和方位推导出目的地纬度和经度。
I'm having a hard time wrapping my head around some Trigonometry. I am trying to deduce a destination latitude and longitude from a start lat and log and distance and bearing.
幸运的是,我发现了一个令人惊叹的网站,它描述了我需要的功能:
http://www.movable-type.co.uk/ scripts / latlong.html 目的地点给定距离并从起点开始承载
我在我的java程序中尝试过它,但它对我不起作用。我按照网站的说法部署了它。这是我的代码:
Fortunately, I found an amazing site which describes exactly the function I need: http://www.movable-type.co.uk/scripts/latlong.html " Destination point given distance and bearing from start point " I tried it in my java program but it is not working for me. I deployed it as the website said. Here is my code:
double dist = 150/6371;
double brng = Math.toRadians(90);
double lat1 = Math.toRadians(26.88288045572338);
double lon1 = Math.toRadians(75.78369140625);
double lat2 = Math.asin( Math.sin(lat1)*Math.cos(dist) + Math.cos(lat1)*Math.sin(dist)*Math.cos(brng) );
double a = Math.atan2(Math.sin(brng)*Math.sin(dist)*Math.cos(lat1), Math.cos(dist)-Math.sin(lat1)*Math.sin(lat2));
System.out.println("a = " + a);
double lon2 = lon1 + a;
lon2 = (lon2+ 3*Math.PI) % (2*Math.PI) - Math.PI;
System.out.println("Latitude = "+Math.toDegrees(lat2)+"\nLongitude = "+Math.toDegrees(lon2));
但它显示输出为:
a = 0.0
Latitude = 26.882880455723377
Longitude = 75.78369140625
我没有得到我在做错的地方。请任何人帮我解决问题。
I am not getting where i am doing the mistake. Please anybody can help me to find out the problem.
提前使用Thanx。 : - )
Thanx in Advance. :-)
推荐答案
你的问题就在你的第一行。
Your problem is on your first line.
尝试
double dist = 150.0 / 6371.0;
原因是 150/6371
获取计算为 0
,因为它执行整数除法(而不是浮点除法)。即使结果存储在 double
中也是如此。您可以通过使两个数字中的一个成为浮点字面值来强制浮点除法。
The reason is that 150/6371
gets calculated as 0
, because it performs integer division (rather than floating point division). This is true even though the result is being stored in a double
. You can force floating point division by making one of the two numbers a floating point literal.
这篇关于从轴承和距离计算纬度和长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!