Skip to content

Commit b0f68a0

Browse files
tarushirastogipre-commit-ci[bot]SparshRastogi
authored
Create centripetal_force.py (TheAlgorithms#7778)
* Create centripetal_force.py Centripetal force is the force acting on an object in curvilinear motion directed towards the axis of rotation or centre of curvature. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update centripetal_force.py The value error should also handle negative values of the radius and using more descriptive names will be more beneficial for the users * Update centripetal_force.py Made some bug fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: SparshRastogi <[email protected]>
1 parent 327c38d commit b0f68a0

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

physics/centripetal_force.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
Description : Centripetal force is the force acting on an object in
3+
curvilinear motion directed towards the axis of rotation
4+
or centre of curvature.
5+
6+
The unit of centripetal force is newton.
7+
8+
The centripetal force is always directed perpendicular to the
9+
direction of the object’s displacement. Using Newton’s second
10+
law of motion, it is found that the centripetal force of an object
11+
moving in a circular path always acts towards the centre of the circle.
12+
The Centripetal Force Formula is given as the product of mass (in kg)
13+
and tangential velocity (in meters per second) squared, divided by the
14+
radius (in meters) that implies that on doubling the tangential velocity,
15+
the centripetal force will be quadrupled. Mathematically it is written as:
16+
F = mv²/r
17+
Where, F is the Centripetal force, m is the mass of the object, v is the
18+
speed or velocity of the object and r is the radius.
19+
20+
Reference: https://byjus.com/physics/centripetal-and-centrifugal-force/
21+
"""
22+
23+
24+
def centripetal(mass: float, velocity: float, radius: float) -> float:
25+
"""
26+
The Centripetal Force formula is given as: (m*v*v)/r
27+
28+
>>> round(centripetal(15.5,-30,10),2)
29+
1395.0
30+
>>> round(centripetal(10,15,5),2)
31+
450.0
32+
>>> round(centripetal(20,-50,15),2)
33+
3333.33
34+
>>> round(centripetal(12.25,40,25),2)
35+
784.0
36+
>>> round(centripetal(50,100,50),2)
37+
10000.0
38+
"""
39+
if mass < 0:
40+
raise ValueError("The mass of the body cannot be negative")
41+
if radius <= 0:
42+
raise ValueError("The radius is always a positive non zero integer")
43+
return (mass * (velocity) ** 2) / radius
44+
45+
46+
if __name__ == "__main__":
47+
import doctest
48+
49+
doctest.testmod(verbose=True)

0 commit comments

Comments
 (0)