mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-30 16:31:08 +00:00
in_static_equilibrium checks if a 2D static system is in equilibrium (#1062)
* Add files via upload * Add files via upload * Create .a * Add files via upload * Add files via upload * Rename static_solver.py to in_static_equilibrium.py * Delete .a * Update in_static_equilibrium.py * Add files via upload * Add files via upload * Update in_static_equilibrium.py * Add files via upload * Add files via upload * Add files via upload * Add files via upload * pyTests added * Add files via upload * Delete red_black_tree.py * Add files via upload
This commit is contained in:
parent
3c8e9314b6
commit
c27bd5144f
BIN
arithmetic_analysis/image_data/2D_problems.JPG
Normal file
BIN
arithmetic_analysis/image_data/2D_problems.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 57 KiB |
BIN
arithmetic_analysis/image_data/2D_problems_1.JPG
Normal file
BIN
arithmetic_analysis/image_data/2D_problems_1.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
89
arithmetic_analysis/in_static_equilibrium.py
Normal file
89
arithmetic_analysis/in_static_equilibrium.py
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
"""
|
||||||
|
Checks if a system of forces is in static equilibrium.
|
||||||
|
|
||||||
|
python/black : true
|
||||||
|
flake8 : passed
|
||||||
|
mypy : passed
|
||||||
|
"""
|
||||||
|
|
||||||
|
from numpy import array, cos, sin, radians, cross # type: ignore
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
def polar_force(
|
||||||
|
magnitude: float, angle: float, radian_mode: bool = False
|
||||||
|
) -> List[float]:
|
||||||
|
"""
|
||||||
|
Resolves force along rectangular components.
|
||||||
|
(force, angle) => (force_x, force_y)
|
||||||
|
>>> polar_force(10, 45)
|
||||||
|
[7.0710678118654755, 7.071067811865475]
|
||||||
|
>>> polar_force(10, 3.14, radian_mode=True)
|
||||||
|
[-9.999987317275394, 0.01592652916486828]
|
||||||
|
"""
|
||||||
|
if radian_mode:
|
||||||
|
return [magnitude * cos(angle), magnitude * sin(angle)]
|
||||||
|
return [magnitude * cos(radians(angle)), magnitude * sin(radians(angle))]
|
||||||
|
|
||||||
|
|
||||||
|
def in_static_equilibrium(
|
||||||
|
forces: array, location: array, eps: float = 10 ** -1
|
||||||
|
) -> bool:
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
moments: array = cross(location, forces)
|
||||||
|
sum_moments: float = sum(moments)
|
||||||
|
return abs(sum_moments) < eps
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Test to check if it works
|
||||||
|
forces = array(
|
||||||
|
[
|
||||||
|
polar_force(718.4, 180 - 30),
|
||||||
|
polar_force(879.54, 45),
|
||||||
|
polar_force(100, -90)
|
||||||
|
])
|
||||||
|
|
||||||
|
location = array([[0, 0], [0, 0], [0, 0]])
|
||||||
|
|
||||||
|
assert in_static_equilibrium(forces, location)
|
||||||
|
|
||||||
|
# Problem 1 in image_data/2D_problems.jpg
|
||||||
|
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)
|
||||||
|
|
||||||
|
# Problem in image_data/2D_problems_1.jpg
|
||||||
|
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()
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user