Menu

[r4766]: / branches / transforms / unit / ellipse_large.py  Maximize  Restore  History

Download this file

108 lines (80 with data), 3.1 kB

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