From 2e81e22b5a862da9e4f1cf2c2e678c279cff1a53 Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Sat, 8 Jul 2023 13:35:42 -0400 Subject: [PATCH 01/24] Added file basic_orbital_capture --- physics/basic_orbital_capture.py | 118 +++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 physics/basic_orbital_capture.py diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py new file mode 100644 index 000000000000..ea5935f3184f --- /dev/null +++ b/physics/basic_orbital_capture.py @@ -0,0 +1,118 @@ +import math + +""" +These two functions will return the radii of capture for a target object +of mass M and radius R as well as it's effective cross sectional area σ(sigma). +That is to say any projectile with velocity v passing within σ, will be caputered +by the target object with mass M. The derivation of which is given at the bottom +of this file. + +The derivation shows that a projectile does not need to aim directly at the target +body in order to hit it, as R_capture>R_target. Astronomers refer to the effective +cross section for caputre as σ=π*R_capture**2. + +This algorithm does not account for an N-body problem. + +""" + + + +def capture_radii( + target_body_radius: float, target_body_mass: float, + projectile_velocity: float + )->float: + + #Gravitational constant to four signifigant figures as of 7/8/2023| + #Source google: gravitational constant + g=6.6743e-11 #SI units (N*m**2)/kg**2 + + escape_velocity_squared=(2*g*target_body_mass)/target_body_radius + + capture_radius=target_body_radius*math.sqrt( + 1+escape_velocity_squared/math.pow(projectile_velocity,2) + ) + return capture_radius + + +def capture_area(capture_radius: float)->float: + sigma=math.pi*math.pow(capture_radius,2) + return sigma + + +""" +Derivation: + +Let: Mt=target mass, Rt=target radius, v=projectile_velocity, + r_0=radius of projectile at instant 0 to CM of target + v_p=v at closest approach, + r_p=radius from projectile to target CM at closest approach, + R_capture= radius of impact for projectile with velocity v + +(1)At time=0 the projectile's energy falling from infinity| E=K+U=0.5*m*(v**2)+0 + + E_initial=0.5*m*(v**2) + +(2)at time=0 the angular momentum of the projectile relative to CM target| + L_initial=m*r_0*v*sin(Θ)->m*r_0*v*(R_capture/r_0)->m*v*R_capture + + L_i=m*v*R_capture + +(3)The energy of the projectile at closest approach will be its kinetic energy + at closest approach plus gravitational potential energy(-(GMm)/R)| + E_p=K_p+U_p->E_p=0.5*m*(v_p**2)-(G*Mt*m)/r_p + + E_p=0.0.5*m*(v_p**2)-(G*Mt*m)/r_p + +(4)The angular momentum of the projectile relative to the target at closest + approach will be L_p=m*r_p*v_p*sin(Θ), however relative to the target Θ=90° + sin(90°)=1| + + L_p=m*r_p*v_p +(5)Using conservation of angular momentum and energy, we can write a quadratic + equation that solves for r_p| + + (a) + Ei=Ep-> 0.5*m*(v**2)=0.5*m*(v_p**2)-(G*Mt*m)/r_p-> v**2=v_p**2-(2*G*Mt)/r_p + + (b) + Li=Lp-> m*v*R_capture=m*r_p*v_p-> v*R_capture=r_p*v_p-> v_p=(v*R_capture)/r_p + + (c) b plugs int a| + v**2=((v*R_capture)/r_p)**2-(2*G*Mt)/r_p-> + + v**2-(v**2)*(R_c**2)/(r_p**2)+(2*G*Mt)/r_p=0-> + + (v**2)*(r_p**2)+2*G*Mt*r_p-(v**2)*(R_c**2)=0 + + (d) Using the quadratic formula, we'll solve for r_p then rearrange to solve to + R_capture + + r_p=(-2*G*Mt ± sqrt(4*G^2*Mt^2+ 4(v^4*R_c^2)))/(2*v^2)-> + + r_p=(-G*Mt ± sqrt(G^2*Mt+v^4*R_c^2))/v^2-> + + r_p<0 is something we can ignore, as it has no physical meaning for our purposes.-> + + r_p=(-G*Mt)/v^2 + sqrt(G^2*Mt^2/v^4 + R_c^2) + + (e)We are trying to solve for R_c. We are looking for capture, so we want r_p=Rt + + Rt + G*Mt/v^2 = sqrt(G^2*Mt^2/v^4 + R_c^2)-> + + (Rt + G*Mt/v^2)^2 = G^2*Mt^2/v^4 + R_c^2-> + + Rt^2 + 2*G*Mt*Rt/v^2 + G^2*Mt^2/v^4 = G^2*Mt^2/v^4 + R_c^2-> + + Rt**2 + 2*G*Mt*Rt/v**2 = R_c**2-> + + Rt**2 * (1 + 2*G*Mt/Rt *1/v**2) = R_c**2-> + + escape velocity = sqrt(2GM/R)= v_escape**2=2GM/R-> + + Rt**2 * (1 + v_esc**2/v**2) = R_c**2-> + +(6) + R_capture = Rt * sqrt(1 + v_esc**2/v**2) + +Source: Problem Set 3 #8 c.Fall_2017|Honors Astronomy|Professor Rachel Bezanson +""" From 8050929ba0f0b1310ac5a853e05ae74c4208ffbb Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 8 Jul 2023 17:36:35 +0000 Subject: [PATCH 02/24] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index d25d665ef28b..f4664fe68c45 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -745,6 +745,7 @@ ## Physics * [Archimedes Principle](physics/archimedes_principle.py) + * [Basic Orbital Capture](physics/basic_orbital_capture.py) * [Casimir Effect](physics/casimir_effect.py) * [Centripetal Force](physics/centripetal_force.py) * [Grahams Law](physics/grahams_law.py) From 9760f3641d2d60ca2292f71e48304b51fbcb2e9f Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Sat, 8 Jul 2023 14:22:34 -0400 Subject: [PATCH 03/24] added second source --- physics/basic_orbital_capture.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index ea5935f3184f..2d5f13a208d1 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -1,10 +1,10 @@ import math """ -These two functions will return the radii of capture for a target object +These two functions will return the radii of impact for a target object of mass M and radius R as well as it's effective cross sectional area σ(sigma). -That is to say any projectile with velocity v passing within σ, will be caputered -by the target object with mass M. The derivation of which is given at the bottom +That is to say any projectile with velocity v passing within σ, will impact the +target object with mass M. The derivation of which is given at the bottom of this file. The derivation shows that a projectile does not need to aim directly at the target @@ -95,7 +95,7 @@ def capture_area(capture_radius: float)->float: r_p=(-G*Mt)/v^2 + sqrt(G^2*Mt^2/v^4 + R_c^2) - (e)We are trying to solve for R_c. We are looking for capture, so we want r_p=Rt + (e)We are trying to solve for R_c. We are looking for impact, so we want r_p=Rt Rt + G*Mt/v^2 = sqrt(G^2*Mt^2/v^4 + R_c^2)-> @@ -115,4 +115,7 @@ def capture_area(capture_radius: float)->float: R_capture = Rt * sqrt(1 + v_esc**2/v**2) Source: Problem Set 3 #8 c.Fall_2017|Honors Astronomy|Professor Rachel Bezanson + +Source #2: http://www.nssc.ac.cn/wxzygx/weixin/201607/P020160718380095698873.pdf + 8.8 Planetary Rendevous: Pg.368 """ From 3b6df7598ead9eeffd0f53ad6bf8ae27039469c0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 8 Jul 2023 18:26:20 +0000 Subject: [PATCH 04/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/basic_orbital_capture.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index 2d5f13a208d1..45c6b1164402 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -16,26 +16,23 @@ """ - def capture_radii( - target_body_radius: float, target_body_mass: float, - projectile_velocity: float - )->float: - - #Gravitational constant to four signifigant figures as of 7/8/2023| - #Source google: gravitational constant - g=6.6743e-11 #SI units (N*m**2)/kg**2 + target_body_radius: float, target_body_mass: float, projectile_velocity: float +) -> float: + # Gravitational constant to four signifigant figures as of 7/8/2023| + # Source google: gravitational constant + g = 6.6743e-11 # SI units (N*m**2)/kg**2 - 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*math.sqrt( - 1+escape_velocity_squared/math.pow(projectile_velocity,2) - ) + capture_radius = target_body_radius * math.sqrt( + 1 + escape_velocity_squared / math.pow(projectile_velocity, 2) + ) return capture_radius -def capture_area(capture_radius: float)->float: - sigma=math.pi*math.pow(capture_radius,2) +def capture_area(capture_radius: float) -> float: + sigma = math.pi * math.pow(capture_radius, 2) return sigma From 3444fbd4ed619916a2709ab276eafef148242270 Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Sat, 8 Jul 2023 14:35:26 -0400 Subject: [PATCH 05/24] fixed spelling errors --- physics/basic_orbital_capture.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index 2d5f13a208d1..34ab8cd1b81d 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -9,7 +9,7 @@ The derivation shows that a projectile does not need to aim directly at the target body in order to hit it, as R_capture>R_target. Astronomers refer to the effective -cross section for caputre as σ=π*R_capture**2. +cross section for capture as σ=π*R_capture**2. This algorithm does not account for an N-body problem. @@ -22,7 +22,7 @@ def capture_radii( projectile_velocity: float )->float: - #Gravitational constant to four signifigant figures as of 7/8/2023| + #Gravitational constant to four significant figures as of 7/8/2023| #Source google: gravitational constant g=6.6743e-11 #SI units (N*m**2)/kg**2 @@ -117,5 +117,5 @@ def capture_area(capture_radius: float)->float: Source: Problem Set 3 #8 c.Fall_2017|Honors Astronomy|Professor Rachel Bezanson Source #2: http://www.nssc.ac.cn/wxzygx/weixin/201607/P020160718380095698873.pdf - 8.8 Planetary Rendevous: Pg.368 + 8.8 Planetary Rendezvous: Pg.368 """ From f1570fed31fbf202084589c0661f846c4b152032 Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Sat, 8 Jul 2023 14:43:31 -0400 Subject: [PATCH 06/24] accepted changes --- physics/basic_orbital_capture.py | 121 +++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 physics/basic_orbital_capture.py diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py new file mode 100644 index 000000000000..4fc7e36e8646 --- /dev/null +++ b/physics/basic_orbital_capture.py @@ -0,0 +1,121 @@ +import math + +""" +These two functions will return the radii of impact for a target object +of mass M and radius R as well as it's effective cross sectional area σ(sigma). +That is to say any projectile with velocity v passing within σ, will impact the +target object with mass M. The derivation of which is given at the bottom +of this file. + +The derivation shows that a projectile does not need to aim directly at the target +body in order to hit it, as R_capture>R_target. Astronomers refer to the effective +cross section for capture as σ=π*R_capture**2. + +This algorithm does not account for an N-body problem. + +""" + + +def capture_radii( + target_body_radius: float, target_body_mass: float, projectile_velocity: float +) -> float: + # Gravitational constant to four signifigant figures as of 7/8/2023| + # Source google: gravitational constant + g = 6.6743e-11 # SI units (N*m**2)/kg**2 + + #Gravitational constant to four significant figures as of 7/8/2023| + #Source google: gravitational constant + g=6.6743e-11 #SI units (N*m**2)/kg**2 + escape_velocity_squared = (2 * g * target_body_mass) / target_body_radius + + capture_radius = target_body_radius * math.sqrt( + 1 + escape_velocity_squared / math.pow(projectile_velocity, 2) + ) + return capture_radius + + +def capture_area(capture_radius: float) -> float: + sigma = math.pi * math.pow(capture_radius, 2) + return sigma + + +""" +Derivation: + +Let: Mt=target mass, Rt=target radius, v=projectile_velocity, + r_0=radius of projectile at instant 0 to CM of target + v_p=v at closest approach, + r_p=radius from projectile to target CM at closest approach, + R_capture= radius of impact for projectile with velocity v + +(1)At time=0 the projectile's energy falling from infinity| E=K+U=0.5*m*(v**2)+0 + + E_initial=0.5*m*(v**2) + +(2)at time=0 the angular momentum of the projectile relative to CM target| + L_initial=m*r_0*v*sin(Θ)->m*r_0*v*(R_capture/r_0)->m*v*R_capture + + L_i=m*v*R_capture + +(3)The energy of the projectile at closest approach will be its kinetic energy + at closest approach plus gravitational potential energy(-(GMm)/R)| + E_p=K_p+U_p->E_p=0.5*m*(v_p**2)-(G*Mt*m)/r_p + + E_p=0.0.5*m*(v_p**2)-(G*Mt*m)/r_p + +(4)The angular momentum of the projectile relative to the target at closest + approach will be L_p=m*r_p*v_p*sin(Θ), however relative to the target Θ=90° + sin(90°)=1| + + L_p=m*r_p*v_p +(5)Using conservation of angular momentum and energy, we can write a quadratic + equation that solves for r_p| + + (a) + Ei=Ep-> 0.5*m*(v**2)=0.5*m*(v_p**2)-(G*Mt*m)/r_p-> v**2=v_p**2-(2*G*Mt)/r_p + + (b) + Li=Lp-> m*v*R_capture=m*r_p*v_p-> v*R_capture=r_p*v_p-> v_p=(v*R_capture)/r_p + + (c) b plugs int a| + v**2=((v*R_capture)/r_p)**2-(2*G*Mt)/r_p-> + + v**2-(v**2)*(R_c**2)/(r_p**2)+(2*G*Mt)/r_p=0-> + + (v**2)*(r_p**2)+2*G*Mt*r_p-(v**2)*(R_c**2)=0 + + (d) Using the quadratic formula, we'll solve for r_p then rearrange to solve to + R_capture + + r_p=(-2*G*Mt ± sqrt(4*G^2*Mt^2+ 4(v^4*R_c^2)))/(2*v^2)-> + + r_p=(-G*Mt ± sqrt(G^2*Mt+v^4*R_c^2))/v^2-> + + r_p<0 is something we can ignore, as it has no physical meaning for our purposes.-> + + r_p=(-G*Mt)/v^2 + sqrt(G^2*Mt^2/v^4 + R_c^2) + + (e)We are trying to solve for R_c. We are looking for impact, so we want r_p=Rt + + Rt + G*Mt/v^2 = sqrt(G^2*Mt^2/v^4 + R_c^2)-> + + (Rt + G*Mt/v^2)^2 = G^2*Mt^2/v^4 + R_c^2-> + + Rt^2 + 2*G*Mt*Rt/v^2 + G^2*Mt^2/v^4 = G^2*Mt^2/v^4 + R_c^2-> + + Rt**2 + 2*G*Mt*Rt/v**2 = R_c**2-> + + Rt**2 * (1 + 2*G*Mt/Rt *1/v**2) = R_c**2-> + + escape velocity = sqrt(2GM/R)= v_escape**2=2GM/R-> + + Rt**2 * (1 + v_esc**2/v**2) = R_c**2-> + +(6) + R_capture = Rt * sqrt(1 + v_esc**2/v**2) + +Source: Problem Set 3 #8 c.Fall_2017|Honors Astronomy|Professor Rachel Bezanson + +Source #2: http://www.nssc.ac.cn/wxzygx/weixin/201607/P020160718380095698873.pdf + 8.8 Planetary Rendezvous: Pg.368 +""" From 5f91b01db0ac4cb769d9c79c4b217dd2f006d426 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 8 Jul 2023 18:43:48 +0000 Subject: [PATCH 07/24] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index d25d665ef28b..f4664fe68c45 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -745,6 +745,7 @@ ## Physics * [Archimedes Principle](physics/archimedes_principle.py) + * [Basic Orbital Capture](physics/basic_orbital_capture.py) * [Casimir Effect](physics/casimir_effect.py) * [Centripetal Force](physics/centripetal_force.py) * [Grahams Law](physics/grahams_law.py) From 06da0325b4ec6afcbea5c993ac3e166ab038cff2 Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Sat, 8 Jul 2023 14:46:20 -0400 Subject: [PATCH 08/24] corrected spelling error --- physics/basic_orbital_capture.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index 4fc7e36e8646..2d125cf019ee 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -19,7 +19,7 @@ def capture_radii( target_body_radius: float, target_body_mass: float, projectile_velocity: float ) -> float: - # Gravitational constant to four signifigant figures as of 7/8/2023| + # Gravitational constant to four significant figures as of 7/8/2023| # Source google: gravitational constant g = 6.6743e-11 # SI units (N*m**2)/kg**2 From 61427c7dd67d74226bf0778780574efd3a95a943 Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Sat, 8 Jul 2023 13:35:42 -0400 Subject: [PATCH 09/24] Added file basic_orbital_capture --- physics/basic_orbital_capture.py | 121 ------------------------------- 1 file changed, 121 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index 2d125cf019ee..e69de29bb2d1 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -1,121 +0,0 @@ -import math - -""" -These two functions will return the radii of impact for a target object -of mass M and radius R as well as it's effective cross sectional area σ(sigma). -That is to say any projectile with velocity v passing within σ, will impact the -target object with mass M. The derivation of which is given at the bottom -of this file. - -The derivation shows that a projectile does not need to aim directly at the target -body in order to hit it, as R_capture>R_target. Astronomers refer to the effective -cross section for capture as σ=π*R_capture**2. - -This algorithm does not account for an N-body problem. - -""" - - -def capture_radii( - target_body_radius: float, target_body_mass: float, projectile_velocity: float -) -> float: - # Gravitational constant to four significant figures as of 7/8/2023| - # Source google: gravitational constant - g = 6.6743e-11 # SI units (N*m**2)/kg**2 - - #Gravitational constant to four significant figures as of 7/8/2023| - #Source google: gravitational constant - g=6.6743e-11 #SI units (N*m**2)/kg**2 - escape_velocity_squared = (2 * g * target_body_mass) / target_body_radius - - capture_radius = target_body_radius * math.sqrt( - 1 + escape_velocity_squared / math.pow(projectile_velocity, 2) - ) - return capture_radius - - -def capture_area(capture_radius: float) -> float: - sigma = math.pi * math.pow(capture_radius, 2) - return sigma - - -""" -Derivation: - -Let: Mt=target mass, Rt=target radius, v=projectile_velocity, - r_0=radius of projectile at instant 0 to CM of target - v_p=v at closest approach, - r_p=radius from projectile to target CM at closest approach, - R_capture= radius of impact for projectile with velocity v - -(1)At time=0 the projectile's energy falling from infinity| E=K+U=0.5*m*(v**2)+0 - - E_initial=0.5*m*(v**2) - -(2)at time=0 the angular momentum of the projectile relative to CM target| - L_initial=m*r_0*v*sin(Θ)->m*r_0*v*(R_capture/r_0)->m*v*R_capture - - L_i=m*v*R_capture - -(3)The energy of the projectile at closest approach will be its kinetic energy - at closest approach plus gravitational potential energy(-(GMm)/R)| - E_p=K_p+U_p->E_p=0.5*m*(v_p**2)-(G*Mt*m)/r_p - - E_p=0.0.5*m*(v_p**2)-(G*Mt*m)/r_p - -(4)The angular momentum of the projectile relative to the target at closest - approach will be L_p=m*r_p*v_p*sin(Θ), however relative to the target Θ=90° - sin(90°)=1| - - L_p=m*r_p*v_p -(5)Using conservation of angular momentum and energy, we can write a quadratic - equation that solves for r_p| - - (a) - Ei=Ep-> 0.5*m*(v**2)=0.5*m*(v_p**2)-(G*Mt*m)/r_p-> v**2=v_p**2-(2*G*Mt)/r_p - - (b) - Li=Lp-> m*v*R_capture=m*r_p*v_p-> v*R_capture=r_p*v_p-> v_p=(v*R_capture)/r_p - - (c) b plugs int a| - v**2=((v*R_capture)/r_p)**2-(2*G*Mt)/r_p-> - - v**2-(v**2)*(R_c**2)/(r_p**2)+(2*G*Mt)/r_p=0-> - - (v**2)*(r_p**2)+2*G*Mt*r_p-(v**2)*(R_c**2)=0 - - (d) Using the quadratic formula, we'll solve for r_p then rearrange to solve to - R_capture - - r_p=(-2*G*Mt ± sqrt(4*G^2*Mt^2+ 4(v^4*R_c^2)))/(2*v^2)-> - - r_p=(-G*Mt ± sqrt(G^2*Mt+v^4*R_c^2))/v^2-> - - r_p<0 is something we can ignore, as it has no physical meaning for our purposes.-> - - r_p=(-G*Mt)/v^2 + sqrt(G^2*Mt^2/v^4 + R_c^2) - - (e)We are trying to solve for R_c. We are looking for impact, so we want r_p=Rt - - Rt + G*Mt/v^2 = sqrt(G^2*Mt^2/v^4 + R_c^2)-> - - (Rt + G*Mt/v^2)^2 = G^2*Mt^2/v^4 + R_c^2-> - - Rt^2 + 2*G*Mt*Rt/v^2 + G^2*Mt^2/v^4 = G^2*Mt^2/v^4 + R_c^2-> - - Rt**2 + 2*G*Mt*Rt/v**2 = R_c**2-> - - Rt**2 * (1 + 2*G*Mt/Rt *1/v**2) = R_c**2-> - - escape velocity = sqrt(2GM/R)= v_escape**2=2GM/R-> - - Rt**2 * (1 + v_esc**2/v**2) = R_c**2-> - -(6) - R_capture = Rt * sqrt(1 + v_esc**2/v**2) - -Source: Problem Set 3 #8 c.Fall_2017|Honors Astronomy|Professor Rachel Bezanson - -Source #2: http://www.nssc.ac.cn/wxzygx/weixin/201607/P020160718380095698873.pdf - 8.8 Planetary Rendezvous: Pg.368 -""" From edf9d254290f198e36f736ab1a1394d85e754ab4 Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Sat, 8 Jul 2023 14:22:34 -0400 Subject: [PATCH 10/24] added second source --- physics/basic_orbital_capture.py | 118 +++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index e69de29bb2d1..ea5935f3184f 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -0,0 +1,118 @@ +import math + +""" +These two functions will return the radii of capture for a target object +of mass M and radius R as well as it's effective cross sectional area σ(sigma). +That is to say any projectile with velocity v passing within σ, will be caputered +by the target object with mass M. The derivation of which is given at the bottom +of this file. + +The derivation shows that a projectile does not need to aim directly at the target +body in order to hit it, as R_capture>R_target. Astronomers refer to the effective +cross section for caputre as σ=π*R_capture**2. + +This algorithm does not account for an N-body problem. + +""" + + + +def capture_radii( + target_body_radius: float, target_body_mass: float, + projectile_velocity: float + )->float: + + #Gravitational constant to four signifigant figures as of 7/8/2023| + #Source google: gravitational constant + g=6.6743e-11 #SI units (N*m**2)/kg**2 + + escape_velocity_squared=(2*g*target_body_mass)/target_body_radius + + capture_radius=target_body_radius*math.sqrt( + 1+escape_velocity_squared/math.pow(projectile_velocity,2) + ) + return capture_radius + + +def capture_area(capture_radius: float)->float: + sigma=math.pi*math.pow(capture_radius,2) + return sigma + + +""" +Derivation: + +Let: Mt=target mass, Rt=target radius, v=projectile_velocity, + r_0=radius of projectile at instant 0 to CM of target + v_p=v at closest approach, + r_p=radius from projectile to target CM at closest approach, + R_capture= radius of impact for projectile with velocity v + +(1)At time=0 the projectile's energy falling from infinity| E=K+U=0.5*m*(v**2)+0 + + E_initial=0.5*m*(v**2) + +(2)at time=0 the angular momentum of the projectile relative to CM target| + L_initial=m*r_0*v*sin(Θ)->m*r_0*v*(R_capture/r_0)->m*v*R_capture + + L_i=m*v*R_capture + +(3)The energy of the projectile at closest approach will be its kinetic energy + at closest approach plus gravitational potential energy(-(GMm)/R)| + E_p=K_p+U_p->E_p=0.5*m*(v_p**2)-(G*Mt*m)/r_p + + E_p=0.0.5*m*(v_p**2)-(G*Mt*m)/r_p + +(4)The angular momentum of the projectile relative to the target at closest + approach will be L_p=m*r_p*v_p*sin(Θ), however relative to the target Θ=90° + sin(90°)=1| + + L_p=m*r_p*v_p +(5)Using conservation of angular momentum and energy, we can write a quadratic + equation that solves for r_p| + + (a) + Ei=Ep-> 0.5*m*(v**2)=0.5*m*(v_p**2)-(G*Mt*m)/r_p-> v**2=v_p**2-(2*G*Mt)/r_p + + (b) + Li=Lp-> m*v*R_capture=m*r_p*v_p-> v*R_capture=r_p*v_p-> v_p=(v*R_capture)/r_p + + (c) b plugs int a| + v**2=((v*R_capture)/r_p)**2-(2*G*Mt)/r_p-> + + v**2-(v**2)*(R_c**2)/(r_p**2)+(2*G*Mt)/r_p=0-> + + (v**2)*(r_p**2)+2*G*Mt*r_p-(v**2)*(R_c**2)=0 + + (d) Using the quadratic formula, we'll solve for r_p then rearrange to solve to + R_capture + + r_p=(-2*G*Mt ± sqrt(4*G^2*Mt^2+ 4(v^4*R_c^2)))/(2*v^2)-> + + r_p=(-G*Mt ± sqrt(G^2*Mt+v^4*R_c^2))/v^2-> + + r_p<0 is something we can ignore, as it has no physical meaning for our purposes.-> + + r_p=(-G*Mt)/v^2 + sqrt(G^2*Mt^2/v^4 + R_c^2) + + (e)We are trying to solve for R_c. We are looking for capture, so we want r_p=Rt + + Rt + G*Mt/v^2 = sqrt(G^2*Mt^2/v^4 + R_c^2)-> + + (Rt + G*Mt/v^2)^2 = G^2*Mt^2/v^4 + R_c^2-> + + Rt^2 + 2*G*Mt*Rt/v^2 + G^2*Mt^2/v^4 = G^2*Mt^2/v^4 + R_c^2-> + + Rt**2 + 2*G*Mt*Rt/v**2 = R_c**2-> + + Rt**2 * (1 + 2*G*Mt/Rt *1/v**2) = R_c**2-> + + escape velocity = sqrt(2GM/R)= v_escape**2=2GM/R-> + + Rt**2 * (1 + v_esc**2/v**2) = R_c**2-> + +(6) + R_capture = Rt * sqrt(1 + v_esc**2/v**2) + +Source: Problem Set 3 #8 c.Fall_2017|Honors Astronomy|Professor Rachel Bezanson +""" From d5e5dde6b87e61a91c0b4cea3b441526bd2aad78 Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Sat, 8 Jul 2023 14:35:26 -0400 Subject: [PATCH 11/24] fixed spelling errors --- physics/basic_orbital_capture.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index ea5935f3184f..002b304e8715 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -9,7 +9,7 @@ The derivation shows that a projectile does not need to aim directly at the target body in order to hit it, as R_capture>R_target. Astronomers refer to the effective -cross section for caputre as σ=π*R_capture**2. +cross section for capture as σ=π*R_capture**2. This algorithm does not account for an N-body problem. @@ -22,7 +22,7 @@ def capture_radii( projectile_velocity: float )->float: - #Gravitational constant to four signifigant figures as of 7/8/2023| + #Gravitational constant to four significant figures as of 7/8/2023| #Source google: gravitational constant g=6.6743e-11 #SI units (N*m**2)/kg**2 @@ -115,4 +115,7 @@ def capture_area(capture_radius: float)->float: R_capture = Rt * sqrt(1 + v_esc**2/v**2) Source: Problem Set 3 #8 c.Fall_2017|Honors Astronomy|Professor Rachel Bezanson + +Source #2: http://www.nssc.ac.cn/wxzygx/weixin/201607/P020160718380095698873.pdf + 8.8 Planetary Rendezvous: Pg.368 """ From de4da186292260acac3a2073b311f8e066d70926 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 8 Jul 2023 18:26:20 +0000 Subject: [PATCH 12/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/basic_orbital_capture.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index 002b304e8715..9db92c85a252 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -16,26 +16,29 @@ """ - def capture_radii( - target_body_radius: float, target_body_mass: float, - projectile_velocity: float - )->float: + target_body_radius: float, target_body_mass: float, projectile_velocity: float +) -> float: + # Gravitational constant to four signifigant figures as of 7/8/2023| + # Source google: gravitational constant + g = 6.6743e-11 # SI units (N*m**2)/kg**2 +<<<<<<< HEAD #Gravitational constant to four significant figures as of 7/8/2023| #Source google: gravitational constant g=6.6743e-11 #SI units (N*m**2)/kg**2 +======= + escape_velocity_squared = (2 * g * target_body_mass) / target_body_radius +>>>>>>> 3b6df759 ([pre-commit.ci] auto fixes from pre-commit.com hooks) - escape_velocity_squared=(2*g*target_body_mass)/target_body_radius - - capture_radius=target_body_radius*math.sqrt( - 1+escape_velocity_squared/math.pow(projectile_velocity,2) - ) + capture_radius = target_body_radius * math.sqrt( + 1 + escape_velocity_squared / math.pow(projectile_velocity, 2) + ) return capture_radius -def capture_area(capture_radius: float)->float: - sigma=math.pi*math.pow(capture_radius,2) +def capture_area(capture_radius: float) -> float: + sigma = math.pi * math.pow(capture_radius, 2) return sigma From d34a68c7a77155b8a22ca0c9cdf55d4aacbc0dcf Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Sat, 8 Jul 2023 15:09:30 -0400 Subject: [PATCH 13/24] applied changes --- physics/basic_orbital_capture.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index cffca493339a..efdb4d938f08 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -23,11 +23,9 @@ def capture_radii( # Source google: gravitational constant g = 6.6743e-11 # SI units (N*m**2)/kg**2 -<<<<<<< HEAD #Gravitational constant to four significant figures as of 7/8/2023| #Source google: gravitational constant g=6.6743e-11 #SI units (N*m**2)/kg**2 -======= escape_velocity_squared = (2 * g * target_body_mass) / target_body_radius capture_radius = target_body_radius * math.sqrt( From 57e08afa607f0b652caabe300aa696dc4515f3ea Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Sat, 8 Jul 2023 15:12:02 -0400 Subject: [PATCH 14/24] reviewed and checked file --- physics/basic_orbital_capture.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index efdb4d938f08..5908f06bdf19 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -1,10 +1,10 @@ import math """ -These two functions will return the radii of capture for a target object +These two functions will return the radii of impact for a target object of mass M and radius R as well as it's effective cross sectional area σ(sigma). -That is to say any projectile with velocity v passing within σ, will be caputered -by the target object with mass M. The derivation of which is given at the bottom +That is to say any projectile with velocity v passing within σ, will impact the +target object with mass M. The derivation of which is given at the bottom of this file. The derivation shows that a projectile does not need to aim directly at the target @@ -26,6 +26,8 @@ def capture_radii( #Gravitational constant to four significant figures as of 7/8/2023| #Source google: gravitational constant g=6.6743e-11 #SI units (N*m**2)/kg**2 + + escape_velocity_squared = (2 * g * target_body_mass) / target_body_radius capture_radius = target_body_radius * math.sqrt( @@ -95,7 +97,7 @@ def capture_area(capture_radius: float) -> float: r_p=(-G*Mt)/v^2 + sqrt(G^2*Mt^2/v^4 + R_c^2) - (e)We are trying to solve for R_c. We are looking for capture, so we want r_p=Rt + (e)We are trying to solve for R_c. We are looking for impact, so we want r_p=Rt Rt + G*Mt/v^2 = sqrt(G^2*Mt^2/v^4 + R_c^2)-> From bcc341589b82af076fc2077e45c63f9ea5d90149 Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Sat, 8 Jul 2023 15:20:08 -0400 Subject: [PATCH 15/24] added doctest --- physics/basic_orbital_capture.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index 5908f06bdf19..33aa5bba5e16 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -40,6 +40,10 @@ def capture_area(capture_radius: float) -> float: sigma = math.pi * math.pow(capture_radius, 2) return sigma +if __name__ == "__main__": + import doctest + + doctest.testmod() """ Derivation: From a349b7bcb7b85d2deaae4e9818bd1b66f713749f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 8 Jul 2023 19:25:20 +0000 Subject: [PATCH 16/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/basic_orbital_capture.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index 33aa5bba5e16..9e06533ffde0 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -23,10 +23,9 @@ def capture_radii( # Source google: gravitational constant g = 6.6743e-11 # SI units (N*m**2)/kg**2 - #Gravitational constant to four significant figures as of 7/8/2023| - #Source google: gravitational constant - g=6.6743e-11 #SI units (N*m**2)/kg**2 - + # Gravitational constant to four significant figures as of 7/8/2023| + # Source google: gravitational constant + g = 6.6743e-11 # SI units (N*m**2)/kg**2 escape_velocity_squared = (2 * g * target_body_mass) / target_body_radius @@ -40,6 +39,7 @@ def capture_area(capture_radius: float) -> float: sigma = math.pi * math.pow(capture_radius, 2) return sigma + if __name__ == "__main__": import doctest From 0ef592b1e862f35cbdddfdb0fcc7bbc5d062be3c Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Sun, 9 Jul 2023 10:50:48 -0400 Subject: [PATCH 17/24] removed redundant constnant --- physics/basic_orbital_capture.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index 9e06533ffde0..6f3c5f068420 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -22,11 +22,7 @@ def capture_radii( # Gravitational constant to four significant figures as of 7/8/2023| # Source google: gravitational constant g = 6.6743e-11 # SI units (N*m**2)/kg**2 - - # Gravitational constant to four significant figures as of 7/8/2023| - # Source google: gravitational constant - g = 6.6743e-11 # SI units (N*m**2)/kg**2 - + escape_velocity_squared = (2 * g * target_body_mass) / target_body_radius capture_radius = target_body_radius * math.sqrt( @@ -39,7 +35,6 @@ def capture_area(capture_radius: float) -> float: sigma = math.pi * math.pow(capture_radius, 2) return sigma - if __name__ == "__main__": import doctest From 233722443cd8f727e404ab5c353cd882e1328df4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 9 Jul 2023 14:53:25 +0000 Subject: [PATCH 18/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/basic_orbital_capture.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index 6f3c5f068420..9f5fc9f85e1d 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -22,7 +22,7 @@ def capture_radii( # Gravitational constant to four significant figures as of 7/8/2023| # Source google: gravitational constant g = 6.6743e-11 # SI units (N*m**2)/kg**2 - + escape_velocity_squared = (2 * g * target_body_mass) / target_body_radius capture_radius = target_body_radius * math.sqrt( @@ -35,6 +35,7 @@ def capture_area(capture_radius: float) -> float: sigma = math.pi * math.pow(capture_radius, 2) return sigma + if __name__ == "__main__": import doctest From 964b454248253cdf6ca5abca5cc1d50f554d593b Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Thu, 13 Jul 2023 10:08:06 -0400 Subject: [PATCH 19/24] added scipy imports --- physics/basic_orbital_capture.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index 9f5fc9f85e1d..f0c013d1488c 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -1,4 +1,6 @@ -import math +from math import sqrt,pow +from scipy.constants import G as g +from scipy.constants import pi as pi """ These two functions will return the radii of impact for a target object @@ -25,14 +27,14 @@ def capture_radii( escape_velocity_squared = (2 * g * target_body_mass) / target_body_radius - capture_radius = target_body_radius * math.sqrt( - 1 + escape_velocity_squared / math.pow(projectile_velocity, 2) + capture_radius = target_body_radius * sqrt( + 1 + escape_velocity_squared / pow(projectile_velocity, 2) ) return capture_radius def capture_area(capture_radius: float) -> float: - sigma = math.pi * math.pow(capture_radius, 2) + sigma = pi * pow(capture_radius, 2) return sigma From f38d19b7f916002e81e75dea3c4cc3749eb6ceea Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 13 Jul 2023 14:10:57 +0000 Subject: [PATCH 20/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/basic_orbital_capture.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index f0c013d1488c..01747c0ed734 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -1,6 +1,6 @@ -from math import sqrt,pow +from math import sqrt, pow from scipy.constants import G as g -from scipy.constants import pi as pi +from scipy.constants import pi as pi """ These two functions will return the radii of impact for a target object From 6a805073b75ad153b9984b13144663ee232d6b31 Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Thu, 13 Jul 2023 15:05:31 -0400 Subject: [PATCH 21/24] added doctests to capture_radii and scipy const --- physics/basic_orbital_capture.py | 58 +++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index f0c013d1488c..4b5f1e3e881d 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -1,6 +1,5 @@ from math import sqrt,pow -from scipy.constants import G as g -from scipy.constants import pi as pi +from scipy.constants import G, pi, c """ These two functions will return the radii of impact for a target object @@ -21,27 +20,56 @@ def capture_radii( target_body_radius: float, target_body_mass: float, projectile_velocity: float ) -> float: - # Gravitational constant to four significant figures as of 7/8/2023| - # Source google: gravitational constant - g = 6.6743e-11 # SI units (N*m**2)/kg**2 - - 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) - ) - return capture_radius + """ + Input Params: + ------------- + target_body_radius: Radius of the central body SI units: meters | m + target_body_mass: Mass of the central body SI units: kilograms | kg + projectile_velocity: Velocity of object moving toward central body + SI units: meters/second | m/s + Returns: + -------- + >>> capture_radii(6.957e8, 1.99e30, 25000.0) + 17209590691 + >>> capture_radii(-6.957e8, 1.99e30, 25000.0) + Traceback (most recent call last): + ... + ValueError: Radius cannot be less than 0 + >>> capture_radii(6.957e8, -1.99e30, 25000.0) + Traceback (most recent call last): + ... + ValueError: Mass cannot be less than 0 + >>> capture_radii(6.957e8, 1.99e30, c+1) + Traceback (most recent call last): + ... + ValueError: Cannot go beyond speed of light + """ + + if(target_body_mass <0): + raise ValueError("Mass cannot be less than 0") + elif(target_body_radius<0): + raise ValueError("Radius cannot be less than 0") + elif(projectile_velocity>c): + raise ValueError("Cannot go beyond speed of light") + + else: + 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) + ) + return round(capture_radius) def capture_area(capture_radius: float) -> float: + sigma = pi * pow(capture_radius, 2) return sigma if __name__ == "__main__": - import doctest - - doctest.testmod() + from doctest import testmod + testmod() """ Derivation: From eb4fb404e5a30ac488ee12eaba656c52c3e3cca2 Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Thu, 13 Jul 2023 15:06:56 -0400 Subject: [PATCH 22/24] fixed conflicts --- physics/basic_orbital_capture.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index b3e280fb578a..4b5f1e3e881d 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -1,11 +1,5 @@ -<<<<<<< HEAD from math import sqrt,pow from scipy.constants import G, pi, c -======= -from math import sqrt, pow -from scipy.constants import G as g -from scipy.constants import pi as pi ->>>>>>> f38d19b7f916002e81e75dea3c4cc3749eb6ceea """ These two functions will return the radii of impact for a target object From a6d113a2dafb9cdec024bd3277edbc5154754ec2 Mon Sep 17 00:00:00 2001 From: FatAnorexic Date: Thu, 13 Jul 2023 16:02:42 -0400 Subject: [PATCH 23/24] finalizing file. Added tests --- physics/basic_orbital_capture.py | 58 +++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index 4b5f1e3e881d..b3655176756a 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -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 @@ -25,50 +26,77 @@ def capture_radii( ------------- target_body_radius: Radius of the central body SI units: meters | m target_body_mass: Mass of the central body SI units: kilograms | kg - projectile_velocity: Velocity of object moving toward central body + projectile_velocity: Velocity of object moving toward central body SI units: meters/second | m/s 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): ... ValueError: Radius cannot be less than 0 >>> capture_radii(6.957e8, -1.99e30, 25000.0) Traceback (most recent call last): - ... + ... ValueError: Mass cannot be less than 0 >>> capture_radii(6.957e8, 1.99e30, c+1) 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: 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) ) - return round(capture_radius) + return round(capture_radius, 0) def capture_area(capture_radius: float) -> float: - - sigma = pi * pow(capture_radius, 2) - return sigma + """ + 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 + + 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() """ From c5ed1ae94f0de3f7e0993f4232b3288470d1f14e Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 28 Jul 2023 20:25:51 +0200 Subject: [PATCH 24/24] Update physics/basic_orbital_capture.py --- physics/basic_orbital_capture.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/physics/basic_orbital_capture.py b/physics/basic_orbital_capture.py index b3655176756a..eeb45e60240c 100644 --- a/physics/basic_orbital_capture.py +++ b/physics/basic_orbital_capture.py @@ -52,18 +52,16 @@ def capture_radii( if target_body_mass < 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") - elif projectile_velocity > c: + if projectile_velocity > c: raise ValueError("Cannot go beyond speed of light") - else: - 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) - ) - return round(capture_radius, 0) + 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) + ) + return round(capture_radius, 0) def capture_area(capture_radius: float) -> float: @@ -89,9 +87,8 @@ def capture_area(capture_radius: float) -> float: 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) + sigma = pi * pow(capture_radius, 2) + return round(sigma, 0) if __name__ == "__main__":