import Animated from "react-native-reanimated" ; import { atan2 } from "./Math" ; import type { Vector } from "./Vectors" ; const { sub , multiply , add , cos , sin , pow , sqrt } = Animated ; export interface PolarPoint { theta : Animated . Adaptable < number > ; radius : Animated . Adaptable < number > ; } export const canvas2Cartesian = ( { x , y } , center ) => { return { x : sub ( x , center . x ) , y : multiply ( sub ( y , center . y ) , - 1 ) , } ; } ; export const cartesian2Canvas = ( { x , y } , center ) => ( { x : add ( x , center . x ) , y : add ( multiply ( y , - 1 ) , center . y ) , } ) ; export const cartesian2Polar = ( { x , y } ) => { return { theta : atan2 ( y , x ) , radius : sqrt ( add ( pow ( x , 2 ) , pow ( y , 2 ) ) ) , } ; } ; export const polar2Cartesian = ( { theta , radius } ) => ( { x : multiply ( radius , cos ( theta ) ) , y : multiply ( radius , sin ( theta ) ) , } ) ; export const polar2Canvas = ( { theta , radius } , center ) => cartesian2Canvas ( polar2Cartesian ( { theta , radius } ) , center ) ; export const canvas2Polar = ( { x , y } , center ) => cartesian2Polar ( canvas2Cartesian ( { x , y } , center ) ) ;