From 3a573847da577e96d0e1aee65521d7b3faca21b8 Mon Sep 17 00:00:00 2001 From: Anson Date: Sun, 15 Aug 2021 23:54:42 -0700 Subject: [PATCH] more work on orbits example --- index.html | 4 +- index.jl | 107 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 76 insertions(+), 35 deletions(-) diff --git a/index.html b/index.html index b105261..f42bbc6 100644 --- a/index.html +++ b/index.html @@ -53,11 +53,11 @@ diff --git a/index.jl b/index.jl index b0c8693..da276e1 100644 --- a/index.jl +++ b/index.jl @@ -378,8 +378,24 @@ md""" # ╔═╡ f6d87354-ac46-4202-92f8-b39a0db13327 μ = 3.986004418e14u"m^3/s^2" # Standard Gravitational Parameter for Earth +# ╔═╡ f8039870-2570-47d0-8d46-30922415ec9d +earth_radius = 6378u"km" + +# ╔═╡ 863cd607-a459-49ae-9049-983f3374f523 +abstract type Orbit end + # ╔═╡ 44daff45-f608-47e3-ad6e-fca43532f322 -struct Elliptic_Orbit +struct Circular_Orbit <: Orbit + """Simple 2d circular orbit""" + r::typeof(.1u"km") # altitude +end + + +# ╔═╡ efb58b79-24e4-45c6-ad45-aeaa339d82fd +ISS = Circular_Orbit(420u"km") + +# ╔═╡ ad3a2b19-5639-4d11-8d89-bc54772d639b +struct Elliptic_Orbit <: Orbit """Simple 2d elliptic orbit""" r::typeof(.1u"km") # altitude a::typeof(.1u"km") # semimajor axis @@ -387,48 +403,70 @@ struct Elliptic_Orbit function Elliptic_Orbit(r, a, e) @assert e < 1 "Eccentricity must be less than 1!" + @assert 0 < e "Eccentricity must be greater than 0!" new(r, a, e) end - function Elliptic_Orbit(r) - new(r,r,0) # we'll pretend circular orbits count for this example + + + function Elliptic_Orbit(perigee, apogee) + a = (perigee + apogee) / 2 + e = 1 - (perigee/a) + r = a*((1-e^2)/(1+e)) # Assume θ is 0 since we aren't keeping track of it + Elliptic_Orbit(r,a,e) end end - -# ╔═╡ efb58b79-24e4-45c6-ad45-aeaa339d82fd -ISS = Elliptic_Orbit(420u"km") +# ╔═╡ b4e08868-d48a-4f66-9d20-f45ea4d83f00 +sat = Elliptic_Orbit(earth_radius+537.0u"km", earth_radius+9040.9u"km") # ╔═╡ 3efd8a29-6a56-4f5c-9cab-0f08875b2064 +function get_velocity(o::Circular_Orbit) + v = sqrt(μ/o.r) + return v |> u"km/s" +end + +# ╔═╡ 59207a25-fa6d-4369-979d-cd9cc2f094cf function get_velocity(o::Elliptic_Orbit) v = sqrt(μ*(2/o.r - 1/o.a)) return v |> u"km/s" end -# ╔═╡ 59207a25-fa6d-4369-979d-cd9cc2f094cf -function get_period(o::Elliptic_Orbit) - T = 2*π*sqrt(o.a^3/μ) - return T |> u"s" -end - -# ╔═╡ 5a4b673b-babb-4e11-a292-d71087fa32bc - - -# ╔═╡ a6c72acc-39fc-4dfc-8126-64c6b35145d1 -get_period(ISS) - -# ╔═╡ d79a6752-77ba-496f-96c3-d9904db0a46b +# ╔═╡ 11fb3a28-edf3-46ff-8c4a-5286793b6e43 get_velocity(ISS) -# ╔═╡ 026321df-6991-4b59-aaba-c467b267a477 -whatsit(u"m") - -# ╔═╡ 3955b9d6-7514-4712-ba22-929afda3c77c -typeof(1.1u"km") - -# ╔═╡ a7bacb81-0f19-4d2d-9588-61e912689001 -Elliptic_Orbit(1,2,.9) +# ╔═╡ 79a9ab94-06a8-4613-8f60-358e08f0f32e +get_velocity(sat) # ╔═╡ c3d943b4-809d-4a96-a99d-be7653ba2c8b +begin +function Plots.plot(orbit::Elliptic_Orbit) + a = orbit.a |> u"km" |> ustrip + b = orbit.a*sqrt(1-orbit.e^2) |> u"km" |> ustrip + t = 0:.01:2π + + x_orbit(t) = a*cos(t) + y_orbit(t) = b*sin(t) + + plot(x_orbit, y_orbit, t) + + x_earth(t) = ustrip(earth_radius)*cos(t) + a*orbit.e + y_earth(t) = ustrip(earth_radius)*sin(t) + plot!(x_earth,y_earth, t, c=:gray,fill=(0,:blue), legend=false,aspect_ratio=:equal) + + title!("Satellite Orbiting Earth") +end +plot(sat) +end + +# ╔═╡ 01ba1742-d26e-4271-ab62-0bd9ce5e291d +function get_ΔV(start::Orbit, final::Orbit) + get_velocity(start) - get_velocity(final) +end + +# ╔═╡ ad4d24a8-f601-4522-a3eb-c01f6fd68aec +get_ΔV(ISS,sat) + +# ╔═╡ 2d0de5db-5558-41e0-96d5-a3317d151aff # ╔═╡ 8924673f-e99c-44b3-be6d-2abf0b2f5e23 @@ -1401,17 +1439,20 @@ version = "0.9.1+5" # ╠═9ea4584c-8177-4f69-9739-b2faa93281a8 # ╠═f43812d2-9f87-489a-9317-e7aa19ffd3bc # ╠═f6d87354-ac46-4202-92f8-b39a0db13327 +# ╠═f8039870-2570-47d0-8d46-30922415ec9d +# ╠═863cd607-a459-49ae-9049-983f3374f523 # ╠═44daff45-f608-47e3-ad6e-fca43532f322 # ╠═efb58b79-24e4-45c6-ad45-aeaa339d82fd +# ╠═ad3a2b19-5639-4d11-8d89-bc54772d639b +# ╠═b4e08868-d48a-4f66-9d20-f45ea4d83f00 # ╠═3efd8a29-6a56-4f5c-9cab-0f08875b2064 # ╠═59207a25-fa6d-4369-979d-cd9cc2f094cf -# ╠═5a4b673b-babb-4e11-a292-d71087fa32bc -# ╠═a6c72acc-39fc-4dfc-8126-64c6b35145d1 -# ╠═d79a6752-77ba-496f-96c3-d9904db0a46b -# ╠═026321df-6991-4b59-aaba-c467b267a477 -# ╠═3955b9d6-7514-4712-ba22-929afda3c77c -# ╠═a7bacb81-0f19-4d2d-9588-61e912689001 +# ╠═11fb3a28-edf3-46ff-8c4a-5286793b6e43 +# ╠═79a9ab94-06a8-4613-8f60-358e08f0f32e # ╠═c3d943b4-809d-4a96-a99d-be7653ba2c8b +# ╠═01ba1742-d26e-4271-ab62-0bd9ce5e291d +# ╠═ad4d24a8-f601-4522-a3eb-c01f6fd68aec +# ╠═2d0de5db-5558-41e0-96d5-a3317d151aff # ╠═8924673f-e99c-44b3-be6d-2abf0b2f5e23 # ╠═3f7ae2df-9d4d-46d3-b12e-22107a560b66 # ╠═fbc06121-d53a-4a64-9497-63d7f3583fbb