-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | A library with the kerbal space program universe and demo code
--
@package KSP
@version 0.1
module System.KSP.Auxiliary
-- | The function takeUntil takes a test function and a list of
-- values. It returns all elements that do not pass the test function
-- until it reaches the first one that passes the test function,
-- otherwise it returns the empty list.
takeUntil :: (a -> Bool) -> [a] -> [a]
-- | firstJust returns of a list of Maybe values the first
-- actual Just value or nothing if none is within the list.
firstJust :: [Maybe a] -> Maybe a
module System.KSP.DataConstructors
-- | An Object is something named.
data Object
Object :: String -> Object
name :: Object -> String
-- | The Celestial type defines a celestial object within this
-- library. Every celestial object has
--
--
-- - r [m] the radius (from the bodys center) in meter
-- - m [kg] the mass of the object in kilo gramms
-- - soi [m] the sphere of influence of the
-- object in meter
-- - system empty or a system of surronding objects.
--
data Celestial
Celestial :: Double -> Double -> Double -> System Body Body -> Celestial
r :: Celestial -> Double
m :: Celestial -> Double
soi :: Celestial -> Double
system :: Celestial -> System Body Body
-- | The Body type is the central data type within the KSP library.
-- It could be either Railed or Movable
--
--
-- - Railed is everything withing ksp that is a star, a planet
-- or a moon. They are static in their orbits and are therefore called
-- railed.
-- - Movable is every other part in ksp, that is physical. Here
-- they include deltaV counter, but are also modelled as celestial
-- objects. Actually in ksp orbits around movable parts arent possible.
-- Anyhow, within this data type such constructs are doable.
--
data Body
Railed :: Object -> Celestial -> Body
object :: Body -> Object
celestial :: Body -> Celestial
Movable :: Object -> Celestial -> DeltaV -> Body
object :: Body -> Object
celestial :: Body -> Celestial
deltaV :: Body -> DeltaV
-- | The 'Orbit a' data type defines an orbit around a central body
-- centerBody.
--
--
-- - centerBody is the body the orbit is around
-- - apoapsis is the height of the heighest point of the
-- orbit
-- - periapsis is the height of the lowest point of the
-- orbit
-- - inclination is the angle that the orbit is inclined against
-- the aquatorial plane
-- - omega_big is the longitude of the ascending node
-- - omega_small is the argument of the periapsis
--
data Orbit a
Landed :: Orbit a
O :: a -> Double -> Double -> Maybe Double -> Maybe Double -> Maybe Double -> Orbit a
centerBody :: Orbit a -> a
apoapsis :: Orbit a -> Double
periapsis :: Orbit a -> Double
inclination :: Orbit a -> Maybe Double
omega_big :: Orbit a -> Maybe Double
omega_small :: Orbit a -> Maybe Double
-- | mkOrbit takes a body as well as apoapsis and periapsis and of
-- that creates an orbit.
mkOrbit :: a -> Height -> Height -> Orbit a
-- | mkCircOrbit is similar to mkOrbit with the difference
-- that it creates a circular orbit.
mkCircOrbit :: a -> Height -> Orbit a
-- | The Height is the height above ground level.
type Height = Double
-- | The System module contains the type definition of a
-- System.
data System b a
Empty :: System b a
System :: [(Orbit b, a)] -> System b a
-- | GravConst is the type of the gravitation constant, which is
-- obious a double.
type GravConst = Double
-- | KSystem creates a data constructor, that binds the
-- System to a System of Orbits around Bodys.
type KSystem = System Body
module System.KSP.OrbitalMechanics
-- | Radius of Orbit at the current Position
type Radius = Double
-- | Speed is an alias for Double
type Speed = Double
-- | var_G [Nm^2/kg^2] is the Gravitation constant in newton meter
-- squared over kilo gramms squared
var_G :: GravConst
-- | semiMajor calculates the semi major axis of an orbit.
semiMajor :: Orbit Body -> Double
-- | v takes an orbit and a radius (from the center of the
-- centerBody) and calculates the orbital speed at that position.
v :: Orbit Body -> Radius -> Speed
-- | v_e calculates the escape velocity of that body.
v_e :: Body -> Speed
-- | burnProgradeFromCircOrb calculates the transformed orbit,
-- after the supplied delta V is applied to the initial orbit.
--
-- A prograde burn is done through a positive Speed parameter, a
-- retrograde burn respective through a negative Speed.
burnFromCircOrb :: Orbit Body -> Speed -> Orbit Body
-- | updateOrbit is a function that takes an orbit and two heights.
-- It updates the apoapsis with the bigger height and the periapsis with
-- the smaller.
updateOrbit :: Orbit Body -> Double -> Double -> Orbit Body
-- | burnAt calculates the new orbit after a burn of Speed
-- delta V is applied to the given orbit.
--
--
-- - f is the function that calculates returns the distance of
-- the body within orbit, to the center body. Typical this is one of
-- apoapsis or periapsis
-- - o is the initial orbit
-- - dV is the amount of delta V to apply to the orbit.
--
burnAt :: (Orbit Body -> Double) -> Orbit Body -> Speed -> Orbit Body
-- | burnAtPeriapsis calculates the new orbit after a burn of
-- Speed delta V is applied to the given orbit at the periapsis.
burnAtPeriapsis :: Orbit Body -> Speed -> Orbit Body
-- | burnAt calculates the new orbit after a burn of Speed
-- delta V is applied to the given orbit at the apoapsis.
burnAtApoapsis :: Orbit Body -> Speed -> Orbit Body
-- | hohmann takes two orbits around the same centerBody. It
-- calculates both (v1 and v2 ) delta V changes for a hohmann transfair.
hohmann :: Orbit Body -> Orbit Body -> (Double, Double)
module System.KSP.DataDestructors
-- | getNextUp takes a KSystem system and a Body. It
-- returns the body that the supplied body orbits. Nothing is
-- returned if the supplied body is not found within the system.
getNextUp :: KSystem Body -> Body -> Maybe Body
-- | getPathUp takes a KSystem system and a Body. It
-- returns the chain of body's that are orbiting each other.
getPathUp :: KSystem Body -> Body -> [Body]
-- | getDivid takes a KSystem system and a from
-- Body and a to Body. For both bodys, the path up
-- is calculated by getPathUp and the position, where they reach
-- the same body is returned (as Position and with the actual body).
getDivid :: KSystem Body -> Body -> Body -> (Int, Body)
-- | sOrbitInSystem takes a body, a KSystem system and maybe
-- returns the orbit of the body.
sOrbitInSystem :: Body -> KSystem Body -> Maybe (Orbit Body)
-- | pathOBetween takes a KSystem system and a from
-- Body and a to Body. If one want's to reach the
-- to body from from body the bodys between and their orbit
-- around their centerBody are returnd.
pathOBetween :: KSystem Body -> Body -> Body -> [(Body, Orbit Body)]
-- | pathOBetween' takes a KSystem system and a from
-- Body and a to Body. If one want's to reach the
-- to body from from body the bodys between and their orbit
-- around their centerBody are returnd. They are returnd as triple, with
-- the overlapping body in the center of the triple and the path of the
-- from body in the first element of the triple. The path of the
-- to body in the last element of the triple.
pathOBetween' :: KSystem Body -> Body -> Body -> ([(Body, Orbit Body)], (Body, Orbit Body), [(Body, Orbit Body)])
-- | pathBetween_ takes a KSystem system and a from
-- Body and a to Body. If one want's to reach the
-- to body from from body the bodys between are returnd,
-- without the common body.
pathBetween_ :: KSystem Body -> Body -> Body -> [Body]
-- | pathBetween takes a KSystem system and from
-- Body and a to Body. If one want's to reach the
-- to body from from body the bodys between and their orbit
-- around their centerBody are returnd. They are returnd as triple, with
-- the overlapping body in the center of the triple and the path of the
-- from body in the first element of the triple. The path of the
-- to body in the last element of the triple.
pathBetween' :: KSystem Body -> Body -> Body -> ([Body], Body, [Body])
-- | pathBetween takes a KSystem system and a from
-- Body and a to Body. If one want's to reach the
-- to body from from body the bodys between are returnd,
-- including the common body.
pathBetween :: KSystem Body -> Body -> Body -> [Body]
-- | pathSpeeds takes the result of pathOBetween and
-- calculates the corresponding orbital speeds.
pathSpeeds :: [(Body, Orbit Body)] -> [Speed]
-- | orbitalSpeed returns the orbital velocity of the given orbit.
orbitalSpeed :: (Orbit Body) -> Speed
-- | updateOrbit is a function that takes an orbit and two heights.
-- It updates the apoapsis with the bigger height and the periapsis with
-- the smaller.
updateOrbit :: Orbit Body -> Double -> Double -> Orbit Body
-- | burnProgradeFromCircOrb calculates the transformed orbit,
-- after the supplied delta V is applied to the initial orbit.
--
-- A prograde burn is done through a positive Speed parameter, a
-- retrograde burn respective through a negative Speed.
burnFromCircOrb :: Orbit Body -> Speed -> Orbit Body
-- | burnAt calculates the new orbit after a burn of Speed
-- delta V is applied to the given orbit.
--
--
-- - f is the function that calculates returns the distance of
-- the body within orbit, to the center body. Typical this is one of
-- apoapsis or periapsis
-- - o is the initial orbit
-- - dV is the amount of delta V to apply to the orbit.
--
burnAt :: (Orbit Body -> Double) -> Orbit Body -> Speed -> Orbit Body
-- | burnAt calculates the new orbit after a burn of Speed
-- delta V is applied to the given orbit at the apoapsis.
burnAtApoapsis :: Orbit Body -> Speed -> Orbit Body
-- | burnAtPeriapsis calculates the new orbit after a burn of
-- Speed delta V is applied to the given orbit at the periapsis.
burnAtPeriapsis :: Orbit Body -> Speed -> Orbit Body
module System.KSP.Datatypes
-- | An Object is something named.
data Object
Object :: String -> Object
name :: Object -> String
-- | The Celestial type defines a celestial object within this
-- library. Every celestial object has
--
--
-- - r [m] the radius (from the bodys center) in meter
-- - m [kg] the mass of the object in kilo gramms
-- - soi [m] the sphere of influence of the
-- object in meter
-- - system empty or a system of surronding objects.
--
data Celestial
Celestial :: Double -> Double -> Double -> System Body Body -> Celestial
r :: Celestial -> Double
m :: Celestial -> Double
soi :: Celestial -> Double
system :: Celestial -> System Body Body
-- | The Body type is the central data type within the KSP library.
-- It could be either Railed or Movable
--
--
-- - Railed is everything withing ksp that is a star, a planet
-- or a moon. They are static in their orbits and are therefore called
-- railed.
-- - Movable is every other part in ksp, that is physical. Here
-- they include deltaV counter, but are also modelled as celestial
-- objects. Actually in ksp orbits around movable parts arent possible.
-- Anyhow, within this data type such constructs are doable.
--
data Body
Railed :: Object -> Celestial -> Body
object :: Body -> Object
celestial :: Body -> Celestial
Movable :: Object -> Celestial -> DeltaV -> Body
object :: Body -> Object
celestial :: Body -> Celestial
deltaV :: Body -> DeltaV
-- | The 'Orbit a' data type defines an orbit around a central body
-- centerBody.
--
--
-- - centerBody is the body the orbit is around
-- - apoapsis is the height of the heighest point of the
-- orbit
-- - periapsis is the height of the lowest point of the
-- orbit
-- - inclination is the angle that the orbit is inclined against
-- the aquatorial plane
-- - omega_big is the longitude of the ascending node
-- - omega_small is the argument of the periapsis
--
data Orbit a
Landed :: Orbit a
O :: a -> Double -> Double -> Maybe Double -> Maybe Double -> Maybe Double -> Orbit a
centerBody :: Orbit a -> a
apoapsis :: Orbit a -> Double
periapsis :: Orbit a -> Double
inclination :: Orbit a -> Maybe Double
omega_big :: Orbit a -> Maybe Double
omega_small :: Orbit a -> Maybe Double
-- | mkOrbit takes a body as well as apoapsis and periapsis and of
-- that creates an orbit.
mkOrbit :: a -> Height -> Height -> Orbit a
-- | mkCircOrbit is similar to mkOrbit with the difference
-- that it creates a circular orbit.
mkCircOrbit :: a -> Height -> Orbit a
-- | The Height is the height above ground level.
type Height = Double
-- | The System module contains the type definition of a
-- System.
data System b a
Empty :: System b a
System :: [(Orbit b, a)] -> System b a
-- | GravConst is the type of the gravitation constant, which is
-- obious a double.
type GravConst = Double
-- | KSystem creates a data constructor, that binds the
-- System to a System of Orbits around Bodys.
type KSystem = System Body
-- | getNextUp takes a KSystem system and a Body. It
-- returns the body that the supplied body orbits. Nothing is
-- returned if the supplied body is not found within the system.
getNextUp :: KSystem Body -> Body -> Maybe Body
-- | getPathUp takes a KSystem system and a Body. It
-- returns the chain of body's that are orbiting each other.
getPathUp :: KSystem Body -> Body -> [Body]
-- | getDivid takes a KSystem system and a from
-- Body and a to Body. For both bodys, the path up
-- is calculated by getPathUp and the position, where they reach
-- the same body is returned (as Position and with the actual body).
getDivid :: KSystem Body -> Body -> Body -> (Int, Body)
-- | sOrbitInSystem takes a body, a KSystem system and maybe
-- returns the orbit of the body.
sOrbitInSystem :: Body -> KSystem Body -> Maybe (Orbit Body)
-- | pathOBetween takes a KSystem system and a from
-- Body and a to Body. If one want's to reach the
-- to body from from body the bodys between and their orbit
-- around their centerBody are returnd.
pathOBetween :: KSystem Body -> Body -> Body -> [(Body, Orbit Body)]
-- | pathOBetween' takes a KSystem system and a from
-- Body and a to Body. If one want's to reach the
-- to body from from body the bodys between and their orbit
-- around their centerBody are returnd. They are returnd as triple, with
-- the overlapping body in the center of the triple and the path of the
-- from body in the first element of the triple. The path of the
-- to body in the last element of the triple.
pathOBetween' :: KSystem Body -> Body -> Body -> ([(Body, Orbit Body)], (Body, Orbit Body), [(Body, Orbit Body)])
-- | pathBetween_ takes a KSystem system and a from
-- Body and a to Body. If one want's to reach the
-- to body from from body the bodys between are returnd,
-- without the common body.
pathBetween_ :: KSystem Body -> Body -> Body -> [Body]
-- | pathBetween takes a KSystem system and from
-- Body and a to Body. If one want's to reach the
-- to body from from body the bodys between and their orbit
-- around their centerBody are returnd. They are returnd as triple, with
-- the overlapping body in the center of the triple and the path of the
-- from body in the first element of the triple. The path of the
-- to body in the last element of the triple.
pathBetween' :: KSystem Body -> Body -> Body -> ([Body], Body, [Body])
-- | pathSpeeds takes the result of pathOBetween and
-- calculates the corresponding orbital speeds.
pathSpeeds :: [(Body, Orbit Body)] -> [Speed]
-- | orbitalSpeed returns the orbital velocity of the given orbit.
orbitalSpeed :: (Orbit Body) -> Speed
module System.KSP.Universe
-- | kMoho is the definition of Moho
kMoho :: Body
-- | kGilly is the definition of Gilly
kGilly :: Body
-- | kEve is the definition of Eve
kEve :: Body
-- | kMun is the definition of Mun
kMun :: Body
-- | kMinmus is the definition of Minmus
kMinmus :: Body
-- | kKerbin is the definition of Kerbin
kKerbin :: Body
-- | kIke is the definition of Ike
kIke :: Body
-- | kDres is the definition of Dres
kDres :: Body
-- | kDuna is the definition of Duna
kDuna :: Body
-- | kLaythe is the definition of Laythe
kLaythe :: Body
-- | kVall is the definition of Vall
kVall :: Body
-- | kTylo is the definition of Tylo
kTylo :: Body
-- | kBop is the definition of Bop
kBop :: Body
-- | kPol is the definition of Pol
kPol :: Body
-- | kJool is the definition of Jool
kJool :: Body
-- | kEeloo is the definition of Eeloo
kEeloo :: Body
-- | kKerbol is the definition of Kerbol
kKerbol :: Body
-- | kGillyOrbit is the definition of the Orbit of Gilly
kGillyOrbit :: Orbit Body
-- | kMunOrbit is the definition of the Orbit of Mun
kMunOrbit :: Orbit Body
-- | kMinmusOrbit is the definition of the Orbit of Minmus
kMinmusOrbit :: Orbit Body
-- | kIkeOrbit is the definition of the Orbit of Ike
kIkeOrbit :: Orbit Body
-- | kLaytheOrbit is the definition of the Orbit of Laythe
kLaytheOrbit :: Orbit Body
-- | kVallOrbit is the definition of the Orbit of Vall
kVallOrbit :: Orbit Body
-- | kTyloOrbit is the definition of the Orbit of Tylo
kTyloOrbit :: Orbit Body
-- | kBopOrbit is the definition of the Orbit of Bop
kBopOrbit :: Orbit Body
-- | kPolOrbit is the definition of the Orbit of Pol
kPolOrbit :: Orbit Body
-- | kMohoOrbit is the definition of the Orbit of Moho
kMohoOrbit :: Orbit Body
-- | kEveOrbit is the definition of the Orbit of Eve
kEveOrbit :: Orbit Body
-- | kKerbinOrbit is the definition of the Orbit of Kerbin
kKerbinOrbit :: Orbit Body
-- | kDunaOrbit is the definition of the Orbit of Duna
kDunaOrbit :: Orbit Body
-- | kDresOrbit is the definition of the Orbit of Dres
kDresOrbit :: Orbit Body
-- | kJoolOrbit is the definition of the Orbit of Jool
kJoolOrbit :: Orbit Body
-- | kEelooOrbit is the definition of the Orbit of Eeloo
kEelooOrbit :: Orbit Body
-- | Simple Calculation
--
-- The folowing should show some basic calculations that can be done with
-- this library.
--
-- Orbital Velocity
--
-- The orbital velocity of something in an 80k orbit around kerbin could
-- be calculated by:
--
--
-- >>> v_orbKerbin 80e3
-- 2278.9316462467027
--
--
-- The corresponding velocity of a 100k orbit is calculated via:
--
--
-- >>> v_orbKerbin 100e3
-- 2246.1395532335027
--
--
-- Paths
--
-- Paths are always calculated within an existing system. Typically is
-- such a system the one around kerbol.
--
--
-- >>> let ksp_system = (system . celestial $ kKerbol) :: KSystem Body
--
-- >>> :t ksp_system
-- ksp_system :: KSystem Body
--
--
-- An easy path is the one between mun and minmus, via kerbin. This one
-- is calculated via:
--
--
-- >>> pathBetween ksp_system kMun kMinmus
-- [R/Mun,R/Kerbin,R/Minmus]
--
--
-- A much wieder path would be the one between kerbins moon minmus and
-- jools moon tylo. The path could be calculated via:
--
--
-- >>> pathBetween ksp_system kMinmus kTylo
-- [R/Minmus,R/Kerbin,R/Kerbol,R/Jool,R/Tylo]
--
--
-- Paths with Orbits
--
-- The function pathOBetween calculates not only the path between
-- two given bodys. It also calculates the orbit, of each body. For the
-- path between mun and minmus, the orbits of mun and minmus (each around
-- kerbin) are also returned.
--
--
-- >>> pathOBetween ksp_system kMun kMinmus
-- [(R/Mun,Around R/Kerbin (1.14e7|1.14e7)),(R/Minmus,Around R/Kerbin
-- (4.64e7|4.64e7))]
--
--
-- Path speeds
--
-- To calculate the differences in deltaV between different orbits, do
-- the following. First calculate the pathOBetween, then take that
-- result and feed it into pathSpeeds to get the orbital speeds
-- along the path.
--
--
-- >>> let pathMunMinmus = pathOBetween ksp_system kMun kMinmus
--
-- >>> pathSpeeds pathMunMinmus
-- [542.4942415070719,274.11754059162286]
--
--
-- The orbital velocity of the Mun is 542.5 m/s, the one around Minmus is
-- 274.1 m/s.
--
-- Hohmann Transfair
--
-- To do a hohmann transfair of a low kerbin orbit (100km) to the orbit
-- of Mun (47Mm) the following burns must be done.
--
--
-- >>> let o1 = mkCircOrbit kKerbin 100e3
--
-- >>> let o2 = mkCircOrbit kKerbin 47000e3
--
-- >>> hohmann o1 o2
-- (907.2791882798308,226.01062520890378)
--
--
-- Lets save these two speeds:
--
--
-- >>> let (v1, v2) = hohmann o1 o2
--
--
-- To calculate the transfair orbit from orbit o1 to orbit o2, the speed
-- v1 has to be applied within the orbit o1.
--
--
-- >>> burnFromCircOrb o1 v1
-- Around R/Kerbin (4.7000000000000596e7|100000.0)
--
--
-- Again save that orbit into o12
--
--
-- >>> let o12 = burnFromCircOrb o1 v1
--
--
-- And apply the speed v2 to the transfair orbit o12:
--
--
-- >>> burnAtApoapsis o12 v2
-- Around R/Kerbin (4.700000000000125e7|4.7000000000000596e7)
--
--
-- Which is the desired, circular orbit, with the height of round 47Mm.
module System.KSP.KSP
-- | To calculate the orbital velocity of a circular orbit around kerbin,
-- v_orbKerbin uses v_orb with kKerbin as default
-- parameter.
v_orbKerbin :: Height -> Speed
-- | v_orb calculates the velocity within an orbit around
-- Body b, Height h meters above the ground.
v_orb :: Height -> Body -> Speed