From: James E. <jre...@ea...> - 2007-12-08 00:03:12
|
=0A= # This example can be boiled down to a more simplistic example=0A= # to show the problem, but bu including the upper and lower=0A= # bound ellipses, it demonstrates how significant this error=0A= # is to our plots.=0A= =0A= import math=0A= from pylab import *=0A= from matplotlib.patches import Ellipse=0A= =0A= # given a point x, y=0A= x =3D 2692.440=0A= y =3D 6720.850=0A= =0A= # get is the radius of a circle through this point=0A= r =3D math.sqrt( x*x+y*y )=0A= =0A= # show some comparative circles=0A= delta =3D 6=0A= =0A= =0A= ##################################################=0A= def custom_ellipse( ax, x, y, major, minor, theta, numpoints =3D 750, = **kwargs ):=0A= xs =3D []=0A= ys =3D []=0A= incr =3D 2.0*math.pi / numpoints=0A= incrTheta =3D 0.0=0A= while incrTheta <=3D (2.0*math.pi):=0A= a =3D major * math.cos( incrTheta )=0A= b =3D minor * math.sin( incrTheta )=0A= l =3D math.sqrt( ( a**2 ) + ( b**2 ) )=0A= phi =3D math.atan2( b, a )=0A= incrTheta +=3D incr=0A= =0A= xs.append( x + ( l * math.cos( theta + phi ) ) )=0A= ys.append( y + ( l * math.sin( theta + phi ) ) )=0A= # end while=0A= =0A= incrTheta =3D 2.0*math.pi=0A= a =3D major * math.cos( incrTheta )=0A= b =3D minor * math.sin( incrTheta )=0A= l =3D sqrt( ( a**2 ) + ( b**2 ) )=0A= phi =3D math.atan2( b, a )=0A= xs.append( x + ( l * math.cos( theta + phi ) ) )=0A= ys.append( y + ( l * math.sin( theta + phi ) ) )=0A= =0A= ellipseLine =3D ax.plot( xs, ys, **kwargs )=0A= =0A= =0A= ##################################################=0A= # make the axes=0A= ax =3D subplot( 211, aspect=3D'equal' )=0A= ax.set_aspect( 'equal', 'datalim' )=0A= =0A= # make the lower-bound ellipse=0A= diam =3D (r - delta) * 2.0=0A= lower_ellipse =3D Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=3DFalse, = edgecolor=3D"darkgreen" )=0A= ax.add_patch( lower_ellipse )=0A= =0A= # make the target ellipse=0A= diam =3D r * 2.0=0A= target_ellipse =3D Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=3DFalse, = edgecolor=3D"darkred" )=0A= ax.add_patch( target_ellipse )=0A= =0A= # make the upper-bound ellipse=0A= diam =3D (r + delta) * 2.0=0A= upper_ellipse =3D Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=3DFalse, = edgecolor=3D"darkblue" )=0A= ax.add_patch( upper_ellipse )=0A= =0A= # make the target=0A= diam =3D delta * 2.0=0A= target =3D Ellipse( (x, y), diam, diam, 0.0, fill=3DFalse, = edgecolor=3D"#DD1208" )=0A= ax.add_patch( target )=0A= =0A= # give it a big marker=0A= ax.plot( [x], [y], marker=3D'x', linestyle=3D'None', mfc=3D'red', = mec=3D'red', markersize=3D10 )=0A= =0A= ##################################################=0A= # now lets do the same thing again using a custom ellipse function=0A= =0A= # make the axes=0A= ax =3D subplot( 212, aspect=3D'equal', sharex=3Dax, sharey=3Dax )=0A= ax.set_aspect( 'equal', 'datalim' )=0A= =0A= # make the lower-bound ellipse=0A= custom_ellipse( ax, 0.0, 0.0, r-delta, r-delta, 0.0, color=3D"darkgreen" = )=0A= =0A= # make the target ellipse=0A= custom_ellipse( ax, 0.0, 0.0, r, r, 0.0, color=3D"darkred" )=0A= =0A= # make the upper-bound ellipse=0A= custom_ellipse( ax, 0.0, 0.0, r+delta, r+delta, 0.0, color=3D"darkblue" )=0A= =0A= # make the target=0A= custom_ellipse( ax, x, y, delta, delta, 0.0, color=3D"#BB1208" )=0A= =0A= # give it a big marker=0A= ax.plot( [x], [y], marker=3D'x', linestyle=3D'None', mfc=3D'red', = mec=3D'red', markersize=3D10 )=0A= =0A= ##################################################=0A= # lets zoom in to see the area of interest=0A= =0A= ax.set_xlim(2650, 2735)=0A= ax.set_ylim(6705, 6735)=0A= show()=0A= =0A= |