For the interval [iX, iY] we 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 = iX + 360 2. i_slide.Y = iY + 360
we can prove that, for your input A and B , A overlaps with B if and only if:
normalize (A) overlap interval with normalize (B)
or
normalize (A) overlaps the interval with the slide (normalize (B))
interval overlaps are defined in the same way as "intersection" in post admoldak.
and both normalize () and slide () are easy to implement.
take your example: A=[-45°,45°]; B=[10°,20°] A=[-45°,45°]; B=[10°,20°] , we have
normalize(A) = [315,405] normalize(B) = [10,20] slide( normalize(B) ) = [370,380]
and [315,405] intervals overlap with [370,380]
source share