import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display,Math
display(Math('(y - k)^2 + (x - h)^2 = r^2'))
h = 2
k = -3
r = 3
axlim = r + np.max((abs(h),abs(k)))
x = np.linspace(-axlim,axlim,100)
X,Y = np.meshgrid(x,x)
plt.imshow(X)
plt.imshow(Y)
Fxy = (X-h)**2 + (Y-k)**2 - r**2 # equals to 0
plt.imshow(Fxy)
plt.contour(Fxy)
plt.contour(Fxy,0)
plt.contour(X,Y,Fxy,0)
plt.plot([-axlim,axlim],[0,0],'k--')
plt.plot([0,0],[-axlim,axlim],'k--')
plt.plot(h,k,'go')
plt.gca().set_aspect('equal')
plt.show()
Exercise
h = [-1.5,1.5]
x = np.linspace(-5,5,100)
X,Y = np.meshgrid(x,x)
for r in np.linspace(.5,3,15):
for hi in h:
Fxy = (X-hi)**2 + (Y-0)**2 - r**2
plt.contour(X,Y,Fxy,0,colors=[[r/3,r/3,r/3]])
plt.axis('off')
plt.gca().set_aspect('equal')
plt.plot(h,[0,0],'k',linewidth=3)
plt.show()