Py5Vector.normalize()

Py5Vector.normalize()

Normalize the vector by setting the vector’s magnitude to 1.0.

Examples

1
2
3
4
5
6
7
8
9
v1 = py5.Py5Vector(3, 4)

print("magnitude =", v1.mag)
# magnitude = 5.0

v1.normalize()

print("magnitude =", v1.mag)
# magnitude = 1.0

Description

Normalize the vector by setting the vector’s magnitude to 1.0. This method cannot be used on a vector of zeros, because a vector of zeros cannot be normalized.

Syntax

normalize() -> Py5Vector

Updated on January 16, 2022 16:51:21pm UTC