import numpy as np
import matplotlib.pyplot as plt1
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, AutoMinorLocator)
%matplotlib inline
fig, ax1a = plt1.subplots(1, figsize=(16, 8))
ax1a.clear()
#Itterations step and circumference
rationals=1000
for p in range(rationals):
#n=p/(rationals/100)
n=p/50
#counter
k=np.arange(n)
#Determine angle and linesegment lenght
angle=k*2*np.pi/(n+1) +np.pi/(n+1)
#angle=k*2*np.pi/(n+1)
#length=1/(1+n)
length=2*np.sqrt(np.abs(np.tan(np.pi/(n+1))/(n+1)))
#Calculate each individual vector
y=length*np.cos(angle)
x=length*np.sin(angle)
#Cumulative sum vector
xc=np.cumsum(x)
yc=np.cumsum(y)
#Add coordinate 0,0 to start and end.
xc=np.append(xc,0)
yc=np.append(yc,0)
xc=np.concatenate(([0],xc),axis=0)
yc=np.concatenate(([0],yc),axis=0)
#Plot points or circumference.
#ax1a.plot(xc,yc, marker='.', color='black', linestyle='', markersize=1,fillstyle='full',linewidth=0,alpha=0.25)
#Plot all Polygon outline
ax1a.plot(xc,yc, marker='.', color='black', linestyle='-', linewidth=0.05, markersize=0,zorder=rationals-int(n)-1)
#Plot Polygon outline inter number of sides
if n.is_integer()==True and n<20:
ax1a.plot(xc,yc, marker='.', color='red', linestyle='-', linewidth=0.25, markersize=0,zorder=rationals+int(n)+1,alpha=1)
ax1a.plot(xc,yc, marker='o', color='red', linestyle='', markersize=1,zorder=rationals+int(n),alpha=1)
#Plot Circle outline last polygon
ax1a.plot(xc,yc, marker='.', color='blue', linestyle='-', linewidth=1.5, markersize=0, label='Circle', zorder=rationals,alpha=1)
ax1a.plot(yc,xc, marker='.', color='red', linestyle='', markersize=1,fillstyle='full',linewidth=0,alpha=0.25, zorder=-1000,label='Discrete n<20 (n-gon)')
ax1a.plot(xc,yc, marker='.', color='black', linestyle='', markersize=1,fillstyle='full',linewidth=0,alpha=0.25,zorder=-1000, label='Continuous n')
ax1a.set_xlabel('$x$',fontsize=20)
ax1a.set_ylabel('$y$',fontsize=20)
ax1a.set_title('Circle Creation, Area=1',fontsize=15)
ax1a.legend(loc='lower right',fontsize=12,markerscale=20,frameon=False)
ax1a.grid(b=True, which='major', color='#666666', linestyle='-', zorder=0)
ax1a.axes.set_ylim([-1,1])
ax1a.axes.set_xlim([0,4])
ax1a.xaxis.set_major_locator(MultipleLocator(0.2))
ax1a.yaxis.set_major_locator(MultipleLocator(0.2))
plt1.gca().set_aspect('equal', adjustable='box')
plt1.savefig('Circle Plot, Polygons Area=1', dpi=300, bbox_inches='tight')