Untitled

mail@pastecode.io avatar
unknown
python
3 years ago
1.1 kB
4
Indexable
Never

def is_angle_in_between(left_angle, right_angle, test_angle):
    return left_angle <= test_angle <= right_angle

def range(angle_a, angle_b):
    result = angle_a - angle_b
    return float(result) if result >=0 else result+360.0

def apply_positive_rotation(angle, rotation):
    angle += rotation
    if angle >= 360.0:
        angle -= 360
    return angle

def determine_ranges(angle_a, angle_b, angle_direction):
    while True:
        if is_angle_in_between(angle_a, angle_b, angle_direction):
            return range(angle_b, angle_a)
        elif is_angle_in_between(angle_b, angle_a, angle_direction):
            return range(angle_a, angle_b)
        else: # rotation is required
            m = max(angle_a, angle_b, angle_direction)
            rotation_angle = 360.0-m
            angle_a = apply_positive_rotation(angle_a, rotation_angle)
            angle_b = apply_positive_rotation(angle_b, rotation_angle)
            angle_direction = apply_positive_rotation(angle_direction, rotation_angle)

print(determine_ranges(350,80,10))
print(determine_ranges(350,80,100))