本文整理汇总了Python中Polygon.Polygon类的典型用法代码示例。如果您正苦于以下问题:Python Polygon类的具体用法?Python Polygon怎么用?Python Polygon使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Polygon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: line
def line(pos=(0,0), np=2, rotate=0.0, scale=1.0, xscale=1.0, yscale=1.0,
thickness=None, start=(0,0), end=(0,1), path=False):
v = vis.vector((end[0]-start[0]), (end[1]-start[1]))
if thickness is None:
thickness = 0.01*vis.mag(v)
dv = thickness*vis.norm(vis.vector(0,0,1).cross(v))
dx = dv.x
dy = dv.y
cp = [] # outer line
cpi = [] # inner line
vline = (vis.vector(end)-vis.vector(start)).norm()
mline = vis.mag(vis.vector(end)-vis.vector(start))
for i in range(np):
x = start[0] + (vline*i)[0]/float(np-1)*mline
y = start[1] + (vline*i)[1]/float(np-1)*mline
cp.append( (x+pos[0],y+pos[1]) )
cpi.append( (x+pos[0]+dx,y+pos[1]+dy) )
if not path:
cpi.reverse()
for p in cpi:
cp.append(p)
cp.append(cp[0])
if rotate != 0.0: cp = rotatecp(cp, pos, rotate)
if scale != 1.0: xscale = yscale = scale
pp = Polygon(cp)
if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
if not path:
return pp
else:
return [cp]
示例2: ngon
def ngon(pos=(0,0), np=3, length=None, radius=1.0, rotate=0.0, thickness=0,
roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0):
cp = []
if np < 3:
raise AttributeError("number of sides can not be less than 3")
return None
angle = 2*pi/np
if length != None: radius = (length/2.0)/(sin(angle/2))
else: length = radius*(sin(angle/2))*2
if thickness == 0:
seg = 2.0*pi/np
angle = rotate
for i in range(np):
x = radius*cos(angle) + pos[0]
y = radius*sin(angle) + pos[1]
cp.append((x,y))
angle += seg
cp.append(cp[0])
if scale != 1.0: xscale = yscale = scale
pp = Polygon(cp)
if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
if roundness > 0:
cp = roundc(pp.contour(0), roundness=roundness, invert=invert)
return Polygon(cp)
else: return pp
else:
pp = nframe(pos=pos, length=length, thickness=thickness, roundness=roundness,
invert=invert, rotate=rotate, np=np)
return pp
示例3: arc
def arc(pos=(0,0), radius=0.5, np=32, rotate=0.0, scale=1.0, xscale=1.0, yscale=1.0,
thickness=None, angle1=0.0, angle2=pi, path=False):
if thickness is None:
thickness = 0.01*radius
cp = [] # outer arc
cpi = [] # inner arc
seg = 2.0*pi/np
nseg = int(abs((angle2-angle1))/seg)+1
seg = (angle2-angle1)/nseg
for i in range(nseg+1):
x = cos(angle1+i*seg)
y = sin(angle1+i*seg)
cp.append( (radius*x+pos[0],radius*y+pos[1]) )
cpi.append( ((radius-thickness)*x+pos[0],(radius-thickness)*y+pos[1]) )
if not path:
cpi.reverse()
for p in cpi:
cp.append(p)
cp.append(cp[0])
if rotate != 0.0: cp = rotatecp(cp, pos, rotate)
if scale != 1.0: xscale = yscale = scale
pp = Polygon(cp)
if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
if not path:
return pp
else:
return [cp]
示例4: shape_center
def shape_center(shape):
"""
computes the center of gravity of a shapefile multi-polygon
"""
from Polygon import Polygon
parts = shape.parts[:]
parts.append(len(shape.points))
# check for countries that cross the 180° longitude
far_east = False
far_west = False
for i in range(len(parts)-1):
pts = shape.points[parts[i]:parts[i+1]]
if len(pts) == 0: continue
if pts[0][0] < -90:
far_west = True
if pts[0][0] > 90:
far_east = True
poly = Polygon()
for i in range(len(parts)-1):
pts = shape.points[parts[i]:parts[i+1]]
if far_east and far_west:
# correct points
for j in range(len(pts)):
if pts[j][0] < 0: pts[j][0] += 360
poly.addContour(pts)
return poly.center()
示例5: rectangle
def rectangle(pos=(0,0), width=1.0, height=None, rotate=0.0, thickness=0,
roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0):
if height is None: height = width
if thickness == 0:
p0 = (pos[0]+width/2.0, pos[1]-height/2.0)
p1 = (pos[0]+width/2.0, pos[1]+height/2.0)
p2 = (pos[0]-width/2.0, pos[1]+height/2.0)
p3 = (pos[0]-width/2.0, pos[1]-height/2.0)
p4 = (pos[0]+width/2.0, pos[1]-height/2.0)
cp = [p0, p1, p2, p3, p4]
if rotate != 0.0: cp = rotatecp(cp, pos, rotate)
if scale != 1.0: xscale = yscale = scale
pp = Polygon(cp)
if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
if roundness > 0:
cp = roundc(pp.contour(0), roundness=roundness, invert=invert)
return Polygon(cp)
else: return pp
else:
pp = rframe(pos=pos, width=width, height=height, thickness=thickness,
rotate=rotate, roundness=roundness, invert=invert,
scale=scale, xscale=xscale, yscale=yscale)
return pp
示例6: gear
def gear(pos=(0,0), n=20, radius=5, phi=20, addendum=0.4, dedendum=0.5,
fradius=0.1, rotate=0, scale=1.0, internal=False, res=1, bevel=0):
tooth = ToothOutline(n, res, phi, radius, addendum, dedendum,
fradius, bevel=0.0)
if internal:
itooth = []
for p in tooth:
px = p[0]
py = p[1]
driro = sqrt(px*px +py*py) - radius
ir = radius - driro
ro = radius + driro
ix = (ir/ro)*px
iy = (ir/ro)*py
itooth.append((ix,iy))
tooth = itooth
gear = []
for i in range(0, n):
rotan = -i*2*pi/n
rtooth = []
for (x, y) in tooth:
rx = x*cos(rotan) - y*sin(rotan) + pos[0]
ry = x*sin(rotan) + y*cos(rotan) + pos[1]
rtooth.append((rx,ry))
gear.extend(rtooth)
#gear.append(gear[0])
pp = Polygon(gear)
if rotate != 0.0: pp.rotate(rotate)
if scale != 1.0 : pp.scale(scale,scale)
return pp
示例7: ellipse
def ellipse(pos=(0,0), width=1.0, height=None, np=32, rotate=0.0, thickness=None,
scale=1.0, xscale=1.0, yscale=1.0):
if height == None: height = 0.5*width
if thickness == 0 or thickness == None:
cp = []
seg = 2.0*pi/np
angle = 0
radius=0.5
lf = width/2.0
hf = height/2.0
for i in range(np):
x = cos(angle)*lf + pos[0]
y = sin(angle)*hf + pos[1]
cp.append((x,y))
angle += seg
cp.append(cp[0])
if rotate != 0.0: cp = rotatecp(cp, pos, rotate)
if scale != 1.0: xscale = yscale = scale
pp = Polygon(cp)
if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
return pp
else:
pp = ering(pos=pos, width=width, height=height, np=np, rotate=rotate,
thickness=thickness)
return pp
示例8: rackGear
def rackGear(pos=(0,0), n=30, radius=5., phi=20., addendum=0.4, dedendum=0.5,
fradius=0.1, rotate=0, scale=1.0, length=10*pi, res=1, bevel=0.05, depth=(0.4+0.6+0.1)):
tooth = RackOutline(n, res, phi, radius, addendum, dedendum,
fradius, bevel)
toothl = tooth[0][1] - tooth[-1][1]
ntooth = int(length/toothl)
flength = ntooth * toothl
gear = []
for i in range(0, ntooth):
ntooth = []
for (x, y) in tooth:
nx = x + pos[0]
ny = -i*toothl + y + pos[1]
ntooth.append((nx,ny))
gear.extend(ntooth)
gear.append((gear[-1][0]-depth,gear[-1][1]))
gear.append((gear[0][0]-depth,gear[0][1]))
gear.append(gear[0])
pp = Polygon(gear)
pp.shift(-pp.center()[0],-pp.center()[1])
if rotate != 0.0: pp.rotate(rotate)
if scale != 1.0 : pp.scale(scale,scale)
return pp
示例9: center
def center(self):
ret = [0, 0]
if self.type() == 'MultiPolygon':
p = Polygon(self.coordinates()[0][0])
ret = list(p.center())
else:
ret = self.coordinates()
c = transform_to_4326(self.crs_code(), ret[0], ret[1])
return [c[0], c[1]]
示例10: polygon_center
def polygon_center(polygon):
"""
computes the center of gravity of a gisutils.Polygon
"""
from Polygon import Polygon as Poly
pts = []
for pt in polygon.points:
pts.append((pt.x, pt.y))
poly = Poly(pts)
c = poly.center()
return Point(c[0], c[1])
示例11: __init__
def __init__(self,score,time):
"Initialises resources and start level"
self.background=pygame.image.load("sprites/sky.jpg")
self.background.convert() #for blitting more faster
self.screen=Constants.SCREEN
self.score = score
self.display_items = pygame.sprite.Group()
self.timeclock = GameTime((0.05,0.05),time)
self.display_items.add(self.timeclock,self.score)
self.time_speed=pygame.time.Clock()
self.time=0.0
self.quit = False
self.pause = False
self.start = False
self.completed = False
self.gameover = False
self.message = None
self.polygon=Polygon(self)
self.event_manager = EventManager(self)
self.on_enter()
示例12: restore_poly_from_path_str
def restore_poly_from_path_str(path_str):
"""
restores a list of polygons from a SVG path string
"""
contours = path_str.split('Z') # last contour may be empty
from Polygon import Polygon as Poly
poly = Poly()
for c_str in contours:
if c_str.strip() != "":
pts_str = c_str.strip()[1:].split("L")
pts = []
for pt_str in pts_str:
x, y = map(float, pt_str.split(','))
pts.append((x, y))
poly.addContour(pts, is_clockwise(pts))
return poly
示例13: __init__
def __init__(self, world, chunk_pos):
self.world = world
self.pos = (chunk_pos[0] * 51.2, chunk_pos[1] * 51.2)
self.chunk_pos = (chunk_pos[0] % 32, chunk_pos[1])
self.texture = None
self.polygon = None
self.body = None
self.entities = []
self.things_to_blit = []
texture_filename = "data/world/%i_%i.tga" % self.chunk_pos
if os.path.exists(texture_filename):
self.texture = pygame.image.load(texture_filename)
self.texture.set_colorkey((255, 0, 255))
elif chunk_pos[1] <= 1:
self.texture = Chunk.underground_texture
data_filename = "data/world/%i_%i.dat" % self.chunk_pos
if os.path.exists(data_filename):
with open(data_filename) as fin:
self.polygon, self.entities = pickle.load(fin)
elif chunk_pos[1] <= 1:
self.polygon = Polygon((
(-25.6, -25.6),
(-25.6, 25.6),
(25.6, 25.6),
(25.6, -25.6)
))
self.load_body()
示例14: __init__
def __init__( self , polygons = None ):
if polygons is None:
self._polygons = [ Polygon.rand_triangle( IMG_WIDTH , IMG_HEIGHT ) for _ in range( 0 , P ) ]
else:
self._polygons = polygons
self._fitness = -1
self._pixelArray = None
pass
示例15: updateLocation
def updateLocation(self, newLocation):
self.previousLocation = self.location
self.location = newLocation
self.bbox = BoundingBox(self.location.x-self.width/2, self.location.y-self.height/2,
self.location.x+self.width/2, self.location.y+self.height/2)
self.polygon = Polygon.createBoundingBoxPolygon(Vector(self.location.x-self.width/2, self.location.y-self.height/2),
Vector(self.location.x+self.width/2, self.location.y+self.height/2))
self.polygon.convex = True