Skip to content

Commit a6d113a

Browse files
committed
finalizing file. Added tests
1 parent eb4fb40 commit a6d113a

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

physics/basic_orbital_capture.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from math import sqrt,pow
2-
from scipy.constants import G, pi, c
1+
from math import pow, sqrt
2+
3+
from scipy.constants import G, c, pi
34

45
"""
56
These two functions will return the radii of impact for a target object
@@ -25,50 +26,77 @@ def capture_radii(
2526
-------------
2627
target_body_radius: Radius of the central body SI units: meters | m
2728
target_body_mass: Mass of the central body SI units: kilograms | kg
28-
projectile_velocity: Velocity of object moving toward central body
29+
projectile_velocity: Velocity of object moving toward central body
2930
SI units: meters/second | m/s
3031
Returns:
3132
--------
3233
>>> capture_radii(6.957e8, 1.99e30, 25000.0)
33-
17209590691
34+
17209590691.0
3435
>>> capture_radii(-6.957e8, 1.99e30, 25000.0)
3536
Traceback (most recent call last):
3637
...
3738
ValueError: Radius cannot be less than 0
3839
>>> capture_radii(6.957e8, -1.99e30, 25000.0)
3940
Traceback (most recent call last):
40-
...
41+
...
4142
ValueError: Mass cannot be less than 0
4243
>>> capture_radii(6.957e8, 1.99e30, c+1)
4344
Traceback (most recent call last):
44-
...
45+
...
4546
ValueError: Cannot go beyond speed of light
47+
48+
Returned SI units:
49+
------------------
50+
meters | m
4651
"""
47-
48-
if(target_body_mass <0):
52+
53+
if target_body_mass < 0:
4954
raise ValueError("Mass cannot be less than 0")
50-
elif(target_body_radius<0):
55+
elif target_body_radius < 0:
5156
raise ValueError("Radius cannot be less than 0")
52-
elif(projectile_velocity>c):
57+
elif projectile_velocity > c:
5358
raise ValueError("Cannot go beyond speed of light")
54-
59+
5560
else:
5661
escape_velocity_squared = (2 * G * target_body_mass) / target_body_radius
5762

5863
capture_radius = target_body_radius * sqrt(
5964
1 + escape_velocity_squared / pow(projectile_velocity, 2)
6065
)
61-
return round(capture_radius)
66+
return round(capture_radius, 0)
6267

6368

6469
def capture_area(capture_radius: float) -> float:
65-
66-
sigma = pi * pow(capture_radius, 2)
67-
return sigma
70+
"""
71+
Input Param:
72+
------------
73+
capture_radius: The radius of orbital capture and impact for a central body of
74+
mass M and a projectile moving towards it with velocity v
75+
SI units: meters | m
76+
Returns:
77+
--------
78+
>>> capture_area(17209590691)
79+
9.304455331329126e+20
80+
>>> capture_area(-1)
81+
Traceback (most recent call last):
82+
...
83+
ValueError: Cannot have a capture radius less than 0
84+
85+
Returned SI units:
86+
------------------
87+
meters*meters | m**2
88+
"""
89+
90+
if capture_radius < 0:
91+
raise ValueError("Cannot have a capture radius less than 0")
92+
else:
93+
sigma = pi * pow(capture_radius, 2)
94+
return round(sigma, 0)
6895

6996

7097
if __name__ == "__main__":
7198
from doctest import testmod
99+
72100
testmod()
73101

74102
"""

0 commit comments

Comments
 (0)