src/inputjs/get-angle.js
raw| 1 | import { PROPS_XY } from './input-consts'; |
| 2 | |
| 3 | /** |
| 4 | * @private |
| 5 | * calculate the angle between two coordinates |
| 6 | * @param {Object} p1 |
| 7 | * @param {Object} p2 |
| 8 | * @param {Array} [props] containing x and y keys |
| 9 | * @return {Number} angle |
| 10 | */ |
| 11 | export default function getAngle(p1, p2, props) { |
| 12 | if (!props) { |
| 13 | props = PROPS_XY; |
| 14 | } |
| 15 | let x = p2[props[0]] - p1[props[0]]; |
| 16 | let y = p2[props[1]] - p1[props[1]]; |
| 17 | return Math.atan2(y, x) * 180 / Math.PI; |
| 18 | } |