|
| 1 | + |
| 2 | +# This example can be boiled down to a more simplistic example |
| 3 | +# to show the problem, but bu including the upper and lower |
| 4 | +# bound ellipses, it demonstrates how significant this error |
| 5 | +# is to our plots. |
| 6 | + |
| 7 | +import math |
| 8 | +from pylab import * |
| 9 | +from matplotlib.patches import Ellipse |
| 10 | + |
| 11 | +# given a point x, y |
| 12 | +x = 2692.440 |
| 13 | +y = 6720.850 |
| 14 | + |
| 15 | +# get is the radius of a circle through this point |
| 16 | +r = math.sqrt( x*x+y*y ) |
| 17 | + |
| 18 | +# show some comparative circles |
| 19 | +delta = 6 |
| 20 | + |
| 21 | + |
| 22 | +################################################## |
| 23 | +def custom_ellipse( ax, x, y, major, minor, theta, numpoints = 750, **kwargs ): |
| 24 | + xs = [] |
| 25 | + ys = [] |
| 26 | + incr = 2.0*math.pi / numpoints |
| 27 | + incrTheta = 0.0 |
| 28 | + while incrTheta <= (2.0*math.pi): |
| 29 | + a = major * math.cos( incrTheta ) |
| 30 | + b = minor * math.sin( incrTheta ) |
| 31 | + l = math.sqrt( ( a**2 ) + ( b**2 ) ) |
| 32 | + phi = math.atan2( b, a ) |
| 33 | + incrTheta += incr |
| 34 | + |
| 35 | + xs.append( x + ( l * math.cos( theta + phi ) ) ) |
| 36 | + ys.append( y + ( l * math.sin( theta + phi ) ) ) |
| 37 | + # end while |
| 38 | + |
| 39 | + incrTheta = 2.0*math.pi |
| 40 | + a = major * math.cos( incrTheta ) |
| 41 | + b = minor * math.sin( incrTheta ) |
| 42 | + l = sqrt( ( a**2 ) + ( b**2 ) ) |
| 43 | + phi = math.atan2( b, a ) |
| 44 | + xs.append( x + ( l * math.cos( theta + phi ) ) ) |
| 45 | + ys.append( y + ( l * math.sin( theta + phi ) ) ) |
| 46 | + |
| 47 | + ellipseLine = ax.plot( xs, ys, **kwargs ) |
| 48 | + |
| 49 | + |
| 50 | +################################################## |
| 51 | +# make the axes |
| 52 | +ax = subplot( 211, aspect='equal' ) |
| 53 | +ax.set_aspect( 'equal', 'datalim' ) |
| 54 | + |
| 55 | +# make the lower-bound ellipse |
| 56 | +diam = (r - delta) * 2.0 |
| 57 | +lower_ellipse = Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkgreen" ) |
| 58 | +ax.add_patch( lower_ellipse ) |
| 59 | + |
| 60 | +# make the target ellipse |
| 61 | +diam = r * 2.0 |
| 62 | +target_ellipse = Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkred" ) |
| 63 | +ax.add_patch( target_ellipse ) |
| 64 | + |
| 65 | +# make the upper-bound ellipse |
| 66 | +diam = (r + delta) * 2.0 |
| 67 | +upper_ellipse = Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkblue" ) |
| 68 | +ax.add_patch( upper_ellipse ) |
| 69 | + |
| 70 | +# make the target |
| 71 | +diam = delta * 2.0 |
| 72 | +target = Ellipse( (x, y), diam, diam, 0.0, fill=False, edgecolor="#DD1208" ) |
| 73 | +ax.add_patch( target ) |
| 74 | + |
| 75 | +# give it a big marker |
| 76 | +ax.plot( [x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10 ) |
| 77 | + |
| 78 | +################################################## |
| 79 | +# now lets do the same thing again using a custom ellipse function |
| 80 | + |
| 81 | +# make the axes |
| 82 | +ax = subplot( 212, aspect='equal', sharex=ax, sharey=ax ) |
| 83 | +ax.set_aspect( 'equal', 'datalim' ) |
| 84 | + |
| 85 | +# make the lower-bound ellipse |
| 86 | +custom_ellipse( ax, 0.0, 0.0, r-delta, r-delta, 0.0, color="darkgreen" ) |
| 87 | + |
| 88 | +# make the target ellipse |
| 89 | +custom_ellipse( ax, 0.0, 0.0, r, r, 0.0, color="darkred" ) |
| 90 | + |
| 91 | +# make the upper-bound ellipse |
| 92 | +custom_ellipse( ax, 0.0, 0.0, r+delta, r+delta, 0.0, color="darkblue" ) |
| 93 | + |
| 94 | +# make the target |
| 95 | +custom_ellipse( ax, x, y, delta, delta, 0.0, color="#BB1208" ) |
| 96 | + |
| 97 | +# give it a big marker |
| 98 | +ax.plot( [x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10 ) |
| 99 | + |
| 100 | +################################################## |
| 101 | +# lets zoom in to see the area of interest |
| 102 | + |
| 103 | +ax.set_xlim(2650, 2735) |
| 104 | +ax.set_ylim(6705, 6735) |
| 105 | +show() |
| 106 | + |
| 107 | +savefig("ellipse") |
0 commit comments