export class Geometry { static distance ( p1 , p2 ) { return Math . sqrt ( ( p1 . x - p2 . x ) ** 2 + ( p1 . y - p2 . y ) ** 2 ) ; } static norm ( vector ) { return Math . sqrt ( vector . x ** 2 + vector . y ** 2 ) ; } static normalize ( vector ) { const norm = Geometry . norm ( vector ) ; return { x : vector . x / norm , y : vector . y / norm } ; } static angle ( u , v ) { return Math . atan2 ( u . y , u . x ) - Math . atan2 ( v . y , v . x ) ; } static polar ( center , distance , angle ) { return { x : center . x + distance * Math . cos ( angle ) , y : center . y + distance * Math . sin ( angle ) } ; } static middle ( p1 , p2 ) { return { x : ( p1 . x + p2 . x ) / 2 , y : ( p1 . y + p2 . y ) / 2 } ; } static numberRound ( x ) { return Math . round ( 10 * x ) / 10 ; } param point param origin param direction returns static getNewCoordinates ( point , origin , direction ) { const directionVector = { x : direction . x - origin . x , y : direction . y - origin . y } ; const distance = Geometry . distance ( origin , point ) ; const OP = { x : point . x - origin . x , y : point . y - origin . y } ; const angle = Geometry . angle ( OP , directionVector ) ; return { x : distance * Math . cos ( angle ) , y : distance * Math . sin ( angle ) } ; } }