Last active
November 21, 2025 17:08
-
-
Save nicksheffield/493f82af9f0a466d4e1339a0f7a27cc0 to your computer and use it in GitHub Desktop.
Angle Tools
This file contains hidden or 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
| const angleTools = { | |
| /** | |
| * Calculate the angle between two points in degrees. | |
| */ | |
| angle: (a: { x: number; y: number }, b: { x: number; y: number }) => { | |
| return (Math.atan2(b.y - a.y, b.x - a.x) / Math.PI) * 180 | |
| }, | |
| /** | |
| * Calculate the distance between two points in a straight line in pixels. | |
| */ | |
| dist: (a: { x: number; y: number }, b: { x: number; y: number }) => { | |
| return Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) | |
| }, | |
| /** | |
| * Calculate the x and y changes needed to move in a straight line on a specific angle | |
| */ | |
| step: (angle: number, distance: number) => { | |
| return { | |
| x: distance * Math.cos((angle * Math.PI) / 180), | |
| y: distance * Math.sin((angle * Math.PI) / 180), | |
| } | |
| }, | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment