查找两个轴承之间的角度 [英] Find the Angle between two Bearings

查看:96
本文介绍了查找两个轴承之间的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出两个轴承,我如何找到它们之间的最小角度?

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)
}

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