Py5Vector.dot()#

Calculate the dot product between two vectors.

Examples#

 1import numpy as np
 2
 3v1 = py5.Py5Vector(0, 40)
 4v2 = py5.Py5Vector(10, 10)
 5angle = v1.angle_between(v2)
 6print(f'angle = {round(py5.degrees(angle))}°')
 7# angle = 45°
 8angle = np.arccos(v1.norm.dot(v2.norm))
 9print(f'angle = {round(py5.degrees(angle))}°')
10# angle = 45°
 1def setup():
 2    global v1
 3    v1 = py5.Py5Vector(40, 0)
 4
 5
 6def draw():
 7    py5.background(255)
 8    py5.translate(py5.width / 2, py5.height / 2)
 9    py5.stroke(0)
10    py5.stroke_weight(4)
11    py5.line(0, 0, v1.x, v1.y)
12    vm = py5.Py5Vector(py5.mouse_x - py5.width / 2, py5.mouse_y - py5.height / 2)
13    py5.stroke_weight(2)
14    py5.stroke(0, 255, 0)
15    py5.line(0, 0, vm.x, vm.y)
16    v2 = v1.norm.dot(vm) * v1.norm
17    py5.stroke(255, 0, 0)
18    py5.line(0, 0, v2.x, v2.y)

Description#

Calculate the dot product between two vectors.

Syntax#

dot(other: Union[Py5Vector, np.ndarray]) -> Union[float, np.ndarray[np.floating]]

Parameters#

  • other: Union[Py5Vector, np.ndarray] - vector to calculate the dot product with

Updated on February 26, 2022 13:22:44pm UTC