Module: Vector2d::Projection::ClassMethods
- Included in:
- Vector2d
- Defined in:
- lib/vector2d/projection.rb
Overview
The products taking both vectors as arguments. Extended into Vector2d, so they are called on the class.
Vector2d.dot_product(Vector2d(2, 1), Vector2d(2, 3)) # => 7
Instance Method Summary collapse
-
#cross_product(vector1, vector2) ⇒ Integer, ...
Calculates cross product of two vectors.
-
#dot_product(vector1, vector2) ⇒ Integer, ...
Calculates dot product of two vectors.
Instance Method Details
#cross_product(vector1, vector2) ⇒ Integer, ...
Calculates cross product of two vectors.
v1 = Vector2d(2, 1)
v2 = Vector2d(2, 3)
Vector2d.cross_product(v1, v2) # => 4
35 36 37 |
# File 'lib/vector2d/projection.rb', line 35 def cross_product(vector1, vector2) (vector1.x * vector2.y) - (vector1.y * vector2.x) end |
#dot_product(vector1, vector2) ⇒ Integer, ...
Calculates dot product of two vectors.
v1 = Vector2d(2, 1)
v2 = Vector2d(2, 3)
Vector2d.dot_product(v1, v2) # => 7
22 23 24 |
# File 'lib/vector2d/projection.rb', line 22 def dot_product(vector1, vector2) (vector1.x * vector2.x) + (vector1.y * vector2.y) end |