Class: Astronoby::AngularVelocity
- Inherits:
-
Object
- Object
- Astronoby::AngularVelocity
- 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
-
#radians_per_second ⇒ Numeric
(also: #rps)
readonly
The angular velocity in radians per second.
Class Method Summary collapse
-
.from_milliarcseconds_per_year(mas_per_year) ⇒ Astronoby::AngularVelocity
A new AngularVelocity.
-
.from_radians_per_second(radians_per_second) ⇒ Astronoby::AngularVelocity
A new AngularVelocity.
-
.zero ⇒ Astronoby::AngularVelocity
A zero angular velocity.
Instance Method Summary collapse
-
#+(other) ⇒ Astronoby::AngularVelocity
The sum.
-
#-(other) ⇒ Astronoby::AngularVelocity
The difference.
-
#-@ ⇒ Astronoby::AngularVelocity
The negated angular velocity.
-
#<=>(other) ⇒ Integer?
-1, 0, or 1; nil if not comparable.
-
#hash ⇒ Integer
Hash value.
-
#initialize(radians_per_second) ⇒ AngularVelocity
constructor
A new instance of AngularVelocity.
-
#milliarcseconds_per_year ⇒ Float
(also: #mas_per_year)
The angular velocity in milliarcseconds per year.
-
#negative? ⇒ Boolean
True if the angular velocity is negative.
-
#positive? ⇒ Boolean
True if the angular velocity is positive.
-
#zero? ⇒ Boolean
True if the angular velocity is zero.
Constructor Details
#initialize(radians_per_second) ⇒ AngularVelocity
Returns a new instance of AngularVelocity.
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_second ⇒ Numeric (readonly) Also known as: rps
Returns 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.
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.
17 18 19 |
# File 'lib/astronoby/angular_velocity.rb', line 17 def from_radians_per_second(radians_per_second) new(radians_per_second) end |
.zero ⇒ Astronoby::AngularVelocity
Returns a zero angular velocity.
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.
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.
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.
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.
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 |
#hash ⇒ Integer
Returns hash value.
84 85 86 |
# File 'lib/astronoby/angular_velocity.rb', line 84 def hash [@radians_per_second, self.class].hash end |
#milliarcseconds_per_year ⇒ Float Also known as: mas_per_year
Returns 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.
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.
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.
79 80 81 |
# File 'lib/astronoby/angular_velocity.rb', line 79 def zero? @radians_per_second.zero? end |