Skip to content

Instantly share code, notes, and snippets.

@smathot
Last active February 22, 2016 11:24
Show Gist options
  • Save smathot/aaaa03e6c6fac8198a20 to your computer and use it in GitHub Desktop.
Save smathot/aaaa03e6c6fac8198a20 to your computer and use it in GitHub Desktop.
import numpy as np
def uvtoxy(u, v, Bu=1.4, A=3., Bv=1.8):
u = np.array(u, dtype=float)
v = np.array(v, dtype=float)
R = A * np.sqrt(np.exp(2*u/ Bu) - (2*np.exp(u/Bu)*np.cos(v/Bv)) + 1)
phi = np.arctan2(
(np.exp(u/Bu)*np.sin(v/Bv)),
((np.exp(u/Bu)*np.cos(v/Bv))-1)
)
x = R*np.cos(phi)
y = R*np.sin(phi)
return x, y
def xytouv(x, y, Bu=1.4, A=3., Bv=1.8):
x = np.array(x, dtype=float)
y = np.array(y, dtype=float)
R = np.sqrt(x**2 + y**2)
phi = np.arctan2(y, x)
u = Bu*np.log(
np.sqrt(R**2 + A**2 + 2*A*R*np.cos(phi))) \
- Bu*np.log(A)
v = Bv*np.arctan2(
(R*np.sin(phi)),
R*np.cos(phi)+A
)
return u, v
def unit_test():
x1 = np.random.random(1000)*20-10
y1 = np.random.random(1000)*20-10
u, v = xytouv(x1, y1)
x2, y2 = uvtoxy(u, v)
assert(np.sum(np.abs(x1-x2)) < .0001)
assert(np.sum(np.abs(y1-y2)) < .0001)
unit_test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment