Class: VORuby::CoordinateSystems::Equatorial::RADecPosition
- Inherits:
-
SpaceTime::SpatialPosition
- Object
- SpaceTime::SpatialPosition
- VORuby::CoordinateSystems::Equatorial::RADecPosition
- Defined in:
- lib/voruby/spacetime/spacetime.rb
Instance Attribute Summary collapse
-
#dec ⇒ Object
Returns the value of attribute dec.
-
#distance ⇒ Object
Returns the value of attribute distance.
-
#equinox ⇒ Object
Returns the value of attribute equinox.
-
#ra ⇒ Object
Returns the value of attribute ra.
-
#system ⇒ Object
Returns the value of attribute system.
Attributes inherited from SpaceTime::SpatialPosition
Class Method Summary collapse
-
.equatorial_to_rectangular(ra, dec) ⇒ Object
Convert RA and Dec in decimal degrees to rectangular coordinates.
-
.rectangular_to_equatorial(x, y, z) ⇒ Object
Convert rectangular coordinates to equatorial coordinates in degrees.
Instance Method Summary collapse
- #==(position) ⇒ Object
-
#angular_separation(position) ⇒ Object
Returns the angular separation between two positions in degrees.
-
#initialize(ra, dec, distance = nil, equinox = 2000.0, system = :fk5) ⇒ RADecPosition
constructor
Create a Position object.
-
#precess(to_equinox = 2000.0, system = :fk5) ⇒ Object
Precess the position to the specified equinox.
- #to_s ⇒ Object
Constructor Details
#initialize(ra, dec, distance = nil, equinox = 2000.0, system = :fk5) ⇒ RADecPosition
Create a Position object. ra and dec may be:
1) RightAscension or Declination objects
2) Sexigesimal strings in standard format
3) Strings that looks like decimals
4) Degrees in decimal format.
508 509 510 511 512 513 514 515 516 |
# File 'lib/voruby/spacetime/spacetime.rb', line 508 def initialize(ra, dec, distance=nil, equinox=2000.0, system=:fk5) self.ra = ra self.dec = dec self.distance = distance self.equinox = equinox self.system = system super(self.ra, self.dec, self.distance) end |
Instance Attribute Details
#dec ⇒ Object
Returns the value of attribute dec.
500 501 502 |
# File 'lib/voruby/spacetime/spacetime.rb', line 500 def dec @dec end |
#distance ⇒ Object
Returns the value of attribute distance.
500 501 502 |
# File 'lib/voruby/spacetime/spacetime.rb', line 500 def distance @distance end |
#equinox ⇒ Object
Returns the value of attribute equinox.
501 502 503 |
# File 'lib/voruby/spacetime/spacetime.rb', line 501 def equinox @equinox end |
#ra ⇒ Object
Returns the value of attribute ra.
500 501 502 |
# File 'lib/voruby/spacetime/spacetime.rb', line 500 def ra @ra end |
#system ⇒ Object
Returns the value of attribute system.
501 502 503 |
# File 'lib/voruby/spacetime/spacetime.rb', line 501 def system @system end |
Class Method Details
.equatorial_to_rectangular(ra, dec) ⇒ Object
Convert RA and Dec in decimal degrees to rectangular coordinates.
581 582 583 584 585 586 587 588 589 |
# File 'lib/voruby/spacetime/spacetime.rb', line 581 def self.equatorial_to_rectangular(ra, dec) deg_to_rad = Math::PI / 180.0 x = Math.cos(ra * deg_to_rad) * Math.cos(dec * deg_to_rad) y = Math.sin(ra * deg_to_rad) * Math.cos(dec * deg_to_rad) z = Math.sin(dec * deg_to_rad) return [x, y, z] end |
.rectangular_to_equatorial(x, y, z) ⇒ Object
Convert rectangular coordinates to equatorial coordinates in degrees.
592 593 594 595 596 597 598 599 600 601 |
# File 'lib/voruby/spacetime/spacetime.rb', line 592 def self.rectangular_to_equatorial(x, y, z) rad_to_deg = 180.0 / Math::PI ra_rad = Math.atan(y/x) dec_rad = Math.asin(z) ra_rad = ra_rad + 2 * Math::PI if ra_rad < 0.0 [ra_rad * rad_to_deg, dec_rad * rad_to_deg] end |
Instance Method Details
#==(position) ⇒ Object
548 549 550 551 552 |
# File 'lib/voruby/spacetime/spacetime.rb', line 548 def ==(position) # Precess the new position object into the same equinox as the receiver. position = position.precess(self.equinox, self.system) if position.equinox != self.equinox and position.system != self.system self.ra == position.ra && self.dec == position.dec && self.distance == position.distance end |
#angular_separation(position) ⇒ Object
Returns the angular separation between two positions in degrees.
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
# File 'lib/voruby/spacetime/spacetime.rb', line 531 def angular_separation(position) # Convert to radians ra1 = self.ra.value * (Math::PI / 180.0) dec1 = self.dec.value * (Math::PI / 180.0) ra2 = position.ra.value * (Math::PI / 180.0) dec2 = position.dec.value * (Math::PI / 180.0) ninety = 90.0 * (Math::PI / 180) # One quarter of a circle (90 degrees) in radians sep = Math.acos( Math.cos(ninety - dec1) * Math.cos(ninety - dec2) + Math.sin(ninety - dec1) * Math.sin(ninety - dec2) * Math.cos(ra1 - ra2) ) return sep * (180.0 / Math::PI) end |
#precess(to_equinox = 2000.0, system = :fk5) ⇒ Object
Precess the position to the specified equinox. The constants for the precession matrix and general algorithm are taken from the IDL astro routines PREMAT and PRECESS. Notes: Accuracy of precession decreases for declination values near 90 degrees. Should not be used more than 2.5 centuries from 2000 on the FK5 system (1950.0 on the FK4 system).
558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'lib/voruby/spacetime/spacetime.rb', line 558 def precess(to_equinox=2000.0, system=:fk5) if self.equinox != to_equinox or self.system != system deg_to_rad = Math::PI / 180.0 from_components = Matrix.row_vector(RADecPosition::equatorial_to_rectangular(self.ra.value, self.dec.value)) precession_matrix = Equatorial::precession_matrix(self.equinox, to_equinox, system) to_components = from_components * precession_matrix ra, dec = RADecPosition::rectangular_to_equatorial(to_components[0, 0], to_components[0, 1], to_components[0, 2]) return RADecPosition.new(ra, dec, self.distance, to_equinox, system) else return self end end |
#to_s ⇒ Object
573 574 575 576 577 578 |
# File 'lib/voruby/spacetime/spacetime.rb', line 573 def to_s coords = "#{self.ra}, #{self.dec}" coords << ", #{self.distance}" if self.distance coords end |