From 5dd72d28b99d7fff6649c4f7d1f45d2adee49759 Mon Sep 17 00:00:00 2001 From: Anson Date: Sat, 14 Aug 2021 23:28:20 -0700 Subject: [PATCH] tried swapping quaternions example with orbits --- index.jl | 110 ++++++++++++++++++++++++++----------------------------- 1 file changed, 51 insertions(+), 59 deletions(-) diff --git a/index.jl b/index.jl index 8fdb45c..b0c8693 100644 --- a/index.jl +++ b/index.jl @@ -375,71 +375,61 @@ md""" ### Custom Data Types """ +# ╔═╡ f6d87354-ac46-4202-92f8-b39a0db13327 +μ = 3.986004418e14u"m^3/s^2" # Standard Gravitational Parameter for Earth + # ╔═╡ 44daff45-f608-47e3-ad6e-fca43532f322 -struct Quaternion - i::Float64 - j::Float64 - k::Float64 - r::Float64 +struct Elliptic_Orbit + """Simple 2d elliptic orbit""" + r::typeof(.1u"km") # altitude + a::typeof(.1u"km") # semimajor axis + e::Float64 # eccentricity - Quaternion(i, j, k, r) = norm([i, j, k, r]) ≈ 1 ? new(i, j, k, r) : error("Magnitude not equal to 1.") - Quaternion() = new(0, 0, 0, 1) - - Quaternion(yaw, pitch, roll) = Quaternion([0 0 sin(yaw / 2) cos(yaw / 2)]) * Quaternion([0 sin(pitch / 2) 0 cos(pitch / 2)]) * Quaternion([sin(roll / 2) 0 0 cos(roll / 2)]) - - function Quaternion(ē, ϕ) - if sum(ē) == 0 - return Quaternion([0 0 0 cos(ϕ / 2)]) - end - dir = normalize(ē) * sin(ϕ / 2) - return Quaternion(dir[1], dir[2], dir[3], cos(ϕ / 2)) + function Elliptic_Orbit(r, a, e) + @assert e < 1 "Eccentricity must be less than 1!" + new(r, a, e) + end + function Elliptic_Orbit(r) + new(r,r,0) # we'll pretend circular orbits count for this example end - end -# ╔═╡ 639fc5f0-1ab8-4d4e-83b5-77a82ae9bdf8 -q() = Quaternion() +# ╔═╡ efb58b79-24e4-45c6-ad45-aeaa339d82fd +ISS = Elliptic_Orbit(420u"km") -# ╔═╡ 37c4a8ef-d503-497a-a63c-3e43d0ebb2a7 -function QuaternionMultiplication(l::Quaternion, r::Quaternion) - R = [r.r r.k r.j r.i; - -r.k r.r r.i r.j; - r.j -r.i r.r r.k; - -r.i -r.j -r.k r.r] - L = [l.i; l.j; l.k; l.r] - return Quaternion(R * L) - +# ╔═╡ 3efd8a29-6a56-4f5c-9cab-0f08875b2064 +function get_velocity(o::Elliptic_Orbit) + v = sqrt(μ*(2/o.r - 1/o.a)) + return v |> u"km/s" end -# ╔═╡ 0d67e350-a87e-4a07-a01c-d348f3e62599 -Base.:*(l::Quaternion, r::Quaternion) = QuaternionMultiplication(l::Quaternion, r::Quaternion) - -# ╔═╡ cbf7d0fb-855b-442b-80c2-cfb6dcabe104 -begin - Base.iterate(q::Quaternion, state=1) = state > 4 ? nothing : (collect(q)[state], state + 1) - Base.length(q::Quaternion) = 4 - Base.collect(q::Quaternion) = [q.i q.j q.k q.r] - Base.getindex(q::Quaternion, i) = collect(q)[i] +# ╔═╡ 59207a25-fa6d-4369-979d-cd9cc2f094cf +function get_period(o::Elliptic_Orbit) + T = 2*π*sqrt(o.a^3/μ) + return T |> u"s" end -# ╔═╡ 84e6fb12-be8c-4e00-bf9c-d45748347def -begin - LinearAlgebra.norm(q::Quaternion) = norm(collect(q)) - LinearAlgebra.normalize(q::Quaternion) = collect(q) / norm(q) -end +# ╔═╡ 5a4b673b-babb-4e11-a292-d71087fa32bc -# ╔═╡ 2ba455ff-70f5-47d5-9fe8-bf4ebee9386a -q1 = Quaternion(1,0,0,0) -# ╔═╡ 6895bcb2-9a11-4f0a-b1c2-6640f6fb509c -q2 = Quaternion([1 2 3], π) +# ╔═╡ a6c72acc-39fc-4dfc-8126-64c6b35145d1 +get_period(ISS) -# ╔═╡ 045a1898-a3db-4e65-9711-9e4608ce09c6 -q()*q() +# ╔═╡ d79a6752-77ba-496f-96c3-d9904db0a46b +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) + +# ╔═╡ c3d943b4-809d-4a96-a99d-be7653ba2c8b -# ╔═╡ fafa0a8d-5ae5-49e9-8d11-4abb5748431e -q1*q2 # ╔═╡ 8924673f-e99c-44b3-be6d-2abf0b2f5e23 md""" @@ -1410,16 +1400,18 @@ version = "0.9.1+5" # ╟─dc898d32-b30b-4baa-a595-b83ccd1dc86d # ╠═9ea4584c-8177-4f69-9739-b2faa93281a8 # ╠═f43812d2-9f87-489a-9317-e7aa19ffd3bc +# ╠═f6d87354-ac46-4202-92f8-b39a0db13327 # ╠═44daff45-f608-47e3-ad6e-fca43532f322 -# ╠═639fc5f0-1ab8-4d4e-83b5-77a82ae9bdf8 -# ╠═37c4a8ef-d503-497a-a63c-3e43d0ebb2a7 -# ╠═0d67e350-a87e-4a07-a01c-d348f3e62599 -# ╠═cbf7d0fb-855b-442b-80c2-cfb6dcabe104 -# ╠═84e6fb12-be8c-4e00-bf9c-d45748347def -# ╠═2ba455ff-70f5-47d5-9fe8-bf4ebee9386a -# ╠═6895bcb2-9a11-4f0a-b1c2-6640f6fb509c -# ╠═045a1898-a3db-4e65-9711-9e4608ce09c6 -# ╠═fafa0a8d-5ae5-49e9-8d11-4abb5748431e +# ╠═efb58b79-24e4-45c6-ad45-aeaa339d82fd +# ╠═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 +# ╠═c3d943b4-809d-4a96-a99d-be7653ba2c8b # ╠═8924673f-e99c-44b3-be6d-2abf0b2f5e23 # ╠═3f7ae2df-9d4d-46d3-b12e-22107a560b66 # ╠═fbc06121-d53a-4a64-9497-63d7f3583fbb