Created
July 14, 2017 10:27
-
-
Save du5rte/d165ee796fb0d1b98624a2c35a96df49 to your computer and use it in GitHub Desktop.
Distance between two Points(x,y) Pythagorean Theorem
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
function distanceBetweenPoints(p1, p2) { | |
// http://www.mathwarehouse.com/algebra/distance_formula/index.php | |
// https://stackoverflow.com/questions/20916953/get-distance-between-two-points-in-canvas | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot | |
// or | |
// Math.sqr((p2.x - p1.x) + (p2.y - p1.y)) | |
return Math.hypot(p2.x - p1.x, p2.y - p1.y) | |
} | |
console.log( | |
distance(P1, P2) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment