Last active
May 15, 2022 00:02
-
-
Save akinnee/99435ef04ab5a43eff20e907ec08c7c1 to your computer and use it in GitHub Desktop.
typescript 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
type Vector2 = { | |
x: number; | |
y: number; | |
}; | |
export const getDistance = (p1: Vector2, p2: Vector2) => { | |
const { x: x1, y: y1 } = p1; | |
const { x: x2, y: y2 } = p2; | |
const y = x2 - x1; | |
const x = y2 - y1; | |
return Math.sqrt(x * x + y * y); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment