找到两个轴承之间的角度

Find the Angle between two Bearings(找到两个轴承之间的角度)
本文介绍了找到两个轴承之间的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

给定两个方位角,我如何找到它们之间的最小角度?

Given two bearing, how do I find the smallest angle between them?

例如,如果第一个航向是 340 度,第二个航向是 10 度,那么最小的角度就是 30 度.

So for example if 1 heading is 340 degrees and the second is 10 degrees the smallest angle will be 30 degrees.

我附上了一张图片来说明我的意思.我试过从另一个中减去一个,但由于圆圈的环绕效果,这不起作用.我也尝试过使用负度数(180 - 359 是 -180 到 0),但是在尝试计算正数和负数之间的角度时会搞砸.

I've attached a picture to show what I mean. I've tried subtracting one from the other but that didn't work because of the wrap around effect of a circle. I've also tried using negative degrees (180 - 359 being -180 to 0) but that got messed up when trying to calculate the angle between positive and negative number.

我确信必须有一种更简单的方法来处理大量 if 语句.

I'm sure there must be an easier way that having lots of if statements.

感谢您的帮助.亚当

顺便说一句.这是一个导航问题,所以圆的半径是未知的.

BTW. This is a navigation question so the radius of the circle is unknown.

推荐答案

float getDifference(float a1, float a2) {
    return Math.min((a1-a2)<0?a1-a2+360:a1-a2, (a2-a1)<0?a2-a1+360:a2-a1)
}

这篇关于找到两个轴承之间的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)