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
|
import numpy
from kiva import agg
poly = numpy.array((( 0.0, 0.0),
(10.0, 0.0),
(10.0, 10.0),
( 0.0, 10.0)))
print agg.point_in_polygon(-1,-1,poly)
print agg.point_in_polygon(0.0,0.0,poly)
print agg.point_in_polygon(5,5,poly)
print agg.point_in_polygon(10,10,poly)
print agg.point_in_polygon(15,15,poly)
pts = numpy.array(((-1.0, -1.0),
( 0.1, 0.0),
( 0.0, 0.1),
( 0.0, 0.0),
( 5.0, 5.0),
( 10.0, 10.0),
( 15.0, 15.0)))
results = agg.points_in_polygon(pts, poly)
print results
pts = numpy.random.random_sample((20000, 2))*12.5-2.5
import time
t1 = time.clock()
results = agg.points_in_polygon(pts, poly)
t2 = time.clock()
print 'points_in_polygon() for %d pts in %d point polygon (sec): %f' % \
(len(pts), len(poly), t2-t1)
print pts[:5]
print results[:5]
poly = numpy.array((( 0.0, 0.0),
( 2.0, 0.0),
( 5.0, 0.0),
( 7.5, 0.0),
(10.0, 0.0),
(10.0, 2.5),
(10.0, 5.0),
(10.0, 7.5),
(10.0, 10.0),
( 7.5, 10.0),
( 5.0, 10.0),
( 2.5, 10.0),
( 0.0, 10.0)))
t1 = time.clock()
results = agg.points_in_polygon(pts, poly)
t2 = time.clock()
print 'points_in_polygon() for %d pts in %d point polygon (sec): %f' % \
(len(pts), len(poly), t2-t1)
print pts[:5]
print results[:5]
|