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
KerbalDyn::Body::new
# File lib/kerbaldyn/planetoid.rb, line 115 def initialize(name, options={}) super end
# File lib/kerbaldyn/planetoid.rb, line 197 def self.orbit(options={}) return Orbit.new(self, options) end
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
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
# File lib/kerbaldyn/planetoid.rb, line 185 def circular_orbit(radius) return Orbit.circular_orbit(self, radius) end
# File lib/kerbaldyn/planetoid.rb, line 189 def circular_orbit_of_period(period) return Orbit.circular_orbit_of_period(self, period) end
The density of the planetoid.
# File lib/kerbaldyn/planetoid.rb, line 162 def density return self.mass / self.volume end
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
# File lib/kerbaldyn/planetoid.rb, line 193 def escape_orbit(periapsis) return Orbit.escape_orbit(self, periapsis) end
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
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
Returns the gravtiational_parameter (G*M) of the planetoid.
# File lib/kerbaldyn/planetoid.rb, line 122 def gravitational_parameter Constants::G * self.mass end
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
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
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
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
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
↑ topPublic Class Methods
The captured asteroid around Jool.
# File lib/kerbaldyn/planetoid.rb, line 111 def self.bop return @bop ||= make(__method__) end
The fourth planet (Mars like)
# File lib/kerbaldyn/planetoid.rb, line 75 def self.duna return @duna ||= make(__method__) end
The second planet (Venus like)
# File lib/kerbaldyn/planetoid.rb, line 63 def self.eve return @eve ||= make(__method__) end
The asteroid moon of Gilly
# File lib/kerbaldyn/planetoid.rb, line 69 def self.gilly return @gilly ||= make(__method__) end
The moon of Duna
# File lib/kerbaldyn/planetoid.rb, line 81 def self.ike return @ike ||= make(__method__) end
The fifth planet (Jupiter like)
# File lib/kerbaldyn/planetoid.rb, line 87 def self.jool return @jool ||= make(__method__) end
The Earth-like Homeworld.
# File lib/kerbaldyn/planetoid.rb, line 39 def self.kerbin return @kerbin ||= make(__method__) end
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
The first moon of Jool, ocean moon with atmosphere
# File lib/kerbaldyn/planetoid.rb, line 93 def self.laythe return @laythe ||= make(__method__) end
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
The inner planet (Mercury like)
# File lib/kerbaldyn/planetoid.rb, line 57 def self.moho return @moho ||= make(__method__) end
The Moon equivalient; orbits Kerbin.
# File lib/kerbaldyn/planetoid.rb, line 45 def self.mun return @mun ||= make(__method__) end
The third moon of Jool, rocky
# File lib/kerbaldyn/planetoid.rb, line 105 def self.tylo return @tylo ||= make(__method__) end
The second moon of Jool, ice moon
# File lib/kerbaldyn/planetoid.rb, line 99 def self.vall return @vall ||= make(__method__) end