S
S
Sergey Sokolov2020-03-05 18:01:16
Algorithms
Sergey Sokolov, 2020-03-05 18:01:16

How to correctly compare ranges of angles?

Two sectors are given: from angle A1 radians to angle A2 radians, and from angle B1 radians. up to B2 rad.
It is necessary to determine whether they have intersections.

How to solve it correctly-beautifully?

Something stalled with uncertainties when the angle can be set both as 7 * PI / 4, and it is also as -PI / 4.

illustration
5e6115dbb6fae548066185.png
The angles from the X-axis to the rays OA, OB, OC and OD are given.
Interested in whether the AOB and COD ranges intersect.


For unambiguity, each range can be considered a given angle of its bisector and half-width.

How to "correctly" normalize values?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Taus, 2020-03-05
@Taus

One of the solutions. Let the sector A be described by an ordered pair {A1,A2}, i.e., A sector is the area obtained by going around the circle in a clockwise direction from point A1 to point A2.
1. Bring the values ​​of all angles to the range from [0, 2pi).
2. If A1 > A2, then split the sector into two: S1 = [A1, 2pi) U [0, A2].
3. Using the set algebra and the algorithm of intersection of ordinary segments, one can find the intersection:
[A1, A2] ∩ [B1, B2] - the usual algorithm
( [A1, 2pi) U [0, A2] ) ∩ [B1, B2] = ( [B1, B2] ∩ [A1, 2pi) ) U ( [B1, B2] ∩ [0, A2] ) - for each of the intersections, the usual algorithm
( [A1, 2pi) U [0, A2] ) ∩ ( [B1 , 2pi) U [0, B2] ) - it is obvious that they intersect at least at the point 0

Z
Zolg, 2020-03-05
@Zolg

Something stalled with uncertainties, when the angle can be set both as 7 * PI / 4, and it is also as -PI / 4
The easiest way to avoid slipping with uncertainties is to normalize the input values ​​and continue to work with pure arithmetic

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question