Module: Korba::OrbitUtils

Included in:
Kep, KeplerEquationFunction, Tle
Defined in:
lib/korba/orbit_utils.rb

Instance Method Summary collapse

Instance Method Details

#deg_to_rad(deg) ⇒ Object



43
44
45
46
# File 'lib/korba/orbit_utils.rb', line 43

def deg_to_rad(deg)
  rad = deg * Math::PI / 180.0
  normalize_rad(rad)
end

#distanceObject



30
31
32
# File 'lib/korba/orbit_utils.rb', line 30

def distance
  semi_major_axis * (1 - eccentricity * Math.cos(deg_to_rad(eccentric_anomaly)))
end

#eccentric_anomalyObject



18
19
20
21
22
23
# File 'lib/korba/orbit_utils.rb', line 18

def eccentric_anomaly
  f = KeplerEquationFunction.new(eccentricity:, mean_anomaly:)
  x = [deg_to_rad(mean_anomaly)]
  nlsolve(f, x)
  rad_to_deg(x[0])
end

#height_at_apogeeObject



14
15
16
# File 'lib/korba/orbit_utils.rb', line 14

def height_at_apogee
  semi_major_axis * (1 + eccentricity) - Constant::EARTH_RADIUS
end

#height_at_perigeeObject



10
11
12
# File 'lib/korba/orbit_utils.rb', line 10

def height_at_perigee
  semi_major_axis * (1 - eccentricity) - Constant::EARTH_RADIUS
end

#normalize_deg(deg) ⇒ Object



60
61
62
63
64
65
# File 'lib/korba/orbit_utils.rb', line 60

def normalize_deg(deg)
  deg = deg + 360 if deg < 0
  normalized_deg = deg > 360 ? deg - 360 : deg
  normalize_deg(normalized_deg) if normalized_deg != deg
  normalized_deg
end

#normalize_rad(rad) ⇒ Object



48
49
50
51
52
53
# File 'lib/korba/orbit_utils.rb', line 48

def normalize_rad(rad)
  rad = rad + 2 * Math::PI if rad < 0
  normalize_rad = rad > 2 * Math::PI ? rad - 2 * Math::PI : rad
  normalize_rad(normalize_rad) if normalize_rad != rad
  normalize_rad
end

#path_angleObject



38
39
40
41
# File 'lib/korba/orbit_utils.rb', line 38

def path_angle
  factor = Math.sqrt(Constant::GME * semi_major_axis * (1 - eccentricity ** 2)) / (distance * velocity)
  rad_to_deg(Math.acos(factor))
end

#rad_to_deg(rad) ⇒ Object



55
56
57
58
# File 'lib/korba/orbit_utils.rb', line 55

def rad_to_deg(rad)
  deg = rad * 180.0 / Math::PI
  normalize_deg(deg)
end

#semi_major_axisObject



5
6
7
8
# File 'lib/korba/orbit_utils.rb', line 5

def semi_major_axis
  # a = (μ / n^2)^(1/3) m
  (Constant::GME / (mean_motion * 2 * Math::PI / 86400.0) ** 2.0) ** (1.0 / 3.0)
end

#true_anomalyObject



25
26
27
28
# File 'lib/korba/orbit_utils.rb', line 25

def true_anomaly
  factor = (Math.cos(deg_to_rad(eccentric_anomaly)) - eccentricity) / (1 - eccentricity * Math.cos(deg_to_rad(eccentric_anomaly)))
  rad_to_deg(Math.acos(factor))
end

#velocityObject



34
35
36
# File 'lib/korba/orbit_utils.rb', line 34

def velocity
  Math.sqrt(Constant::GME * (2 / distance - 1 / semi_major_axis))
end