checks if a system of forces is in static equilibrium resolves force along rectangular components force angle forcex forcey import math force polarforce10 45 math iscloseforce0 7 071067811865477 true math iscloseforce1 7 0710678118654755 true force polarforce10 3 14 radianmodetrue math iscloseforce0 9 999987317275396 true math iscloseforce1 0 01592652916486828 true check if a system is in equilibrium it takes two numpy array objects forces force1x force1y force2x force2y location x1 y1 x2 y2 force array1 1 1 2 location array1 0 10 0 instaticequilibriumforce location false summation of moments is zero test to check if it works problem 1 in imagedata2dproblems jpg problem in imagedata2dproblems1 jpg resolves force along rectangular components force angle force_x force_y import math force polar_force 10 45 math isclose force 0 7 071067811865477 true math isclose force 1 7 0710678118654755 true force polar_force 10 3 14 radian_mode true math isclose force 0 9 999987317275396 true math isclose force 1 0 01592652916486828 true check if a system is in equilibrium it takes two numpy array objects forces force1_x force1_y force2_x force2_y location x1 y1 x2 y2 force array 1 1 1 2 location array 1 0 10 0 in_static_equilibrium force location false summation of moments is zero test to check if it works problem 1 in image_data 2d_problems jpg problem in image_data 2d_problems_1 jpg
from __future__ import annotations

from numpy import array, cos, cross, float64, radians, sin
from numpy.typing import NDArray


def polar_force(
    magnitude: float, angle: float, radian_mode: bool = False
) -> list[float]:
    
    if radian_mode:
        return [magnitude * cos(angle), magnitude * sin(angle)]
    return [magnitude * cos(radians(angle)), magnitude * sin(radians(angle))]


def in_static_equilibrium(
    forces: NDArray[float64], location: NDArray[float64], eps: float = 10**-1
) -> bool:
    
    
    moments: NDArray[float64] = cross(location, forces)
    sum_moments: float = sum(moments)
    return abs(sum_moments) < eps


if __name__ == "__main__":
    
    forces = array(
        [
            polar_force(718.4, 180 - 30),
            polar_force(879.54, 45),
            polar_force(100, -90),
        ]
    )

    location: NDArray[float64] = array([[0, 0], [0, 0], [0, 0]])

    assert in_static_equilibrium(forces, location)

    
    forces = array(
        [
            polar_force(30 * 9.81, 15),
            polar_force(215, 180 - 45),
            polar_force(264, 90 - 30),
        ]
    )

    location = array([[0, 0], [0, 0], [0, 0]])

    assert in_static_equilibrium(forces, location)

    
    forces = array([[0, -2000], [0, -1200], [0, 15600], [0, -12400]])

    location = array([[0, 0], [6, 0], [10, 0], [12, 0]])

    assert in_static_equilibrium(forces, location)

    import doctest

    doctest.testmod()