我从 http://www.movable-type.co.uk 实现了轴承"公式/scripts/latlong.html.但这似乎非常不准确 - 我怀疑我的实施中有一些错误.你能帮我找到它吗?我的代码如下:
I implemented the "bearing" formula from http://www.movable-type.co.uk/scripts/latlong.html. But it seems highly inaccurate - I suspect some mistakes in my implementation. Could you help me with finding it? My code is below:
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;
}
你只是把括号 () 放错地方了.
You just have your parentheses () in the wrong place.
您正在为弧度值添加度数,这不起作用.toDegrees() 将为您完成从弧度到度数的转换,然后一旦您有度数的值,您就可以进行标准化.
You are adding degrees to a value in radians, which won't work. toDegrees() will do the conversion from radians to degrees for you, then you do the normalisation once you have a value in degrees.
你有:
Math.toDegrees( (Math.atan2(y, x))+360 ) % 360;
但你需要:
( Math.toDegrees(Math.atan2(y, x)) + 360 ) % 360;
还请记住,Math.sin()、Math.cos() 和所有其他三角函数的所有输入都必须以弧度表示.如果您的输入是度数,您需要先使用 Math.toRadians() 进行转换.
Remember also that all inputs to Math.sin(), Math.cos() and all the other trigonometric functions must be in radians. If your inputs are degrees you'll need to convert them using Math.toRadians() first.
这篇关于从一个坐标到另一个坐标的方位角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何检测 32 位 int 上的整数溢出?How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
return 语句之前的局部变量,这有关系吗?Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
如何将整数转换为整数?How to convert Integer to int?(如何将整数转换为整数?)
如何在给定范围内创建一个随机打乱数字的 intHow do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
java的行为不一致==Inconsistent behavior on java#39;s ==(java的行为不一致==)
为什么 Java 能够将 0xff000000 存储为 int?Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)