Class: AppMath::R2
- Inherits:
-
Object
- Object
- AppMath::R2
- Defined in:
- lib/kepler_2d.rb
Overview
Real vector space of two dimensions
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #*(s) ⇒ Object
- #+(p) ⇒ Object
- #-(p) ⇒ Object
- #-@ ⇒ Object
- #abs ⇒ Object
-
#abs2 ⇒ Object
abs squared.
- #clone ⇒ Object
-
#initialize(x, y) ⇒ R2
constructor
A new instance of R2.
-
#spr(p) ⇒ Object
scalar product.
- #to_s ⇒ Object
-
#uv ⇒ Object
unit vector.
Constructor Details
#initialize(x, y) ⇒ R2
Returns a new instance of R2.
41 42 43 44 |
# File 'lib/kepler_2d.rb', line 41 def initialize(x,y) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
38 39 40 |
# File 'lib/kepler_2d.rb', line 38 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
39 40 41 |
# File 'lib/kepler_2d.rb', line 39 def y @y end |
Instance Method Details
#abs ⇒ Object
70 71 72 |
# File 'lib/kepler_2d.rb', line 70 def abs x.hypot(y) end |
#abs2 ⇒ Object
abs squared
75 76 77 |
# File 'lib/kepler_2d.rb', line 75 def abs2 x * x + y * y end |
#spr(p) ⇒ Object
scalar product
80 81 82 |
# File 'lib/kepler_2d.rb', line 80 def spr(p) x * p.x + y * p.y end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/kepler_2d.rb', line 66 def to_s res = "R2(" + x.to_s + ", " + y.to_s + ")" end |
#uv ⇒ Object
unit vector
85 86 87 88 89 90 91 92 93 |
# File 'lib/kepler_2d.rb', line 85 def uv r = abs if r.zero? clone else ri = r.inv self * ri end end |