-
-
Save dead23angel/7b3b4e2d1bb33015159efd02a2aeb1c6 to your computer and use it in GitHub Desktop.
Javascript Math: get the distance between two points.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* return the distance between two points. | |
* | |
* @param {number} x1 x position of first point | |
* @param {number} y1 y position of first point | |
* @param {number} x2 x position of second point | |
* @param {number} y2 y position of second point | |
* @return {number} distance between given points | |
*/ | |
Math.getDistance = function( x1, y1, x2, y2 ) { | |
var xs = x2 - x1, | |
ys = y2 - y1; | |
xs *= xs; | |
ys *= ys; | |
return Math.sqrt( xs + ys ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment