class KerbalDyn::Planetoid

Planetoid is the superclass of any planetary object. It is primarily used to build existing planetoids via factory methods to calculate orbit characteristics around the planetoid.

Most interesting parameters are included through the DerivedParameters module.

Public Class Methods

new(name, options={}) click to toggle source
Calls superclass method KerbalDyn::Body::new
# File lib/kerbaldyn/planetoid.rb, line 115
def initialize(name, options={})
  super
end
orbit(options={}) click to toggle source
# File lib/kerbaldyn/planetoid.rb, line 197
def self.orbit(options={})
  return Orbit.new(self, options)
end
planetoid_methods() click to toggle source

Returns an array of the planetoid methods

# File lib/kerbaldyn/planetoid.rb, line 23
def self.planetoid_methods
  return @planet_methods ||= [:kerbol, :moho, :eve, :gilly, :kerbin, :mun, :minmus, :duna, :ike, :jool, :laythe, :vall, :tylo, :bop]
end

Private Class Methods

make(planet_ref) click to toggle source

For data read in from data files, this private method DRYs the process.

# File lib/kerbaldyn/planetoid.rb, line 11
def self.make(planet_ref)
  data = Data.fetch(:planet_data)[planet_ref][:planetoid]
  name = data[:name]
  parameters = data.reject {|k,v| k == :name}
  return self.new(name, parameters).freeze
end

Public Instance Methods

circular_orbit(radius) click to toggle source
# File lib/kerbaldyn/planetoid.rb, line 185
def circular_orbit(radius)
  return Orbit.circular_orbit(self, radius)
end
circular_orbit_of_period(period) click to toggle source
# File lib/kerbaldyn/planetoid.rb, line 189
def circular_orbit_of_period(period)
  return Orbit.circular_orbit_of_period(self, period)
end
density() click to toggle source

The density of the planetoid.

# File lib/kerbaldyn/planetoid.rb, line 162
def density
  return self.mass / self.volume
end
Also aliased as: rho
equitorial_velocity(h=0.0) click to toggle source

Equitorial linear velocity of the planetoid.

If a value is gien, then this is used as the height above the surface for the calculation.

# File lib/kerbaldyn/planetoid.rb, line 170
def equitorial_velocity(h=0.0)
  return self.angular_velocity * (self.radius + h)
end
escape_orbit(periapsis) click to toggle source
# File lib/kerbaldyn/planetoid.rb, line 193
def escape_orbit(periapsis)
  return Orbit.escape_orbit(self, periapsis)
end
escape_velocity() click to toggle source

Calculates the escape velocity of the planetoid.

# File lib/kerbaldyn/planetoid.rb, line 175
def escape_velocity
  return Math.sqrt( 2.0 * self.gravitational_parameter / self.radius )
end
g(h=0.0)
Alias for: surface_gravity
geostationary_orbit() click to toggle source
Orbit Library Methods =====
# File lib/kerbaldyn/planetoid.rb, line 181
def geostationary_orbit
  return Orbit.geostationary_orbit(self)
end
gravitational_acceleration(r) click to toggle source

Returns the gravitational accelaration at a given radius from the center of the planet.

# File lib/kerbaldyn/planetoid.rb, line 144
def gravitational_acceleration(r)
  return self.gravitational_parameter / r**2
end
gravitational_parameter() click to toggle source

Returns the gravtiational_parameter (G*M) of the planetoid.

# File lib/kerbaldyn/planetoid.rb, line 122
def gravitational_parameter
  Constants::G * self.mass
end
Also aliased as: mu
mu()
rho()
Alias for: density
rotational_period() click to toggle source

The rotational period of this body around its axis.

# File lib/kerbaldyn/planetoid.rb, line 133
def rotational_period
  return 2.0 * Math::PI / self.angular_velocity
end
Also aliased as: t
rotational_period=(period) click to toggle source

Set the rotational period of this body.

# File lib/kerbaldyn/planetoid.rb, line 138
def rotational_period=(period)
  self.angular_velocity = period && (2.0 * Math::PI / period)
