2

I would like to use the two functions pol2cart and cart2pol present in MATLAB.

Are there any equivalent Python functions? Or if we can define the functions?

For instance, I tried using cmath.polar function but it only accepts one argument whereas I have 2 arguments to be passed inside polar and rec function.

I have tried using this function for cart2pol:

def cart2pol(x, y):
    theta = atan2(y, x)
    rho = sqrt(x**2 + y**2)
    return (theta, rho)

Thank you

Okay Lolz
  • 413
  • 1
  • 9
  • 17
  • 1
    So what's your problem. You already answered your question. Define it by your own like you did. – miindlek Aug 01 '14 at 10:54
  • 1
    Just to clarify, cmath is for complex numbers. You could hack it to do what you want with something like `r, phi = cmath.polar(complex(x, y))`. – Pokey McPokerson Aug 01 '14 at 11:52
  • 1
    Possible duplicate of [Python conversion between coordinates](http://stackoverflow.com/questions/20924085/python-conversion-between-coordinates) – abcd Jun 19 '16 at 22:47

0 Answers0