Currently working on refactor, much work to do
This commit is contained in:
@@ -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.μ)
|
||||
θ = ω+ν
|
||||
cΩ,sΩ,ci,si,cθ,sθ = cos(Ω),sin(Ω),cos(i),sin(i),cos(θ),sin(θ)
|
||||
DCM = [cΩ*cθ-sΩ*ci*sθ -cΩ*sθ-sΩ*ci*cθ sΩ*si;
|
||||
@@ -108,10 +132,10 @@ function conv_T(Tm::Vector{Float64},
|
||||
si*sθ si*cθ 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
|
||||
|
||||
Reference in New Issue
Block a user