给定同一个圆的两个圆段:A = [a1,a2]和B = [b1,b2],其中:
如何确定这两个圆弧段是否重叠?(即,如果它们相交或接触至少一点)
例子:
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
这看起来像是一个看似简单的问题,但是我无法解决这个问题。目前,我对解决方案有一个基本的想法,该方案涉及将每个线段在相交0°时分成两部分,但是我不确定是否能涵盖所有情况,并且我想知道是否有一个优雅的公式。
如@admaoldak所述,请先将度数标准化:
a1_norm = a1 % 360 a2_norm = a2 % 360 b1_norm = b1 % 360 b2_norm = b2 % 360
现在检查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
最终答案是:
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)