Currently working on refactor, much work to do

This commit is contained in:
Connor
2021-09-25 16:10:02 -06:00
parent 7d0037f38d
commit af545ba1a7
23 changed files with 286 additions and 353 deletions

View File

@@ -1,4 +1,4 @@
export oe_to_rθh, rθh_to_xyz, oe_to_xyz, xyz_to_oe, conv_T
export oe_to_rθh, rθh_to_xyz, oe_to_xyz, xyz_to_oe, conv_T, spiral, gen_orbit
function oe_to_rθh(oe::Vector,μ::Real) :: Vector
@@ -69,6 +69,30 @@ function xyz_to_oe(cart_vec::Vector,μ::Real)
end
"""
A convenience function for generating start conditions from orbital elements
Inputs: a body, a period, and a mass
Output: a random reasonable orbit
"""
function gen_orbit(T::Float64, mass::Float64, primary::Body=Sun)
μ = primary.μ
i = rand(0.0:0.01:0.4999π)
θ = rand(0.0:0.01:2π)
i = 0
while true
i += 1
e = rand(0.0:0.01:0.5)
a = (μ * ( T/2π )^2 )
a*(1-e) < 1.1primary.r || return [ oe_to_xyz([ a, e, i, 0., 0., θ ], μ); mass ]
i < 100 || throw(GenOrbit_Error)
end
end
"""
A convenience function for generating spiral trajectories
"""
spiral(mag,n,init,sc,time,primary=Sun) = conv_T(fill(mag, n), zeros(n), zeros(n), init, sc, time, primary)
"""
Converts a series of thrust vectors from R,Θ,H frame to cartesian
"""
@@ -78,7 +102,7 @@ function conv_T(Tm::Vector{Float64},
init_state::Vector{Float64},
craft::Sc,
time::Float64,
μ::Float64)
primary::Body=Sun)
Txs = Float64[]
Tys = Float64[]
@@ -100,7 +124,7 @@ function conv_T(Tm::Vector{Float64},
for i in 1:n
mag, α, β = Tm[i], Ta[i], Tb[i]
thrust_rθh = mag * [cos(β)*sin(α), cos(β)*cos(α), sin(β)]
_,_,i,Ω,ω,ν = xyz_to_oe(state, μ)
_,_,i,Ω,ω,ν = xyz_to_oe(state, primary.μ)
θ = ω+ν
,,ci,si,, = cos(Ω),sin(Ω),cos(i),sin(i),cos(θ),sin(θ)
DCM = [*-*ci* -*-*ci* *si;
@@ -108,10 +132,10 @@ function conv_T(Tm::Vector{Float64},
si* si* ci ]
Tx, Ty, Tz = DCM*thrust_rθh
state = prop_one([Tx, Ty, Tz], state, copy(craft), μ, time/n)
state = prop_one([Tx, Ty, Tz], state, craft, time/n, primary)
push!(Txs, Tx)
push!(Tys, Ty)
push!(Tzs, Tz)
end
return Txs, Tys, Tzs
return hcat(Txs, Tys, Tzs)
end