检查同一圆上的两个段是否重叠/相交

Hug*_*une 5 language-agnostic algorithm geometry 2d angle

给定同一圆的两个圆弧段:A = [a1,a2],B = [b1,b2],其中:

  • a1,a2,b1,b2的值在-inf和+ inf之间
  • a1 <= a2; b1 <= b2
  • A2-A1 <= 360; B2-B1 <= 360

如何确定这两个圆弧段是否重叠?(即如果它们相交或触摸至少一个点)

例子:

A=[  -45°,    45°]; B=[   10°,   20°] ==> overlap
A=[  -45°,    45°]; B=[   90°,  180°] ==> no overlap
A=[  -45°,    45°]; B=[  180°,  360°] ==> overlap
A=[ -405°,  -315°]; B=[  180°,  360°] ==> overlap
A=[-3600°, -3601°]; B=[ 3601°, 3602°] ==> overlap (touching counts as overlap)
A=[ 3600°,  3601°]; B=[-3601°,-3602°] ==> overlap (touching counts as overlap)
A=[    -1°,    1°]; B=[ 3602°, 3603°] ==> no overlap 
Run Code Online (Sandbox Code Playgroud)

这看起来像一个看似简单的问题,但我无法绕过它.我目前有一个基本的想法,一个解决方案,如果它跨越0°分裂每个部分,但我不确定是否涵盖所有情况,我想知道是否有一个优雅的公式.

ElK*_*ina 10

正如@admaoldak所提到的,首先将度数标准化:

a1_norm = a1 % 360
a2_norm = a2 % 360
b1_norm = b1 % 360
b2_norm = b2 % 360
Run Code Online (Sandbox Code Playgroud)

现在检查b1是否在(a1,a2)之内,

def intersect(b, as, ae
    Intersect = False
    If as > ae:
        if b >= as or b <= ae:
            return True
    Else:
        if b>=as and b<=ae:
            return True
    return False
Run Code Online (Sandbox Code Playgroud)

最后的答案是:

intersect(b1_norm,a1_norm,a2_norm)||intersect(b2_norm,a1_norm,a2_norm)||
intersect(a1_norm,b1_norm,b2_norm)||intersect(a2_norm,b1_norm,b2_norm)
Run Code Online (Sandbox Code Playgroud)