Skip to content

Instantly share code, notes, and snippets.

@akinnee
Last active May 15, 2022 00:02
Show Gist options
  • Save akinnee/99435ef04ab5a43eff20e907ec08c7c1 to your computer and use it in GitHub Desktop.
Save akinnee/99435ef04ab5a43eff20e907ec08c7c1 to your computer and use it in GitHub Desktop.
typescript distance between two points
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