(x: number, y: number, a: number, px: number, py: number)
| 6 | export const rad = (deg: number) => deg * (Math.PI / 180); |
| 7 | |
| 8 | export const rotate = (x: number, y: number, a: number, px: number, py: number) => { |
| 9 | const c = Math.cos(rad(a)); |
| 10 | const s = Math.sin(rad(a)); |
| 11 | |
| 12 | x -= px; |
| 13 | y -= py; |
| 14 | |
| 15 | const newX = x * c - y * s; |
| 16 | const newY = y * c + x * s; |
| 17 | |
| 18 | return { y: newX + px, x: newY + py }; |
| 19 | }; |
| 20 | |
| 21 | export const calculateDistance = (x1: number, y1: number, x2: number, y2: number) => { |
| 22 | return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)); |