|
| 1 | +""" |
| 2 | +Compare the ellipse generated with arcs versus a polygonal approximation |
| 3 | +""" |
| 4 | +import numpy as npy |
| 5 | +from matplotlib import patches |
| 6 | +from pylab import figure, show |
| 7 | + |
| 8 | +xcenter, ycenter = 0.38, 0.52 |
| 9 | +#xcenter, ycenter = 0., 0. |
| 10 | +width, height = 1e-1, 3e-1 |
| 11 | +angle = -30 |
| 12 | + |
| 13 | +theta = npy.arange(0.0, 360.0, 1.0)*npy.pi/180.0 |
| 14 | +x = width/2. * npy.cos(theta) |
| 15 | +y = height/2. * npy.sin(theta) |
| 16 | + |
| 17 | +rtheta = angle*npy.pi/180. |
| 18 | +R = npy.array([ |
| 19 | + [npy.cos(rtheta), -npy.sin(rtheta)], |
| 20 | + [npy.sin(rtheta), npy.cos(rtheta)], |
| 21 | + ]) |
| 22 | + |
| 23 | + |
| 24 | +x, y = npy.dot(R, npy.array([x, y])) |
| 25 | +x += xcenter |
| 26 | +y += ycenter |
| 27 | + |
| 28 | +fig = figure() |
| 29 | +ax = fig.add_subplot(211, aspect='auto') |
| 30 | +ax.fill(x, y, alpha=0.2, facecolor='yellow') |
| 31 | + |
| 32 | +e1 = patches.Ellipse((xcenter, ycenter), width, height, |
| 33 | + angle=angle, linewidth=2, fill=False) |
| 34 | + |
| 35 | +ax.add_artist(e1) |
| 36 | + |
| 37 | +ax = fig.add_subplot(212, aspect='equal') |
| 38 | +ax.fill(x, y, alpha=0.2, facecolor='yellow') |
| 39 | +e2 = patches.Ellipse((xcenter, ycenter), width, height, |
| 40 | + angle=angle, linewidth=2, fill=False) |
| 41 | + |
| 42 | + |
| 43 | +ax.add_artist(e2) |
| 44 | +ax.autoscale_view() |
| 45 | + |
| 46 | + |
| 47 | +ax.set_xlim(0.2, .5) |
| 48 | +ax.set_ylim(0.3, 0.7) |
| 49 | + |
| 50 | +#fig.savefig('ellipse_compare.png') |
| 51 | +#fig.savefig('ellipse_compare.ps') |
| 52 | + |
| 53 | +show() |
0 commit comments