Reference mag()

mag()

Calculates the magnitude, or length, of a vector.

A vector can be thought of in different ways. In one view, a vector is a point in space. The vector's components, x and y, are the point's coordinates (x, y). A vector's magnitude is the distance from the origin (0, 0) to (x, y). mag(x, y) is a shortcut for calling dist(0, 0, x, y).

A vector can also be thought of as an arrow pointing in space. This view is helpful for programming motion. See p5.Vector for more details.

Use p5.Vector.mag() to calculate the magnitude of a p5.Vector object.

Examples

Syntax

mag(x, y)

Parameters

x

first component.

y

second component.

Notice any errors or typos? Please let us know. Please feel free to edit src/math/calculation.js and open a pull request!

Related References