def disk eps np empty np linspace -1 np meshgrid phi np pi np pi rho t

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def disk(n, eps):
R = np.empty( (n, n) )
t = np.linspace(-1, 1, n)
y, x = np.meshgrid(t, t)
phi = x*np.pi/2 + y*np.pi/2
rho, theta = np.cos(phi), np.sin(phi)
for i in range(n):
for j in range(n):
R[i, j] = 1-x[i, j]**2-y[i, j]**2
if( R[i, j] > 0 or np.abs( R[i, j] ) < eps ):
rho[i, j], theta[i, j] = x[i, j], y[i, j]
coord = np.c_[ rho.reshape(n**2, 1), theta.reshape(n**2, 1) ]
return rho, theta, coord