You can compute cross products between the pairs of vectors, and based on their signs find out their relative orientation.
Consider that you have vectors A, B and C
and you want to check whether C stays between A and B.
In this case if the cross products A x C, C x B and A x B have the same sign,
then it does.
In this solution it does not matter which angle is upper and which is lower.
Reference:
https://gamedev.stackexchange.com/questions/22392/what-is-a-good-way-to-determine-if-a-vector-is-between-two-other-vectors-in-2d
import math
def is_between(angle, first, second):
angle = math.radians(angle)
first = math.radians(first)
second = math.radians(second)
return (
sign(cross_product(first, angle)) ==
sign(cross_product(angle, second)) ==
sign(cross_product(first, second))
)
def cross_product(first, second):
first_x = math.cos(first)
first_y = math.sin(first)
second_x = math.cos(second)
second_y = math.sin(second)
return first_x * second_y - first_y * second_x
def sign(x):
return math.copysign(1, x)
Tests:
import pytest
from angle import is_between
@pytest.mark.parametrize(
'angle, first, second, expected',
[
(20, 0, 40, True),
(20, 30, 10, True),
(20, 30, 350, True),
(-5, 30, 350, True),
(-5, 30, 350, True),
(40, 30, 350, False),
(340, 30, 350, False),
(-20, 30, -10, False),
(25, 15, 270, False),
(25, 15, 90, True),
(25, 15, 194, True),
(25, 15, 270, False),
(90, 0, 179, True),
(90, 0, 181, False),
(90, 0, -179, False),
],
)
def test_is_between(angle, first, second, expected):
result = is_between(angle, first, second)
assert result == expected