Skip to content

Commit

Permalink
Treat true and mean obliquity as angles
Browse files Browse the repository at this point in the history
  • Loading branch information
rhannequin committed Feb 24, 2024
1 parent d673f52 commit a583b44
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 44 deletions.
8 changes: 4 additions & 4 deletions lib/astronoby/coordinates/ecliptic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ def initialize(latitude:, longitude:)
# Chapter: 4 - Orbits and Coordinate Systems
def to_equatorial(epoch:)
mean_obliquity = MeanObliquity.for_epoch(epoch)
obliquity = mean_obliquity.value

y = Angle.as_radians(
@longitude.sin * obliquity.cos - @latitude.tan * obliquity.sin
@longitude.sin * mean_obliquity.cos -
@latitude.tan * mean_obliquity.sin
)
x = Angle.as_radians(@longitude.cos)
r = Angle.atan(y.radians / x.radians)
right_ascension = Util::Trigonometry.adjustement_for_arctangent(y, x, r)

declination = Angle.asin(
@latitude.sin * obliquity.cos +
@latitude.cos * obliquity.sin * @longitude.sin
@latitude.sin * mean_obliquity.cos +
@latitude.cos * mean_obliquity.sin * @longitude.sin
)

Equatorial.new(
Expand Down
9 changes: 4 additions & 5 deletions lib/astronoby/coordinates/equatorial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,18 @@ def to_horizontal(time:, latitude:, longitude:)
# Chapter: 4 - Orbits and Coordinate Systems
def to_ecliptic(epoch:)
mean_obliquity = MeanObliquity.for_epoch(epoch)
obliquity = mean_obliquity.value

y = Angle.as_radians(
@right_ascension.sin * obliquity.cos +
@declination.tan * obliquity.sin
@right_ascension.sin * mean_obliquity.cos +
@declination.tan * mean_obliquity.sin
)
x = Angle.as_radians(@right_ascension.cos)
r = Angle.atan(y.radians / x.radians)
longitude = Util::Trigonometry.adjustement_for_arctangent(y, x, r)

latitude = Angle.asin(
@declination.sin * obliquity.cos -
@declination.cos * obliquity.sin * @right_ascension.sin
@declination.sin * mean_obliquity.cos -
@declination.cos * mean_obliquity.sin * @right_ascension.sin
)

Ecliptic.new(
Expand Down
26 changes: 7 additions & 19 deletions lib/astronoby/mean_obliquity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,22 @@ class MeanObliquity
EPOCH_OF_REFERENCE = Epoch::DEFAULT_EPOCH
OBLIQUITY_OF_REFERENCE = 23.4392794

def initialize(obliquity)
@obliquity = obliquity
end

def self.for_epoch(epoch)
if epoch == EPOCH_OF_REFERENCE
return new(obliquity_of_reference)
end
return obliquity_of_reference if epoch == EPOCH_OF_REFERENCE

t = (epoch - EPOCH_OF_REFERENCE) / Epoch::DAYS_PER_JULIAN_CENTURY

new(
Angle.as_degrees(
obliquity_of_reference.degrees - (
46.815 * t -
0.0006 * t * t +
0.00181 * t * t * t
) / 3600
)
Angle.as_degrees(
obliquity_of_reference.degrees - (
46.815 * t -
0.0006 * t * t +
0.00181 * t * t * t
) / 3600
)
end

def self.obliquity_of_reference
Angle.as_dms(23, 26, 21.45)
end

def value
@obliquity
end
end
end
10 changes: 1 addition & 9 deletions lib/astronoby/true_obliquity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@

module Astronoby
class TrueObliquity
def initialize(obliquity)
@obliquity = obliquity
end

def self.for_epoch(epoch)
mean_obliquity = MeanObliquity.for_epoch(epoch)
nutation = Nutation.for_obliquity_of_the_ecliptic(epoch: epoch)

new(mean_obliquity.value + nutation)
end

def value
@obliquity
mean_obliquity + nutation
end
end
end
10 changes: 5 additions & 5 deletions spec/astronoby/mean_obliquity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
RSpec.describe Astronoby::MeanObliquity do
describe "::for_epoch" do
it "returns an angle" do
obliquity = described_class.for_epoch(Astronoby::Epoch::J2000).value
obliquity = described_class.for_epoch(Astronoby::Epoch::J2000)

expect(obliquity).to be_kind_of(Astronoby::Angle)
end

it "returns the obliquity angle for standard epoch" do
obliquity = described_class.for_epoch(Astronoby::Epoch::J2000).value
obliquity = described_class.for_epoch(Astronoby::Epoch::J2000)

expect(obliquity.degrees.to_f).to eq(23.439291666666666)
end

it "returns the obliquity angle for epoch 1950" do
obliquity = described_class.for_epoch(Astronoby::Epoch::J1950).value
obliquity = described_class.for_epoch(Astronoby::Epoch::J1950)

expect(obliquity.degrees.to_f).to eq 23.445793854513887
end
Expand All @@ -28,7 +28,7 @@
context "with real life arguments (book example)" do
it "computes properly" do
epoch = Astronoby::Epoch.from_time(Time.utc(2009, 7, 6, 0, 0, 0))
obliquity = described_class.for_epoch(epoch).value
obliquity = described_class.for_epoch(epoch)

expect(obliquity.str(:dms)).to eq "+23° 26′ 16.9979″"
end
Expand All @@ -42,7 +42,7 @@
context "with real life arguments (book example)" do
it "computes properly" do
epoch = Astronoby::Epoch.from_time(Time.utc(1987, 4, 10, 0, 0, 0))
obliquity = described_class.for_epoch(epoch).value
obliquity = described_class.for_epoch(epoch)

expect(obliquity.str(:dms)).to eq "+23° 26′ 27.4093″"
end
Expand Down
4 changes: 2 additions & 2 deletions spec/astronoby/true_obliquity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe Astronoby::TrueObliquity do
describe "::for_epoch" do
it "returns an angle" do
obliquity = described_class.for_epoch(Astronoby::Epoch::J2000).value
obliquity = described_class.for_epoch(Astronoby::Epoch::J2000)

expect(obliquity).to be_kind_of(Astronoby::Angle)
end
Expand All @@ -16,7 +16,7 @@
context "with real life arguments (book example)" do
it "computes properly" do
epoch = Astronoby::Epoch.from_time(Time.utc(1987, 4, 10, 0, 0, 0))
obliquity = described_class.for_epoch(epoch).value
obliquity = described_class.for_epoch(epoch)

expect(obliquity.str(:dms)).to eq "+23° 26′ 36.8401″"
end
Expand Down

0 comments on commit a583b44

Please sign in to comment.