torus-distortion.html
001| """Distortion from flat in a normally embedded Torus."""
002|
003| from sys import argv
004| from os import path
005| from math import sqrt, pi,tau, sin,cos, radians
006| import matplotlib.pyplot as plt
007| from matplotlib.ticker import NullLocator, MultipleLocator, NullFormatter, FormatStrFormatter
008| from goodies import intervals
009|
010| BasePath = r'C:\CJS\prj\Python\blog\proj'
011| ImgsPath = path.join(BasePath,'img')
012| Filename = 'torus-distortion.png'
013|
014|
015| r = 0.333333
016| xsteps = 10
017| ysteps = 30
018|
019| xmin,xmax = -18.0, +18.0
020| ymin,ymax = -1.0, +1.0
021|
022|
023| def make_chart (thetas, phis, ys, xts0,xts1, xss0):
024| fig, ax = plt.subplots()
025| fig.suptitle('Torus Earth Grid Distortion (AR=%.2f)' % (1/r))
026|
027| ax.set_xlabel('Theta')
028| ax.set_xlim(xmin-2,xmax+2)
029| ax.set_xticks(xts0, minor=False)
030| ax.set_xticks(xts1, minor=True)
031| ax.set_xticklabels(xss0)
032|
033|
034|
035|
036|
037| for tick in ax.xaxis.get_major_ticks():
038| tick.label1.set_rotation('vertical')
039| tick.label1.set_size(9)
040|
041| ax.set_ylabel('Phi')
042| ax.set_ylim(ymin,ymax)
043| ax.yaxis.set_major_locator(MultipleLocator(0.5))
044| ax.yaxis.set_minor_locator(MultipleLocator(0.1))
045| ax.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
046|
047| ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
048| ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
049| ax.tick_params(which='major', axis='both', direction='out', color='#000000')
050| ax.tick_params(which='minor', axis='both', direction='out', color='#000000')
051|
052|
053| for ix,theta in enumerate(thetas):
054| xs = [theta+(theta*(r*cos(phi))) for phi in phis]
055| ax.plot(xs,ys, c='#ff0000', lw=2.0, label=('%.2f'%theta), zorder=(11+ix), alpha=0.8)
056|
057|
058|
059|
060| fig.set_figwidth(8.0)
061| fig.set_figheight(4.0)
062| fig.subplots_adjust(left=0.08, right=0.98, bottom=0.17, top=0.93)
063|
064| fn = path.join(ImgsPath, Filename)
065| fig.savefig(fn)
066| print('wrote: %s' % fn)
067| print()
068|
069|
070| def main ():
071| gprint = lambda g:('(%d) %s\n' % (len(g),g))
072|
073| thetas = [xmin+(2*n) for n in range(int((xmax-xmin)/2)+1)]
074| print(gprint(thetas))
075|
076| ys = [(n-ysteps)/ysteps for n in range((2*ysteps)+1)]
077|
078|
079| phis = [pi*(1.0-abs(y)) for y in ys]
080|
081|
082| xts0 = list(intervals(xmin, xmax, 4.5))
083| xss0 = ['%+d'%(xt*10) for xt in xts0]
084| xts1 = list(intervals(xmin, xmax, 0.5))
085|
086| make_chart(thetas, phis, ys, xts0,xts1, xss0)
087|
088|
089| if __name__ == '__main__':
090| print(argv[0])
091| print()
092| main()
093| print()
094|
095| '''eof'''
096|