Original Post
Suppose that an "angular range" is specified by a starting and ending angle, proceeding clockwise.
The first angular range is (a,b) and the second is (c,d). If both angular ranges span more than 180 degrees then it is possible that there are two intersection ranges. However if they do not EACH span more than 180 degrees, then the intersection can be represented as a single angular range denoted by (e,f). What is it?
In all cases, it is clear that e = a or c, and f = b or d.
A few examples to begin with:
intersection of (a=45, b=10) with (c=350, d=30) is (e=350, f=10)
intersection of (a=45, b=10) with (c=270, d=300) is (e=270, f=300)
intersection of (a=45, b=95) with (c=55, d=80) is (e=55, f=80)
Progress:
--------
After much mucking about looking for a simple analytical solution that doesn't seem to exist, I realized that if you sort all four angles (a,b,c,d) radially, then find the index "i" such that the angle between "i" and "i-1" (using modular indices) does not belong to either of the input angular ranges, then the intersection should be given by angles at indices "i+1" and "i+2".
Finding this index requires checking whether an angle belongs within a given angular range, and that requires a more mathematical definition of the set of angles in an angular range.
My first thought was that an angular range could be defined by the cross product.
That is, the range (a,b) could be written as the set
{ p \in (0,2pi) | cross(vec(a),vec(p)) > 0 && cross(vec(p), vec(b)) > 0 }
where vec(a) is the 2D cartesian vector represented by the angle 'a', and cross is the 2D analog of the cross product (ie, the z-component of the 3D cross product).
However, then I realized that this definition only works for angular ranges spanning less than 180 degrees. I'm having difficulty coming up with a simple mathematical definition that can be used to test whether a point is inside of an arbitrary angular range which might span more than 180 degrees.
Also, if anyone can think of a simpler overall approach, I'd be happy to hear it.
The first angular range is (a,b) and the second is (c,d). If both angular ranges span more than 180 degrees then it is possible that there are two intersection ranges. However if they do not EACH span more than 180 degrees, then the intersection can be represented as a single angular range denoted by (e,f). What is it?
In all cases, it is clear that e = a or c, and f = b or d.
A few examples to begin with:
intersection of (a=45, b=10) with (c=350, d=30) is (e=350, f=10)
intersection of (a=45, b=10) with (c=270, d=300) is (e=270, f=300)
intersection of (a=45, b=95) with (c=55, d=80) is (e=55, f=80)
Progress:
--------
After much mucking about looking for a simple analytical solution that doesn't seem to exist, I realized that if you sort all four angles (a,b,c,d) radially, then find the index "i" such that the angle between "i" and "i-1" (using modular indices) does not belong to either of the input angular ranges, then the intersection should be given by angles at indices "i+1" and "i+2".
Finding this index requires checking whether an angle belongs within a given angular range, and that requires a more mathematical definition of the set of angles in an angular range.
My first thought was that an angular range could be defined by the cross product.
That is, the range (a,b) could be written as the set
{ p \in (0,2pi) | cross(vec(a),vec(p)) > 0 && cross(vec(p), vec(b)) > 0 }
where vec(a) is the 2D cartesian vector represented by the angle 'a', and cross is the 2D analog of the cross product (ie, the z-component of the 3D cross product).
However, then I realized that this definition only works for angular ranges spanning less than 180 degrees. I'm having difficulty coming up with a simple mathematical definition that can be used to test whether a point is inside of an arbitrary angular range which might span more than 180 degrees.
Also, if anyone can think of a simpler overall approach, I'd be happy to hear it.