Are there functions for conversion between different coordinate systems?
For example, Matlab has [rho,phi] = cart2pol(x,y) for conversion from cartesian
The existing answers can be simplified:
from numpy import exp, abs, angle
def polar2z(r,theta):
return r * exp( 1j * theta )
def z2polar(z):
return ( abs(z), angle(z) )
Or even:
polar2z = lambda r,θ: r * exp( 1j * θ )
z2polar = lambda z: ( abs(z), angle(z) )
Note these also work on arrays!
rS, thetaS = z2polar( [z1,z2,z3] )
zS = polar2z( rS, thetaS )