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.
这篇关于从一个坐标到另一个坐标的方位角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从一个坐标到另一个坐标的方位角
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
