mag() \ Language (API) \ Processing 1.0
Author: Casey Reas & Ben Fry
Description: Processing is an electronic sketchbook for developing ideas. It is a context for learning fundamentals of computer programming within the context of the electronic arts.
Keywords: Processing, Processing, Interactive Media, Electronic Arts, Programming, Java, Ben Fry, Casey Reas

Reference for Processing version 1.5. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name | ### mag()
Examples |
    float x1 = 20;
    float x2 = 80;
    float y1 = 30;
    float y2 = 70;

    line(0, 0, x1, y1);
    println(mag(x1, y1));  // Prints 36.05551
    line(0, 0, x2, y1);
    println(mag(x2, y1));  // Prints 85.44004
    line(0, 0, x1, y2);
    println(mag(x1, y2));  // Prints 72.8011
    line(0, 0, x2, y2);
    println(mag(x2, y2));  // Prints 106.30146
Description | 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 coordinate (0,0) to its (x,y) value. Therefore, mag() is a shortcut for writing "dist(0, 0, x, y)".
Syntax |
    mag(a, b)
    mag(a, b, c)
Parameters |
a | float or int: first value
b | float or int: second value
c | float or int: third value
Returns | float
Usage | Web & Application
Related | dist()

Updated on August 30, 2010 04:29:39pm EDT