Skip to content

math_helpers

utils.math_helpers

Math helpers for Blueprints.

utils.math_helpers.angle_to_slope

angle_to_slope(angle: DEG) -> PERCENTAGE

Convert an angle in degrees to a slope (as a percentage).

Parameters:

  • angle (DEG) –

    Angle in degrees.

Returns:

  • PERCENTAGE

    Slope as a percentage.

Source code in blueprints/utils/math_helpers.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def angle_to_slope(angle: DEG) -> PERCENTAGE:
    """Convert an angle in degrees to a slope (as a percentage).

    Parameters
    ----------
    angle : DEG
        Angle in degrees.

    Returns
    -------
    PERCENTAGE
        Slope as a percentage.
    """
    if angle == 90:
        return np.inf
    if angle == -90:
        return -np.inf
    raise_if_greater_than_90(angle=-angle)
    raise_if_greater_than_90(angle=angle)
    return np.tan(np.deg2rad(angle)) * 100

utils.math_helpers.cot

cot(x: DEG) -> DIMENSIONLESS

Calculate the cotangent of an angle in degrees.

Parameters:

  • x (DEG) –

    Angle in degrees.

Returns:

  • DIMENSIONLESS

    Cotangent of the angle.

Source code in blueprints/utils/math_helpers.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def cot(x: DEG) -> DIMENSIONLESS:
    """Calculate the cotangent of an angle in degrees.

    Parameters
    ----------
    x : DEG
        Angle in degrees.

    Returns
    -------
    DIMENSIONLESS
        Cotangent of the angle.
    """
    raise_if_less_or_equal_to_zero(x=x)
    raise_if_greater_than_90(x=x)
    return 1 / np.tan(np.deg2rad(x))

utils.math_helpers.csc

csc(x: DEG) -> DIMENSIONLESS

Calculate the cosecant of an angle in degrees.

Parameters:

  • x (DEG) –

    Angle in degrees.

Returns:

  • DIMENSIONLESS

    Cosecant of the angle.

Source code in blueprints/utils/math_helpers.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def csc(x: DEG) -> DIMENSIONLESS:
    """Calculate the cosecant of an angle in degrees.

    Parameters
    ----------
    x : DEG
        Angle in degrees.

    Returns
    -------
    DIMENSIONLESS
        Cosecant of the angle.
    """
    raise_if_less_or_equal_to_zero(x=x)
    raise_if_greater_than_90(x=x)
    return 1 / np.sin(np.deg2rad(x))

utils.math_helpers.sec

sec(x: DEG) -> DIMENSIONLESS

Calculate the secant of an angle in degrees.

Parameters:

  • x (DEG) –

    Angle in degrees.

Returns:

  • DIMENSIONLESS

    Secant of the angle.

Source code in blueprints/utils/math_helpers.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def sec(x: DEG) -> DIMENSIONLESS:
    """Calculate the secant of an angle in degrees.

    Parameters
    ----------
    x : DEG
        Angle in degrees.

    Returns
    -------
    DIMENSIONLESS
        Secant of the angle.
    """
    raise_if_negative(x=x)
    raise_if_greater_than_90(x=x)
    return 1 / np.cos(np.deg2rad(x))

utils.math_helpers.slope_to_angle

slope_to_angle(slope: PERCENTAGE) -> DEG

Convert a slope (as a percentage) to an angle in degrees.

Parameters:

  • slope (PERCENTAGE) –

    Slope as a percentage.

Returns:

  • DEG

    Angle in degrees.

Source code in blueprints/utils/math_helpers.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def slope_to_angle(slope: PERCENTAGE) -> DEG:
    """Convert a slope (as a percentage) to an angle in degrees.

    Parameters
    ----------
    slope : PERCENTAGE
        Slope as a percentage.

    Returns
    -------
    DEG
        Angle in degrees.
    """
    return np.rad2deg(np.arctan(slope / 100))