Class: Vector
- Inherits:
-
Object
show all
- Defined in:
- lib/geometry/vector.rb
Overview
Monkeypatch Vector to overcome some deficiencies
Constant Summary
collapse
- X =
Vector[1,0,0]
- Y =
Vector[0,1,0]
- Z =
Vector[0,0,1]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#options ⇒ Object
7
8
9
10
|
# File 'lib/geometry/vector.rb', line 7
def options
@options = {} if !@options
@options
end
|
Instance Method Details
#+@ ⇒ Object
17
18
19
|
# File 'lib/geometry/vector.rb', line 17
def +@
self
end
|
#-@ ⇒ Object
21
22
23
|
# File 'lib/geometry/vector.rb', line 21
def -@
Vector[*(@elements.map {|e| -e })]
end
|
#cross(other) ⇒ Vector
Also known as:
**
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/geometry/vector.rb', line 28
def cross(other)
Vector.Raise ErrDimensionMismatch unless @elements.size == other.size
case @elements.size
when 0 then raise ArgumentError, "Can't multply zero-length Vectors"
when 1 then @elements.first * other.first
when 2 then @elements.first * other[1] - @elements.last * other.first
when 3 then Vector[ @elements[1]*other[2] - @elements[2]*other[1],
@elements[2]*other[0] - @elements[0]*other[2],
@elements[0]*other[1] - @elements[1]*other[0]]
end
end
|