Py5Vector.angle_between()

Py5Vector.angle_between()

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