Update physics/basic_orbital_capture.py

This commit is contained in:
Christian Clauss 2023-07-28 20:25:51 +02:00 committed by GitHub
parent a6d113a2da
commit c5ed1ae94f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -52,18 +52,16 @@ def capture_radii(
if target_body_mass < 0: if target_body_mass < 0:
raise ValueError("Mass cannot be less than 0") raise ValueError("Mass cannot be less than 0")
elif target_body_radius < 0: if target_body_radius < 0:
raise ValueError("Radius cannot be less than 0") raise ValueError("Radius cannot be less than 0")
elif projectile_velocity > c: if projectile_velocity > c:
raise ValueError("Cannot go beyond speed of light") raise ValueError("Cannot go beyond speed of light")
else: escape_velocity_squared = (2 * G * target_body_mass) / target_body_radius
escape_velocity_squared = (2 * G * target_body_mass) / target_body_radius capture_radius = target_body_radius * sqrt(
1 + escape_velocity_squared / pow(projectile_velocity, 2)
capture_radius = target_body_radius * sqrt( )
1 + escape_velocity_squared / pow(projectile_velocity, 2) return round(capture_radius, 0)
)
return round(capture_radius, 0)
def capture_area(capture_radius: float) -> float: def capture_area(capture_radius: float) -> float:
@ -89,9 +87,8 @@ def capture_area(capture_radius: float) -> float:
if capture_radius < 0: if capture_radius < 0:
raise ValueError("Cannot have a capture radius less than 0") raise ValueError("Cannot have a capture radius less than 0")
else: sigma = pi * pow(capture_radius, 2)
sigma = pi * pow(capture_radius, 2) return round(sigma, 0)
return round(sigma, 0)
if __name__ == "__main__": if __name__ == "__main__":