JSFiddle - React, Tailwind, and code Playground

by clauswilke

JavaScript

let toPolar = (x, y) => ({
	r: Math.sqrt(x*x + y*y),
  a: Math.atan2(y, x)
})

let toCartesian = (r, a) => ({
	x: r * Math.cos(a),
  y: r * Math.sin(a)
})

let {r, a} = toPolar(2, -5)
console.log(toCartesian(r, a))