File size: 1,437 Bytes
17da4a9
 
 
7e896b5
17da4a9
 
 
 
 
 
7e896b5
 
17da4a9
 
7e896b5
 
 
17da4a9
 
 
 
 
 
 
 
 
 
 
da30a1f
 
17da4a9
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import numpy as np


def angles_to_unit_vector(heading_angle_degrees, grazing_angle_degrees, left_looking=True):
    # Convert angles to radians
    heading_angle_start_at_east = 90 - heading_angle_degrees
    look_offset = 90 if left_looking else -90
    heading_los = heading_angle_start_at_east + look_offset
    heading_angle_radians = np.radians(heading_los)

    grazing_angle_sensor_to_ground = -(90 - grazing_angle_degrees)
    grazing_angle_radians = np.radians(grazing_angle_sensor_to_ground)

    # Calculate the vector components
    x_component = np.cos(heading_angle_radians) * np.cos(grazing_angle_radians)
    y_component = np.sin(heading_angle_radians) * np.cos(grazing_angle_radians)
    z_component = np.sin(grazing_angle_radians)

    # Create a NumPy array for the vector
    vector = np.array([x_component, y_component, z_component])

    # Normalize the vector to obtain the unit vector
    unit_vector = (vector / np.linalg.norm(vector)).round(5)

    return unit_vector


def unit_vector_to_hex(unit_vector):
    centered_rgb = (unit_vector + 1) * 127.5
    r, g, b = centered_rgb.round(0).astype(int)
    hex_color = f'#{r:02X}{g:02X}{b:02X}'
    return hex_color


def angles_to_hex(heading_angle_degrees, incidence_angle_degrees, left_looking=True):
    unit_vector = angles_to_unit_vector(heading_angle_degrees, incidence_angle_degrees, left_looking)
    hex = unit_vector_to_hex(unit_vector)
    return hex