The mag() function in p5.js is used to find the magnitude or length of a vector. As a vector does not have a starting position, the magnitude is calculated from position (0, 0) to (x, y). It is equivalent to using dist(0, 0, x, y).
mag( a, b )
Parameters: This function accept two parameters as mentioned above and described below:
- a: It is a number which denotes the first value, that is the “x” coordinate of the vector.
- b: It is a number which denotes the second value, that is the “y” coordinate of the vector.
Return Value: It returns a number with the magnitude of the vector.
Below examples illustrate the mag() function in p5.js:
Online editor: https://editor.p5js.org/
- How to get the function name inside a function in PHP ?
- PHP | next() Function
- PHP | Ds\Set first() Function
- p5.js | box() Function
- D3.js | d3.map.set() Function
- D3.js | d3.sum() function
- PHP | Ds\Set last() Function
- D3.js | d3.mean() function
- PHP | Ds\Set contains() Function
- D3.js | d3.set.has() Function
- PHP | exp() Function
- PHP | dir() Function
- p5.js | arc() Function
- CSS | url() Function
- PHP | pi( ) Function
- PHP | Ds\Map get() Function
- PHP | Ds\Map xor() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.