Py5Vector.dot()

Calculate the dot product between two vectors.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import numpy as np

v1 = py5.Py5Vector(0, 40)
v2 = py5.Py5Vector(10, 10)
angle = v1.angle_between(v2)
print(f'angle = {round(py5.degrees(angle))}°')
# angle = 45°
angle = np.arccos(v1.norm.dot(v2.norm))
print(f'angle = {round(py5.degrees(angle))}°')
# angle = 45°
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
def setup():
    global v1
    v1 = py5.Py5Vector(40, 0)


def draw():
    py5.background(255)
    py5.translate(py5.width / 2, py5.height / 2)
    py5.stroke(0)
    py5.stroke_weight(4)
    py5.line(0, 0, v1.x, v1.y)
    vm = py5.Py5Vector(py5.mouse_x - py5.width / 2, py5.mouse_y - py5.height / 2)
    py5.stroke_weight(2)
    py5.stroke(0, 255, 0)
    py5.line(0, 0, vm.x, vm.y)
    v2 = v1.norm.dot(vm) * v1.norm
    py5.stroke(255, 0, 0)
    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