Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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