Skip to content

Instantly share code, notes, and snippets.

@kaskichandrakant
Created March 22, 2019 10:40
Show Gist options
  • Save kaskichandrakant/0a7f0a9e475da5adedf119b536f98924 to your computer and use it in GitHub Desktop.
Save kaskichandrakant/0a7f0a9e475da5adedf119b536f98924 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
field = np.zeros((500,500))
center = [25, 25]
radius = 20
x = np.arange(0, radius, 0.0001)
abs_y = (radius**2 - x**2)**0.5
y1 = np.floor((-1*abs_y + center[1])*10).astype(np.int_)
y2 = np.floor((abs_y + center[1])*10).astype(np.int_)
x1 = np.floor((-1*x + center[0])*10).astype(np.int_)
x2 = np.floor((x + center[0])*10).astype(np.int_)
field[x1, y1] = 1
field[x2, y1] = 1
field[x1, y2] = 1
field[x2, y2] = 1
plt.imshow(field)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment