# paploo/kerbaldyn

A library for Kerbal Space Program (KSP) calculation and simulation tools.
Ruby Lua
Latest commit 434e819 Mar 11, 2013 Planetoids: Added pol and eehoo with info from wiki (which I don't al…
`…ways trust).`
 Failed to load latest commit information. bin lib Mar 11, 2013 spec Oct 10, 2012 util .gitignore .rspec Aug 24, 2012 Gemfile Sep 19, 2012 LICENSE.txt Aug 24, 2012 README.rdoc Rakefile Sep 25, 2012 kerbaldyn.gemspec Nov 8, 2012

# Overview

A library for Kerbal Space Program (KSP) calculation and simulation tools.

All units are mks (meters-kilograms-seconds) and all angles are radians.

# Major Classes

Planetoid
• Encapsulates parameters relating to suns, planets, and moons, such as Kerbal and Mun.

Orbit
• Encapsulates parameters relating to orbits about a body.

OrbitalManeuver
• Encapsulates parameters for orbit changes.

Part
• Parses part information into something meaningful.

Part Library
• Allows organization of collections of parts.

# Examples

Calculate the speed and period of an orbit 5000 m above Mun:

```mun = KerbalDyn::Planetoid.mun
orbit.periapsis_velocity
orbit.period```

This should produce a speed of 563.7 m/s and a period of 2285 seconds (38.1 minutes)

To get information about a Hohmann transfer from the above 5000 m orbit to a 25000 m orbit, you could take the following additional steps:

```destination_orbit = KerbalDyn::Orbit.new(mun, :radius => (mun.radius + 25000))
transfer = KerbalDyn::OrbitalManeuver::Hohmann.new(orbit, destination_orbit)
transfer.delta_t
transfer.velocities
transfer.delta_v```

This instructs us that a prograde burn from the starting speed of 563.7 m/s to 576.65 m/s will put us on an intercept orbit whose apoapsis is at 25000 m; furthermore, 1227 seconds later (20.5 minutes) we will reach apoapsis and should do another burn from the apoapsis velocity of 525.4 m/s up to 538 m/s to circularize the orbit.

In the above calculation, if there was a Command Module in a circular orbit at 25000 m, and we were in a LEM at 5000 m, we can calculate the phase angle that the Command Module should be ahead of us when we do our first burn as:

`transfer.mean_lead_angle`

which gives 0.2071 radians, or 11.87 degrees.

# Author

Jeff Reinecke jeff@paploo.net

# TODO

Library:

• Refactor planetoid and orbit tests to use a JSON data file from a game dump.

• Add Elephant Cache to Orbital Manuever methods so that we do not rebuild and recalculate everything all the time.

• Finish Part and Part Library.

Binary Utilities:

• Build a tool for calculating lead angles: kerbaldyn leadangle kerbin@100a mun

• Build a tool for outputting body information in standard units: kerbaldyn info minmus

• Build a tool for calculating the delta-v of hohmann vs various bielliptic transfers: kerbaldyn transfer kerbin@900r minmus

• Build a tool for listing parts of a type with important specs, sorted in useful ways: kerbaldyn partlist –type liquidfuelengine –sort isp

Web:

• Make the CLI bin tools accessible via a Sinatra based mobile interface so that you can hit a local server from your phone.

Notes:

• Remember that bielliptic transfer high altitudes are theoretically limited by the SOI.

• Can specify orbits by planet@400a or planet@400r for 400km alt or 400km radius respectively.

# Version History

0.8.1 - 2012-Nov-07

0.8.0 - 2012-Nov-07

• (FEATURE) Part and PartLibrary completed just in time to realise it won't work with 0.18.

• (FIX) The SOI calculation now uses the empirically tested version from in the game.

0.7.0 - 2012-Oct-02

Initial Public Release.

```Copyright (c) 2012, Jeffrey C. Reinecke

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL JEFFREY REINECKE BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.```