Module: Korba::OrbitUtils
- Included in:
- Car, Kep, KeplersEquation, Tle
- Defined in:
- lib/korba/orbit_utils.rb
Instance Method Summary collapse
- #deg_to_rad(deg) ⇒ Object
- #distance ⇒ Object
- #eccentric_anomaly ⇒ Object
- #height_at_apogee ⇒ Object
- #height_at_perigee ⇒ Object
- #normalize_deg(deg) ⇒ Object
- #normalize_rad(rad) ⇒ Object
- #path_angle ⇒ Object
- #rad_to_deg(rad) ⇒ Object
- #semi_major_axis ⇒ Object
- #true_anomaly ⇒ Object
- #velocity ⇒ Object
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 |
#distance ⇒ Object
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_anomaly ⇒ Object
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_apogee ⇒ Object
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_perigee ⇒ Object
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_angle ⇒ Object
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_axis ⇒ Object
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_anomaly ⇒ Object
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 |