mirror of
https://gitlab.com/MisterBiggs/julia-for-matlabbers.git
synced 2025-06-16 15:17:17 +00:00
tried swapping quaternions example with orbits
This commit is contained in:
parent
1ca7738cc3
commit
5dd72d28b9
110
index.jl
110
index.jl
@ -375,71 +375,61 @@ md"""
|
|||||||
### Custom Data Types
|
### Custom Data Types
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# ╔═╡ f6d87354-ac46-4202-92f8-b39a0db13327
|
||||||
|
μ = 3.986004418e14u"m^3/s^2" # Standard Gravitational Parameter for Earth
|
||||||
|
|
||||||
# ╔═╡ 44daff45-f608-47e3-ad6e-fca43532f322
|
# ╔═╡ 44daff45-f608-47e3-ad6e-fca43532f322
|
||||||
struct Quaternion
|
struct Elliptic_Orbit
|
||||||
i::Float64
|
"""Simple 2d elliptic orbit"""
|
||||||
j::Float64
|
r::typeof(.1u"km") # altitude
|
||||||
k::Float64
|
a::typeof(.1u"km") # semimajor axis
|
||||||
r::Float64
|
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.")
|
function Elliptic_Orbit(r, a, e)
|
||||||
Quaternion() = new(0, 0, 0, 1)
|
@assert e < 1 "Eccentricity must be less than 1!"
|
||||||
|
new(r, a, e)
|
||||||
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)])
|
end
|
||||||
|
function Elliptic_Orbit(r)
|
||||||
function Quaternion(ē, ϕ)
|
new(r,r,0) # we'll pretend circular orbits count for this example
|
||||||
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))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# ╔═╡ 639fc5f0-1ab8-4d4e-83b5-77a82ae9bdf8
|
# ╔═╡ efb58b79-24e4-45c6-ad45-aeaa339d82fd
|
||||||
q() = Quaternion()
|
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
|
end
|
||||||
|
|
||||||
# ╔═╡ 0d67e350-a87e-4a07-a01c-d348f3e62599
|
# ╔═╡ 59207a25-fa6d-4369-979d-cd9cc2f094cf
|
||||||
Base.:*(l::Quaternion, r::Quaternion) = QuaternionMultiplication(l::Quaternion, r::Quaternion)
|
function get_period(o::Elliptic_Orbit)
|
||||||
|
T = 2*π*sqrt(o.a^3/μ)
|
||||||
# ╔═╡ cbf7d0fb-855b-442b-80c2-cfb6dcabe104
|
return T |> u"s"
|
||||||
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]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# ╔═╡ 84e6fb12-be8c-4e00-bf9c-d45748347def
|
# ╔═╡ 5a4b673b-babb-4e11-a292-d71087fa32bc
|
||||||
begin
|
|
||||||
LinearAlgebra.norm(q::Quaternion) = norm(collect(q))
|
|
||||||
LinearAlgebra.normalize(q::Quaternion) = collect(q) / norm(q)
|
|
||||||
end
|
|
||||||
|
|
||||||
# ╔═╡ 2ba455ff-70f5-47d5-9fe8-bf4ebee9386a
|
|
||||||
q1 = Quaternion(1,0,0,0)
|
|
||||||
|
|
||||||
# ╔═╡ 6895bcb2-9a11-4f0a-b1c2-6640f6fb509c
|
# ╔═╡ a6c72acc-39fc-4dfc-8126-64c6b35145d1
|
||||||
q2 = Quaternion([1 2 3], π)
|
get_period(ISS)
|
||||||
|
|
||||||
# ╔═╡ 045a1898-a3db-4e65-9711-9e4608ce09c6
|
# ╔═╡ d79a6752-77ba-496f-96c3-d9904db0a46b
|
||||||
q()*q()
|
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
|
# ╔═╡ 8924673f-e99c-44b3-be6d-2abf0b2f5e23
|
||||||
md"""
|
md"""
|
||||||
@ -1410,16 +1400,18 @@ version = "0.9.1+5"
|
|||||||
# ╟─dc898d32-b30b-4baa-a595-b83ccd1dc86d
|
# ╟─dc898d32-b30b-4baa-a595-b83ccd1dc86d
|
||||||
# ╠═9ea4584c-8177-4f69-9739-b2faa93281a8
|
# ╠═9ea4584c-8177-4f69-9739-b2faa93281a8
|
||||||
# ╠═f43812d2-9f87-489a-9317-e7aa19ffd3bc
|
# ╠═f43812d2-9f87-489a-9317-e7aa19ffd3bc
|
||||||
|
# ╠═f6d87354-ac46-4202-92f8-b39a0db13327
|
||||||
# ╠═44daff45-f608-47e3-ad6e-fca43532f322
|
# ╠═44daff45-f608-47e3-ad6e-fca43532f322
|
||||||
# ╠═639fc5f0-1ab8-4d4e-83b5-77a82ae9bdf8
|
# ╠═efb58b79-24e4-45c6-ad45-aeaa339d82fd
|
||||||
# ╠═37c4a8ef-d503-497a-a63c-3e43d0ebb2a7
|
# ╠═3efd8a29-6a56-4f5c-9cab-0f08875b2064
|
||||||
# ╠═0d67e350-a87e-4a07-a01c-d348f3e62599
|
# ╠═59207a25-fa6d-4369-979d-cd9cc2f094cf
|
||||||
# ╠═cbf7d0fb-855b-442b-80c2-cfb6dcabe104
|
# ╠═5a4b673b-babb-4e11-a292-d71087fa32bc
|
||||||
# ╠═84e6fb12-be8c-4e00-bf9c-d45748347def
|
# ╠═a6c72acc-39fc-4dfc-8126-64c6b35145d1
|
||||||
# ╠═2ba455ff-70f5-47d5-9fe8-bf4ebee9386a
|
# ╠═d79a6752-77ba-496f-96c3-d9904db0a46b
|
||||||
# ╠═6895bcb2-9a11-4f0a-b1c2-6640f6fb509c
|
# ╠═026321df-6991-4b59-aaba-c467b267a477
|
||||||
# ╠═045a1898-a3db-4e65-9711-9e4608ce09c6
|
# ╠═3955b9d6-7514-4712-ba22-929afda3c77c
|
||||||
# ╠═fafa0a8d-5ae5-49e9-8d11-4abb5748431e
|
# ╠═a7bacb81-0f19-4d2d-9588-61e912689001
|
||||||
|
# ╠═c3d943b4-809d-4a96-a99d-be7653ba2c8b
|
||||||
# ╠═8924673f-e99c-44b3-be6d-2abf0b2f5e23
|
# ╠═8924673f-e99c-44b3-be6d-2abf0b2f5e23
|
||||||
# ╠═3f7ae2df-9d4d-46d3-b12e-22107a560b66
|
# ╠═3f7ae2df-9d4d-46d3-b12e-22107a560b66
|
||||||
# ╠═fbc06121-d53a-4a64-9497-63d7f3583fbb
|
# ╠═fbc06121-d53a-4a64-9497-63d7f3583fbb
|
||||||
|
Loading…
x
Reference in New Issue
Block a user