Bearing from one coordinate to another(从一个坐标到另一个坐标的方位角)
问题描述
我从 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.
这篇关于从一个坐标到另一个坐标的方位角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从一个坐标到另一个坐标的方位角
基础教程推荐
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
