Skip to content

Instantly share code, notes, and snippets.

@du5rte
Created July 14, 2017 10:27
Show Gist options
  • Save du5rte/d165ee796fb0d1b98624a2c35a96df49 to your computer and use it in GitHub Desktop.
Save du5rte/d165ee796fb0d1b98624a2c35a96df49 to your computer and use it in GitHub Desktop.
Distance between two Points(x,y) Pythagorean Theorem
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