gpt4 book ai didi

java - 从一个坐标到另一个坐标的方位

转载 作者:太空狗 更新时间:2023-10-29 22:41:51 26 4
gpt4 key购买 nike

我实现了 http://www.movable-type.co.uk/scripts/latlong.html 中的“轴承”公式.但这似乎非常不准确 - 我怀疑我的实现存在一些错误。你能帮我找到它吗?我的代码如下:

protected static double bearing(double lat1, double lon1, double lat2, double lon2){

double longDiff= lon2-lon1;
double y = Math.sin(longDiff)*Math.cos(lat2);
double x = Math.cos(lat1)*Math.sin(lat2)-Math.sin(lat1)*Math.cos(lat2)*Math.cos(longDiff);

return Math.toDegrees((Math.atan2(y, x))+360)%360;
}

最佳答案

这是最终代码:

protected static double bearing(double lat1, double lon1, double lat2, double lon2){
double longitude1 = lon1;
double longitude2 = lon2;
double latitude1 = Math.toRadians(lat1);
double latitude2 = Math.toRadians(lat2);
double longDiff= Math.toRadians(longitude2-longitude1);
double y= Math.sin(longDiff)*Math.cos(latitude2);
double x=Math.cos(latitude1)*Math.sin(latitude2)-Math.sin(latitude1)*Math.cos(latitude2)*Math.cos(longDiff);

return (Math.toDegrees(Math.atan2(y, x))+360)%360;
}

关于java - 从一个坐标到另一个坐标的方位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9457988/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com