Class: Astronoby::AngularVelocity

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/astronoby/angular_velocity.rb

Overview

Represents an angular velocity with radians per second as its internal representation. Used primarily for stellar proper motion.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(radians_per_second) ⇒ AngularVelocity

Returns a new instance of AngularVelocity.

Parameters:

  • radians_per_second (Numeric)

    the angular velocity in rad/s



35
36
37
38
# File 'lib/astronoby/angular_velocity.rb', line 35

def initialize(radians_per_second)
  @radians_per_second = radians_per_second
  freeze
end

Instance Attribute Details

#radians_per_secondNumeric (readonly) Also known as: rps

Returns the angular velocity in radians per second.

Returns:

  • (Numeric)

    the angular velocity in radians per second



31
32
33
# File 'lib/astronoby/angular_velocity.rb', line 31

def radians_per_second
  @radians_per_second
end

Class Method Details

.from_milliarcseconds_per_year(mas_per_year) ⇒ Astronoby::AngularVelocity

Returns a new AngularVelocity.

Parameters:

  • mas_per_year (Numeric)

    the angular velocity in mas/yr

Returns:



23
24
25
26
27
# File 'lib/astronoby/angular_velocity.rb', line 23

def from_milliarcseconds_per_year(mas_per_year)
  angle = Angle.from_degree_arcseconds(mas_per_year / 1000.0)
  radians_per_second = angle.radians / Constants::SECONDS_PER_JULIAN_YEAR
  new(radians_per_second)
end

.from_radians_per_second(radians_per_second) ⇒ Astronoby::AngularVelocity

Returns a new AngularVelocity.

Parameters:

  • radians_per_second (Numeric)

    the angular velocity in rad/s

Returns:



17
18
19
# File 'lib/astronoby/angular_velocity.rb', line 17

def from_radians_per_second(radians_per_second)
  new(radians_per_second)
end

.zeroAstronoby::AngularVelocity

Returns a zero angular velocity.

Returns:



11
12
13
# File 'lib/astronoby/angular_velocity.rb', line 11

def zero
  new(0)
end

Instance Method Details

#+(other) ⇒ Astronoby::AngularVelocity

Returns the sum.

Parameters:

Returns:



49
50
51
52
53
# File 'lib/astronoby/angular_velocity.rb', line 49

def +(other)
  self.class.from_radians_per_second(
    @radians_per_second + other.radians_per_second
  )
end

#-(other) ⇒ Astronoby::AngularVelocity

Returns the difference.

Parameters:

Returns:



57
58
59
60
61
# File 'lib/astronoby/angular_velocity.rb', line 57

def -(other)
  self.class.from_radians_per_second(
    @radians_per_second - other.radians_per_second
  )
end

#-@Astronoby::AngularVelocity

Returns the negated angular velocity.

Returns:



64
65
66
# File 'lib/astronoby/angular_velocity.rb', line 64

def -@
  self.class.from_radians_per_second(-@radians_per_second)
end

#<=>(other) ⇒ Integer?

Returns -1, 0, or 1; nil if not comparable.

Parameters:

Returns:

  • (Integer, nil)

    -1, 0, or 1; nil if not comparable



90
91
92
93
94
# File 'lib/astronoby/angular_velocity.rb', line 90

def <=>(other)
  return unless other.is_a?(self.class)

  @radians_per_second <=> other.radians_per_second
end

#hashInteger

Returns hash value.

Returns:

  • (Integer)

    hash value



84
85
86
# File 'lib/astronoby/angular_velocity.rb', line 84

def hash
  [@radians_per_second, self.class].hash
end

#milliarcseconds_per_yearFloat Also known as: mas_per_year

Returns the angular velocity in milliarcseconds per year.

Returns:

  • (Float)

    the angular velocity in milliarcseconds per year



41
42
43
44
# File 'lib/astronoby/angular_velocity.rb', line 41

def milliarcseconds_per_year
  angle = Angle.from_radians(@radians_per_second)
  angle.degree_milliarcseconds * Constants::SECONDS_PER_JULIAN_YEAR
end

#negative?Boolean

Returns true if the angular velocity is negative.

Returns:

  • (Boolean)

    true if the angular velocity is negative



74
75
76
# File 'lib/astronoby/angular_velocity.rb', line 74

def negative?
  @radians_per_second < 0
end

#positive?Boolean

Returns true if the angular velocity is positive.

Returns:

  • (Boolean)

    true if the angular velocity is positive



69
70
71
# File 'lib/astronoby/angular_velocity.rb', line 69

def positive?
  @radians_per_second > 0
end

#zero?Boolean

Returns true if the angular velocity is zero.

Returns:

  • (Boolean)

    true if the angular velocity is zero



79
80
81
# File 'lib/astronoby/angular_velocity.rb', line 79

def zero?
  @radians_per_second.zero?
end