-
- Notifications
You must be signed in to change notification settings - Fork 49.2k
in_static_equilibrium checks if a 2D static system is in equilibrium #1062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
19 commits Select commit Hold shift + click to select a range
ff020ef Add files via upload
QuantumNovice 67f06f5 Add files via upload
QuantumNovice 374fa2f Create .a
QuantumNovice 9132fa7 Add files via upload
QuantumNovice 4302d45 Add files via upload
QuantumNovice 6586ff4 Rename static_solver.py to in_static_equilibrium.py
QuantumNovice 01e4873 Delete .a
QuantumNovice dd6cfe9 Update in_static_equilibrium.py
QuantumNovice ffe5f2a Add files via upload
QuantumNovice 07d94f3 Add files via upload
QuantumNovice dc186f4 Update in_static_equilibrium.py
QuantumNovice b935764 Add files via upload
QuantumNovice aa834fe Add files via upload
QuantumNovice 6b5c8d3 Add files via upload
QuantumNovice 0af3ef0 Add files via upload
QuantumNovice ecb79ba pyTests added
QuantumNovice cb1b3e3 Add files via upload
QuantumNovice 4be19cc Delete red_black_tree.py
QuantumNovice 717b920 Add files via upload
QuantumNovice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """ | ||
| 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) | ||
| """ | ||
| 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], | ||
| ....] | ||
| """ | ||
| # summation of moments is zero | ||
| moments: array = cross(location, forces) | ||
| sum_moments: float = sum(moments) | ||
| return True if (abs(sum_moments) < eps) else False | ||
| | ||
| | ||
| 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), # | ||
QuantumNovice marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| ] | ||
| ) | ||
| | ||
| location = array([[0, 0], [0, 0], [0, 0]]) | ||
| | ||
| status = in_static_equilibrium(forces, location) | ||
| assert status | ||
QuantumNovice marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| | ||
| # 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]]) | ||
| | ||
| status = in_static_equilibrium(forces, location) | ||
| assert status | ||
QuantumNovice marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| | ||
| # 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]]) | ||
| | ||
| status = in_static_equilibrium(forces, location) | ||
| assert status | ||
QuantumNovice marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.