Py5Vector.angle_between()#

Measure the angle 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°
example picture for angle_between()
 1def setup():
 2    py5.translate(20, 20)
 3    v1 = py5.Py5Vector(60, 0)
 4    v2 = py5.Py5Vector(45, 45)
 5    py5.line(0, 0, v1.x, v1.y)
 6    py5.line(0, 0, v2.x, v2.y)
 7    angle_radians = v1.angle_between(v2)
 8    py5.no_fill()
 9    py5.arc(0, 0, 40, 40, 0, angle_radians)
10    py5.fill(0)
11    py5.text(f'{round(py5.degrees(angle_radians))}°', 25, 15)

Description#

Measure the angle between two vectors.

Syntax#

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

Parameters#

  • other: Union[Py5Vector, np.ndarray] - vector to measure angle between

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