[−][src]Static p5_sys::global::mag
pub static mag: MagInternalType
Calculates the magnitude (or length) of a vector. A vector is a direction in space commonly used in computer graphics and linear algebra. Because it has no "start" position, the magnitude of a vector can be thought of as the distance from the coordinate 0,0 to its x,y value. Therefore, mag() is a shortcut for writing dist(0, 0, x, y).
Examples
function setup() { let x1 = 20; let x2 = 80; let y1 = 30; let y2 = 70; line(0, 0, x1, y1); print(mag(x1, y1)); // Prints "36.05551275463989" line(0, 0, x2, y1); print(mag(x2, y1)); // Prints "85.44003745317531" line(0, 0, x1, y2); print(mag(x1, y2)); // Prints "72.80109889280519" line(0, 0, x2, y2); print(mag(x2, y2)); // Prints "106.3014581273465" }
Parameters
a
first value
b
second value