Created
September 15, 2018 04:43
-
-
Save bhachauk/7fc9aee06acc4d35a2d2cc6a36d0136d to your computer and use it in GitHub Desktop.
spherical <--> cart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sph2cart1(r, th, phi): | |
x = r * cos(phi) * sin(th) | |
y = r * sin(phi) * sin(th) | |
z = r * cos(th) | |
return x, y, z | |
def cart2sph1(x, y, z): | |
r = sqrt(x**2 + y**2 + z**2) + 1e-15 | |
th = acos(z / r) | |
phi = atan2(y, x) | |
return r, th, phi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment