mag()

本参考资料用于Processing 3.0+。 如果你使用的是前一版本,请在使用软件帮助菜单内的参考资料。. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

名称

mag()

示例
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" 
描述 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).
语法
mag(a, b) mag(a, b, c)
参数
a float: first value
b float: second value
c float: third value
返回值 float
相关 dist()

Updated on October 2, 2018 05:02:06pm EDT

mag()