Skip to content

Instantly share code, notes, and snippets.

@timohausmann
Created February 21, 2013 08:43
Show Gist options
  • Save timohausmann/5003280 to your computer and use it in GitHub Desktop.
Save timohausmann/5003280 to your computer and use it in GitHub Desktop.
Javascript Math: get the distance between two points.
/**
* 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 );
};
@kidofcubes
Copy link

thx gonna use

@abrarrahman
Copy link

thanks

@Heunsig
Copy link

Heunsig commented Feb 12, 2023

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment