class Geometry::Vector

Public Instance Methods

*(scalar) click to toggle source
# File lib/geometry/vector.rb, line 38
def *(scalar)      
  Vector.new(x * scalar, y * scalar)
end
+(vector) click to toggle source
# File lib/geometry/vector.rb, line 30
def +(vector)
  Vector.new(x + vector.x, y + vector.y)
end
-(vector) click to toggle source
# File lib/geometry/vector.rb, line 34
def -(vector)
  self + (-1) * vector
end
==(vector) click to toggle source
# File lib/geometry/vector.rb, line 3
def ==(vector)
  x === vector.x && y === vector.y
end
coerce(scalar) click to toggle source
# File lib/geometry/vector.rb, line 42
def coerce(scalar)      
  if scalar.is_a?(Numeric)
    [self, scalar]
  else
    raise ArgumentError, "Vector: cannot coerce #{scalar.inspect}"
  end             
end
collinear_with?(vector) click to toggle source
# File lib/geometry/vector.rb, line 26
def collinear_with?(vector)
  cross_product(vector) === 0
end
cross_product(vector) click to toggle source

z-coordinate of cross product (also known as vector product or outer product) It is positive if other vector should be turned counter-clockwise in order to superpose them. It is negetive if other vector should be turned clockwise in order to superpose them. It is zero when vectors are collinear. Remark: x- and y- coordinates of plane vectors cross product are always zero

# File lib/geometry/vector.rb, line 17
def cross_product(vector)
  x * vector.y - y * vector.x
end
modulus() click to toggle source

Modulus of vector. Also known as length, size or norm

# File lib/geometry/vector.rb, line 8
def modulus      
  Math.hypot(x ,y)
end
scalar_product(vector) click to toggle source

Scalar product, also known as inner product or dot product

# File lib/geometry/vector.rb, line 22
def scalar_product(vector)
  x * vector.x + y * vector.y
end