Class: RubyChartEngine::Calculations::Positions
- Inherits:
-
Object
- Object
- RubyChartEngine::Calculations::Positions
- Defined in:
- lib/ruby_chart_engine/calculations/positions.rb
Instance Attribute Summary collapse
-
#julian_day ⇒ Object
readonly
Returns the value of attribute julian_day.
-
#latitude ⇒ Object
readonly
Returns the value of attribute latitude.
-
#longitude ⇒ Object
readonly
Returns the value of attribute longitude.
Instance Method Summary collapse
-
#calculate_all_planets ⇒ Object
Calculate all planets.
-
#calculate_planet(planet_id) ⇒ Object
Calculate position for a single celestial object.
-
#initialize(julian_day:, latitude:, longitude:) ⇒ Positions
constructor
A new instance of Positions.
-
#longitude_to_sign(longitude) ⇒ Object
Get sign from longitude.
-
#movement_status(speed) ⇒ Object
Get movement status.
-
#retrograde?(speed) ⇒ Boolean
Determine if planet is retrograde.
Constructor Details
#initialize(julian_day:, latitude:, longitude:) ⇒ Positions
Returns a new instance of Positions.
6 7 8 9 10 |
# File 'lib/ruby_chart_engine/calculations/positions.rb', line 6 def initialize(julian_day:, latitude:, longitude:) @julian_day = julian_day @latitude = latitude @longitude = longitude end |
Instance Attribute Details
#julian_day ⇒ Object (readonly)
Returns the value of attribute julian_day.
4 5 6 |
# File 'lib/ruby_chart_engine/calculations/positions.rb', line 4 def julian_day @julian_day end |
#latitude ⇒ Object (readonly)
Returns the value of attribute latitude.
4 5 6 |
# File 'lib/ruby_chart_engine/calculations/positions.rb', line 4 def latitude @latitude end |
#longitude ⇒ Object (readonly)
Returns the value of attribute longitude.
4 5 6 |
# File 'lib/ruby_chart_engine/calculations/positions.rb', line 4 def longitude @longitude end |
Instance Method Details
#calculate_all_planets ⇒ Object
Calculate all planets
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ruby_chart_engine/calculations/positions.rb', line 49 def calculate_all_planets positions = {} PLANETS.each do |name, id| positions[name] = calculate_planet(id) end # Calculate points POINTS.each do |name, id| if name == :south_node # South Node is opposite of North Node north_node = calculate_planet(POINTS[:north_node]) positions[name] = north_node.dup positions[name][:longitude] = normalize_degrees(north_node[:longitude] + 180) elsif name == :chiron # Chiron is not available in Moshier ephemeris, skip it # Would require external ephemeris files (seas_*.se1) next else positions[name] = calculate_planet(id) end end positions end |
#calculate_planet(planet_id) ⇒ Object
Calculate position for a single celestial object
13 14 15 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 45 46 |
# File 'lib/ruby_chart_engine/calculations/positions.rb', line 13 def calculate_planet(planet_id) # Calculation flags: 4 = SEFLG_MOSEPH (use built-in Moshier ephemeris), 256 = SEFLG_SPEED # Using Moshier ephemeris (analytical) to avoid needing external ephemeris files # Provides precision of ~0.1 arc seconds for planets, ~3" for Moon flags = 4 | 256 # SEFLG_MOSEPH | SEFLG_SPEED result = Swe4r.swe_calc_ut(julian_day, planet_id, flags) # swe_calc_ut returns an array: [longitude, latitude, distance, speed_long, speed_lat, speed_dist] # Extract values based on whether it's an array or hash if result.is_a?(Array) { longitude: result[0], latitude: result[1], distance: result[2], speed_longitude: result[3], speed_latitude: result[4], speed_distance: result[5] } elsif result.is_a?(Hash) { longitude: result[:longitude] || result['longitude'], latitude: result[:latitude] || result['latitude'], distance: result[:distance] || result['distance'], speed_longitude: result[:speed_longitude] || result['speed_longitude'], speed_latitude: result[:speed_latitude] || result['speed_latitude'], speed_distance: result[:speed_distance] || result['speed_distance'] } else raise Error, "Unexpected swe_calc_ut return type: #{result.class}" end rescue => e raise Error, "Failed to calculate position for planet #{planet_id}: #{e.}" end |
#longitude_to_sign(longitude) ⇒ Object
Get sign from longitude
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ruby_chart_engine/calculations/positions.rb', line 76 def longitude_to_sign(longitude) sign_index = (longitude / 30).floor sign_longitude = longitude % 30 { index: sign_index, sign: SIGNS[sign_index], longitude: sign_longitude, decan: ((sign_longitude / 10).floor + 1) } end |
#movement_status(speed) ⇒ Object
Get movement status
94 95 96 97 98 99 100 101 102 |
# File 'lib/ruby_chart_engine/calculations/positions.rb', line 94 def movement_status(speed) if speed.abs < 0.0001 'stationary' elsif speed < 0 'retrograde' else 'direct' end end |
#retrograde?(speed) ⇒ Boolean
Determine if planet is retrograde
89 90 91 |
# File 'lib/ruby_chart_engine/calculations/positions.rb', line 89 def retrograde?(speed) speed < 0 end |