Class AppMath::R2
In: kepler_2d.rb
Parent: Object

Real vector space of two dimensions

Methods

*   +   -   -@   abs   abs2   clone   new   spr   to_s   uv  

Attributes

x  [RW] 
y  [RW] 

Public Class methods

[Source]

    # File kepler_2d.rb, line 25
25:   def initialize(x,y)
26:     @x = x
27:     @y = y
28:   end

Public Instance methods

[Source]

    # File kepler_2d.rb, line 42
42:   def *(s)
43:     R2.new(x * s, y * s)
44:   end

[Source]

    # File kepler_2d.rb, line 34
34:   def +(p)
35:     R2.new(x + p.x, y + p.y)
36:   end

[Source]

    # File kepler_2d.rb, line 38
38:   def -(p)
39:     R2.new(x - p.x, y - p.y)
40:   end

[Source]

    # File kepler_2d.rb, line 46
46:   def -@
47:     R2.new(-x, -y)
48:   end

[Source]

    # File kepler_2d.rb, line 54
54:   def abs
55:     x.hypot(y)
56:   end

abs squared

[Source]

    # File kepler_2d.rb, line 59
59:   def abs2
60:     x * x + y * y
61:   end

[Source]

    # File kepler_2d.rb, line 30
30:   def clone
31:     R.new(x,y)
32:   end

scalar product

[Source]

    # File kepler_2d.rb, line 64
64:   def spr(p)
65:     x * p.x + y * p.y
66:   end

[Source]

    # File kepler_2d.rb, line 50
50:   def to_s
51:     res = "R2(" + x.to_s + ", " + y.to_s + ")"
52:   end

unit vector

[Source]

    # File kepler_2d.rb, line 69
69:   def uv
70:     r = abs
71:     if r.zero?
72:       clone
73:     else 
74:       ri = r.inv
75:       self * ri
76:     end
77:   end

[Validate]