两个角度之间的最小差异 [英] The smallest difference between 2 Angles
问题描述
在一个坐标周围的-PI-> PI范围内有两个角度,它们之间的两个角度中最小的值是多少?
考虑到PI和-PI之间的差别不是2PI,而是零。
示例:
想象一个圆圈,有两条线从中心出来,这些线条之间有两个角度,它们在内部形成的角度又称为小角度,以及它们形成的角度外面,也就是更大的角度。两个角度加起来形成一个完整的圆。考虑到每个角度都可以在一定的范围内,考虑到滚动,角度值越小
$ p $
a = targetA - sourceA
a =(a + 180)%360 - 180
注意 左右: 如果角度在[-180,180]之内,这也是works: 以更详细的方式: Given 2 angles in the range -PI -> PI around a coordinate, what is the value of the smallest of the 2 angles between them? Taking into account that the difference between PI and -PI is not 2 PI but zero. Example: Imagine a circle, with 2 lines coming out from the center, there are 2 angles between those lines, the angle they make on the inside aka the smaller angle, and the angle they make on the outside, aka the bigger angle. Both angles when added up make a full circle. Given that each angle can fit within a certain range, what is the smaller angles value, taking into account the rollover This gives a signed angle for any angles: Beware in many languages the Or so: If angles are within [-180, 180] this also works: In a more verbose way:
这篇关于两个角度之间的最小差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!模数
操作返回一个与红利相同符号的值(如C,C ++,C#,JavaScript,完整列表)。这需要定制
mod
函数,如下所示: ,n)→> a - floor(a / n)* n
mod =(a,n) - > (a%n + n)%n
a = targetA - sourceA
a + =(a> 180)? -360:(a <-180)≤ 360:0
a = targetA - sourceA
a - = 360如果a> 180
a + = 360如果a < -180
a = targetA - sourceA
a = (a + 180) % 360 - 180
modulo
operation returns a value with the same sign as the dividend (like C, C++, C#, JavaScript, full list here). This requires a custom mod
function like so:mod = (a, n) -> a - floor(a/n) * n
mod = (a, n) -> (a % n + n) % n
a = targetA - sourceA
a += (a>180) ? -360 : (a<-180) ? 360 : 0
a = targetA - sourceA
a -= 360 if a > 180
a += 360 if a < -180