mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 10:28:39 +00:00
finalizing file. Added tests
This commit is contained in:
parent
eb4fb404e5
commit
a6d113a2da
@ -1,5 +1,6 @@
|
||||
from math import sqrt,pow
|
||||
from scipy.constants import G, pi, c
|
||||
from math import pow, sqrt
|
||||
|
||||
from scipy.constants import G, c, pi
|
||||
|
||||
"""
|
||||
These two functions will return the radii of impact for a target object
|
||||
@ -30,7 +31,7 @@ def capture_radii(
|
||||
Returns:
|
||||
--------
|
||||
>>> capture_radii(6.957e8, 1.99e30, 25000.0)
|
||||
17209590691
|
||||
17209590691.0
|
||||
>>> capture_radii(-6.957e8, 1.99e30, 25000.0)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
@ -43,13 +44,17 @@ def capture_radii(
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Cannot go beyond speed of light
|
||||
|
||||
Returned SI units:
|
||||
------------------
|
||||
meters | m
|
||||
"""
|
||||
|
||||
if(target_body_mass <0):
|
||||
if target_body_mass < 0:
|
||||
raise ValueError("Mass cannot be less than 0")
|
||||
elif(target_body_radius<0):
|
||||
elif target_body_radius < 0:
|
||||
raise ValueError("Radius cannot be less than 0")
|
||||
elif(projectile_velocity>c):
|
||||
elif projectile_velocity > c:
|
||||
raise ValueError("Cannot go beyond speed of light")
|
||||
|
||||
else:
|
||||
@ -58,17 +63,40 @@ def capture_radii(
|
||||
capture_radius = target_body_radius * sqrt(
|
||||
1 + escape_velocity_squared / pow(projectile_velocity, 2)
|
||||
)
|
||||
return round(capture_radius)
|
||||
return round(capture_radius, 0)
|
||||
|
||||
|
||||
def capture_area(capture_radius: float) -> float:
|
||||
"""
|
||||
Input Param:
|
||||
------------
|
||||
capture_radius: The radius of orbital capture and impact for a central body of
|
||||
mass M and a projectile moving towards it with velocity v
|
||||
SI units: meters | m
|
||||
Returns:
|
||||
--------
|
||||
>>> capture_area(17209590691)
|
||||
9.304455331329126e+20
|
||||
>>> capture_area(-1)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Cannot have a capture radius less than 0
|
||||
|
||||
sigma = pi * pow(capture_radius, 2)
|
||||
return sigma
|
||||
Returned SI units:
|
||||
------------------
|
||||
meters*meters | m**2
|
||||
"""
|
||||
|
||||
if capture_radius < 0:
|
||||
raise ValueError("Cannot have a capture radius less than 0")
|
||||
else:
|
||||
sigma = pi * pow(capture_radius, 2)
|
||||
return round(sigma, 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from doctest import testmod
|
||||
|
||||
testmod()
|
||||
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user