All files / src/utils angle.ts

1 2 3 4 5 6 7 8 9 10 11 12 13 14                      7x 6x  
import { Point } from '../types';
import { radiansToDegrees } from './radians-to-degrees';
import { zeroPoint } from './inc';
 
/*
  Angle between points
 
  @param [object]: X and Y coordinates of from point
  @param [object]: X and Y coordinates of to point
  @return [radian]: Angle between the two points in radians
*/
export const angle = (a: Point, b: Point = zeroPoint) =>
  radiansToDegrees(Math.atan2(b.y - a.y, b.x - a.x));