Module: Vector2d::Properties
- Included in:
- Vector2d
- Defined in:
- lib/vector2d/properties.rb
Instance Method Summary collapse
-
#angle ⇒ Object
Angle of vector.
-
#aspect_ratio ⇒ Object
Aspect ratio of vector.
-
#length ⇒ Object
Length of vector.
-
#normalized? ⇒ Boolean
Is this a normalized vector?.
-
#squared_length ⇒ Object
Squared length of vector.
Instance Method Details
#angle ⇒ Object
Angle of vector.
Vector2d(2, 3).angle # => 0.9827..
9 10 11 |
# File 'lib/vector2d/properties.rb', line 9 def angle Math.atan2(y, x) end |
#aspect_ratio ⇒ Object
Aspect ratio of vector.
Vector2d(2, 3).aspect_ratio # => 0.6667..
17 18 19 |
# File 'lib/vector2d/properties.rb', line 17 def aspect_ratio (x.to_f / y).abs end |
#length ⇒ Object
Length of vector.
Vector2d(2, 3).length # => 3.6055..
25 26 27 |
# File 'lib/vector2d/properties.rb', line 25 def length Math.sqrt(squared_length) end |
#normalized? ⇒ Boolean
42 43 44 |
# File 'lib/vector2d/properties.rb', line 42 def normalized? (length.to_f - 1.0).abs < Float::EPSILON end |
#squared_length ⇒ Object
Squared length of vector.
Vector2d(2, 3).squared_length # => 13
33 34 35 |
# File 'lib/vector2d/properties.rb', line 33 def squared_length (x * x) + (y * y) end |