Class: Korba::KeplersEquation
- Inherits:
-
Object
- Object
- Korba::KeplersEquation
- Includes:
- OrbitUtils
- Defined in:
- lib/korba/keplers_equation.rb
Constant Summary collapse
- MAX_ITERATIONS =
1000
Instance Attribute Summary collapse
-
#eccentricity ⇒ Object
readonly
Returns the value of attribute eccentricity.
-
#mean_anomaly ⇒ Object
readonly
Returns the value of attribute mean_anomaly.
Instance Method Summary collapse
-
#initialize(eccentricity:, mean_anomaly:) ⇒ KeplersEquation
constructor
A new instance of KeplersEquation.
- #solve(tolerance = 1e-10) ⇒ Object
Methods included from OrbitUtils
#deg_to_rad, #distance, #eccentric_anomaly, #height_at_apogee, #height_at_perigee, #normalize_deg, #normalize_rad, #path_angle, #rad_to_deg, #semi_major_axis, #true_anomaly, #velocity
Constructor Details
#initialize(eccentricity:, mean_anomaly:) ⇒ KeplersEquation
Returns a new instance of KeplersEquation.
9 10 11 12 13 |
# File 'lib/korba/keplers_equation.rb', line 9 def initialize(eccentricity:, mean_anomaly:) super() @eccentricity = eccentricity @mean_anomaly = mean_anomaly end |
Instance Attribute Details
#eccentricity ⇒ Object (readonly)
Returns the value of attribute eccentricity.
7 8 9 |
# File 'lib/korba/keplers_equation.rb', line 7 def eccentricity @eccentricity end |
#mean_anomaly ⇒ Object (readonly)
Returns the value of attribute mean_anomaly.
7 8 9 |
# File 'lib/korba/keplers_equation.rb', line 7 def mean_anomaly @mean_anomaly end |
Instance Method Details
#solve(tolerance = 1e-10) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/korba/keplers_equation.rb', line 16 def solve(tolerance = 1e-10) m_rad = deg_to_rad(mean_anomaly) if eccentricity < 0.8 en = m_rad else en = Math::PI end MAX_ITERATIONS.times do # f(E) = E - e*sin(E) - M # f'(E) = 1 - e*cos(E) sin_en = Math.sin(en.to_f) cos_en = Math.cos(en.to_f) f = en - eccentricity * sin_en - m_rad f_dot = 1 - eccentricity * cos_en # 更新 delta = f / f_dot en = en - delta # 収束判定 break if delta.abs < tolerance end en end |