Files
thesis/julia/plotting.jl
2021-08-25 10:10:22 -06:00

63 lines
2.1 KiB
Julia

# ------------------------------------------------------------------------------
# PLOTTING FUNCTIONS
using Random, PlotlyJS, Base.Iterators
function random_color()
num1 = rand(0:255)
num2 = rand(0:255)
num3 = rand(0:255)
return "#"*string(num1, base=16, pad=2)*string(num2, base=16, pad=2)*string(num3, base=16, pad=2)
end
function get_true_max(mat::Vector{Array{Float64,2}})
return maximum(abs.(flatten(mat)))
end
function plot_orbits(paths::Vector{Array{Float64,2}};
primary::String="Earth",
plot_theme::Symbol=:juno,
labels::Vector{String}=Vector{String}(),
title::String="Spacecraft Position",
colors::Vector{String}=Vector{String}())
N = 32
θ = collect(range(0,length=N,stop=2π))
ϕ = collect(range(0,length=N,stop=π))
x = cos.(θ) * sin.(ϕ)'
y = sin.(θ) * sin.(ϕ)'
z = repeat(cos.(ϕ)',outer=[N, 1])
ps = rs[primary] .* (x,y,z)
x_p,y_p,z_p = ps
t1 = []
for i = 1:length(paths)
path = [ x for x in paths[i] ]
label = labels != [] ? labels[i] : "orbit"
color = colors != [] ? colors[i] : random_color()
push!(t1, scatter3d(;x=(path[:,1]),y=(path[:,2]),z=(path[:,3]),
mode="lines", name=label, line_color=color, line_width=3))
end
limit = max(maximum(abs.(flatten(paths))),maximum(abs.(flatten(ps)))) * 1.1
t2 = surface(;x=(x_p),
y=(y_p),
z=(z_p),
showscale=false,
colorscale = p_colors[primary])
layout = Layout(;title="Orbit Plot",
width=1000,
height=600,
paper_bgcolor="#222529",
scene = attr(xaxis = attr(autorange = false,range=[-limit,limit]),
yaxis = attr(autorange = false,range=[-limit,limit]),
zaxis = attr(autorange = false,range=[-limit,limit]),
aspectratio=attr(x=1,y=1,z=1),
aspectmode="manual"))
p = Plot([t1...,t2],layout)
plot(p)
end