check if two segments on the same circle overlap / intersect

前端 未结 3 1618
长情又很酷
长情又很酷 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:21

    For an interval [i.X , i.Y] , let's define the normalization i_norm = normalize(i) so that :

    1. 0 <= i_norm.X < 360
    2. i_norm.X <=i_norm.Y
    

    then we define another operation i_slide = slide(i) so that :

    1. i_slide.X = i.X + 360
    2. i_slide.Y = i.Y + 360
    

    we can prove that, for your input A and B , A circle-overlaps with B if and only if :

    normalize(A) interval-overlaps with normalize(B)

    or

    normalize(A) interval-overlaps with slide( normalize(B))

    interval-overlaps is defined in the same way as "intersection" in adamoldak's post.

    and both operations normalize() and slide() are easy to be implemented.

    take your example: A=[-45°,45°]; B=[10°,20°] , we have

    normalize(A) = [315,405] 
    normalize(B) = [10,20] 
    slide( normalize(B) ) = [370,380]
    

    and [315,405] interval-overlaps with [370,380]

提交回复
热议问题