end
surface_gravity(h=0.0) click to toggle source

Returns the surface gravity (acceleration) of this planetoid.

If a value is given, then this is used as the height above the surface to calculate the gravity.

# File lib/kerbaldyn/planetoid.rb, line 152
def surface_gravity(h=0.0)
  return self.gravitational_acceleration( self.radius + h )
end
Also aliased as: g
t()
Alias for: rotational_period
volume() click to toggle source

The volume of the planetoid.

# File lib/kerbaldyn/planetoid.rb, line 157
def volume
  return (4.0/3.0) * Math::PI * self.radius**3
end

Private Instance Methods

gravitational_parameter=(mu) click to toggle source

Sets the gravitational parameter (G*M) by deriving the mass and setting it.

# File lib/kerbaldyn/planetoid.rb, line 127
def gravitational_parameter=(mu)
  self.send(:mass=, mu / Constants::G)
end

Library Methods

↑ top

Public Class Methods

bop() click to toggle source

The captured asteroid around Jool.

# File lib/kerbaldyn/planetoid.rb, line 111
def self.bop
  return @bop ||= make(__method__)
end
duna() click to toggle source

The fourth planet (Mars like)

# File lib/kerbaldyn/planetoid.rb, line 75
def self.duna
  return @duna ||= make(__method__)
end
eve() click to toggle source

The second planet (Venus like)

# File lib/kerbaldyn/planetoid.rb, line 63
def self.eve
  return @eve ||= make(__method__)
end
gilly() click to toggle source

The asteroid moon of Gilly

# File lib/kerbaldyn/planetoid.rb, line 69
def self.gilly
  return @gilly ||= make(__method__)
end
ike() click to toggle source

The moon of Duna

# File lib/kerbaldyn/planetoid.rb, line 81
def self.ike
  return @ike ||= make(__method__)
end
jool() click to toggle source

The fifth planet (Jupiter like)

# File lib/kerbaldyn/planetoid.rb, line 87
def self.jool
  return @jool ||= make(__method__)
end
kerbin() click to toggle source

The Earth-like Homeworld.

# File lib/kerbaldyn/planetoid.rb, line 39
def self.kerbin
  return @kerbin ||= make(__method__)
end
kerbol() click to toggle source

The Kerbal Sun.

# File lib/kerbaldyn/planetoid.rb, line 29
def self.kerbol
  # TODO: Refactor to calculate these from data on-the-fly (need to output that kind of data first).
  #
  # Grav Parameter calculated from semimajor axis and velocity vector dumps via mu = a*v**2, and is good to around the 15th digit.
  # Radius calculated by subtracting Kerbin Apa from Apr in data dump
  return @kerbol ||= self.new('Kerbol', :gravitational_parameter => 1172332794832492300.0, :radius => 261600000).freeze
end
laythe() click to toggle source

The first moon of Jool, ocean moon with atmosphere

# File lib/kerbaldyn/planetoid.rb, line 93
def self.laythe
  return @laythe ||= make(__method__)
end
minmus() click to toggle source

A small outter moon of Kerbin; no Solar System equivalent.

# File lib/kerbaldyn/planetoid.rb, line 51
def self.minmus
  return @minmus ||= make(__method__)
end
moho() click to toggle source

The inner planet (Mercury like)

# File lib/kerbaldyn/planetoid.rb, line 57
def self.moho
  return @moho ||= make(__method__)
end
mun() click to toggle source

The Moon equivalient; orbits Kerbin.

# File lib/kerbaldyn/planetoid.rb, line 45
def self.mun
  return @mun ||= make(__method__)
end
tylo() click to toggle source

The third moon of Jool, rocky

# File lib/kerbaldyn/planetoid.rb, line 105
def self.tylo
  return @tylo ||= make(__method__)
end
vall() click to toggle source

The second moon of Jool, ice moon

# File lib/kerbaldyn/planetoid.rb, line 99
def self.vall
  return @vall ||= make(__method__)
end