check if two segments on the same circle overlap / intersect

前端 未结 3 1625
长情又很酷
长情又很酷 2020-12-06 19:55

Given two circle segments of the same circle: A=[a1, a2] and B=[b1, b2], with:

  • a1, a2, b1, b2 values in degree between -inf and +inf
  • a1 <= a2 ; b1
3条回答
  •  天涯浪人
    2020-12-06 20:24

    As @admaoldak mentioned, normalize the degrees first:

    a1_norm = a1 % 360
    a2_norm = a2 % 360
    b1_norm = b1 % 360
    b2_norm = b2 % 360
    

    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)
    

提交回复
热议问题