检查是否在同一圆周重叠两段/相交 [英] check if two segments on the same circle overlap / intersect
问题描述
由于同一个圆的两个圆弧段:A = [A1,A2]和B = [B1,B2],有:
Given two circle segments of the same circle: A=[a1, a2] and B=[b1, b2], with:
- 在A1,A2,B1,B2在-INF和+ INF之间的度值
- 在A1中= A2; B1< = B2
- A2-A1中= 360; B2-B1< = 360
我如何才能知道,如果这两个圆弧段重叠? (即,如果它们相交或触摸中的至少一个点)
How can I find out if these two circle segments overlap? (i.E. if they intersect or touch in at least one point)
例如:
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°的解决方案,一个基本的想法,但我不知道这涵盖了所有的情况,我想知道是否有一个优雅的公式。
This looks like a deceptively simple problem but I cannot wrap my head around it. I currently have a basic idea for a solution which involves splitting each segment into two if it crosses 0°, but I am not sure if that covers all cases, and I was wondering if there is an elegant formula.
推荐答案
由于@admaoldak提到的,首先规格化度:
As @admaoldak mentioned, normalize the degrees first:
a1_norm = a1 % 360
a2_norm = a2 % 360
b1_norm = b1 % 360
b2_norm = b2 % 360
现在,以检查是否B1内(A1,A2),
Now to check if b1 is within (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
最后的答案是:
Final answer is:
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)
这篇关于检查是否在同一圆周重叠两段/相交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!