class Vector
Monkeypatch Vector
to overcome some deficiencies
Constants
- X
- Y
- Z
Public Instance Methods
+@()
click to toggle source
@group Unary operators
# File lib/euclidean/vector.rb, line 10 def +@ self end
-@()
click to toggle source
# File lib/euclidean/vector.rb, line 14 def -@ Vector[*(@elements.map {|e| -e })] end
cross(other)
click to toggle source
Cross-product of two {Vector}s @return [Vector]
# File lib/euclidean/vector.rb, line 21 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
Also aliased as: **