Module: Vector2d::Calculations::ClassMethods

Includes:
Contracts
Included in:
Vector2d
Defined in:
lib/vector2d/calculations.rb

Instance Method Summary collapse

Instance Method Details

#angle_between(vector1, vector2) ⇒ Object



39
40
41
42
43
# File 'lib/vector2d/calculations.rb', line 39

def angle_between(vector1, vector2)
  one = vector1.normalized? ? vector1 : vector1.normalize
  two = vector2.normalized? ? vector2 : vector2.normalize
  Math.acos(self.dot_product(one, two))
end

#cross_product(vector1, vector2) ⇒ Object



17
18
19
# File 'lib/vector2d/calculations.rb', line 17

def cross_product(vector1, vector2)
  vector1.x * vector2.y - vector1.y * vector2.x
end

#dot_product(vector1, vector2) ⇒ Object



28
29
30
# File 'lib/vector2d/calculations.rb', line 28

def dot_product(vector1, vector2)
  vector1.x * vector2.x + vector1.y * vector2.y
end