I'm trying to write a function that answers the question: if you start counting at a
and stop counting at b
, is c
in that range (aka is c
between a
and b
).
Normally a < c && c < b
would suffice, but I'm in modular arithmetic:
Counter-clockwise is increasing.
Green colors: are values for c where the algorithm should indicate true (where c is between a and b)
Blue colors: are values for c where the algorithm should indicate false (where c is not between a and b) (which happens to be the same as where c is between b and a)
The simple a < c && c < b
fails where the range of a
and b
crosses over 0.
For example, say A = 300 and B = 45. If C is 10 then the function should return true: 300, 301, 302 ... 359, 0, 1, 2, 3 ... 8, 9, 10, 11, 12 ... 43, 44, 45. Therefore, 10 is between 300 and 45 in mod 360.
Ultimately, what I'm trying to determine is if one hue is between two other hues, where hues are specified in degrees around a color wheel (which is a mod 360 system). It would be great if the answer was in terms of mod n so it would solve the general case and not be specific to my problem though.
a
from all three numbers. – Toots