Skip to content

Added archimedes principle (physics) #7143

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 5 commits into from
Oct 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions physics/archimedes_principle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Calculates buoyant force on object submerged within static fluid.
Discovered by greek mathematician, Archimedes. The principle is named after him.

Equation for calculating buoyant force:
Fb = ρ * V * g

Source:
- https://en.wikipedia.org/wiki/Archimedes%27_principle
"""


# Acceleration Constant on Earth (unit m/s^2)
g = 9.80665


def archimedes_principle(
fluid_density: float, volume: float, gravity: float = g
) -> float:
"""
Args:
fluid_density: density of fluid (kg/m^3)
volume: volume of object / liquid being displaced by object
gravity: Acceleration from gravity. Gravitational force on system,
Default is Earth Gravity
returns:
buoyant force on object in Newtons

>>> archimedes_principle(fluid_density=997, volume=0.5, gravity=9.8)
4885.3
>>> archimedes_principle(fluid_density=997, volume=0.7)
6844.061035
"""

if fluid_density <= 0:
raise ValueError("Impossible fluid density")
if volume < 0:
raise ValueError("Impossible Object volume")
if gravity <= 0:
raise ValueError("Impossible Gravity")

return fluid_density * gravity * volume


if __name__ == "__main__":
import doctest

# run doctest
doctest.testmod()