Module: Korba::OrbitUtils

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

Instance Method Summary collapse

Instance Method Details

#deg_to_rad(deg) ⇒ Object



47
48
49
50
# File 'lib/korba/orbit_utils.rb', line 47

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

#distanceObject



32
33
34
# File 'lib/korba/orbit_utils.rb', line 32

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

#eccentric_anomalyObject



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

def eccentric_anomaly
  kepler = KeplersEquation.new(eccentricity:, mean_anomaly:)
  rad_to_deg(kepler.solve)
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



64
65
66
67
68
69
# File 'lib/korba/orbit_utils.rb', line 64

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

#normalize_rad(rad) ⇒ Object



52
53
54
55
56
57
# File 'lib/korba/orbit_utils.rb', line 52

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

#path_angleObject



40
41
42
43
44
45
# File 'lib/korba/orbit_utils.rb', line 40

def path_angle
  return 0.0 if eccentricity < 1e-15

  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



59
60
61
62
# File 'lib/korba/orbit_utils.rb', line 59

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.0 * Math::PI / 86400.0) ** 2.0) ** (1.0 / 3.0)
end

#true_anomalyObject



23
24
25
26
27
28
29
30
# File 'lib/korba/orbit_utils.rb', line 23

def true_anomaly
  e_rad = deg_to_rad(eccentric_anomaly)
  y = Math.sqrt(1 - eccentricity ** 2) * Math.sin(e_rad)
  x = Math.cos(e_rad) - eccentricity

  # atan2(y, x) で正確な位相(-pi から pi)を求める
  rad_to_deg(Math.atan2(y, x))
end

#velocityObject



36
37
38
# File 'lib/korba/orbit_utils.rb', line 36

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