本文整理汇总了Python中polygon.Polygon类的典型用法代码示例。如果您正苦于以下问题:Python Polygon类的具体用法?Python Polygon怎么用?Python Polygon使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Polygon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_should_retrieve_false_to_a_point_that_is_not_inside_a_polygon
def test_should_retrieve_false_to_a_point_that_is_not_inside_a_polygon(self):
A = [3, 6]; B = [3, 11]; C = [6, 11]; D = [6, 9]; E = [5, 9]; F = [5, 6]
polygon = Polygon([A, B, C, D, E, F])
test_point = [4, 5]
assert_false(polygon.belongs_to_polygon(test_point))
test_point = [6, 7]
assert_false(polygon.belongs_to_polygon(test_point))
示例2: __init__
def __init__(self, position = (0, 0), node_list = []):
Polygon.__init__(self, node_list)
Translatable.__init__(self, position)
Named.__init__(self)
self.__connected_objects = []
self.__pointed_objects = []
self.add_name('_arrow_')
示例3: project
def project(self, perspective=False):
p = Polygon()
for line in self.lines:
line2d = line.project(perspective)
p.add_line(line2d)
return p
示例4: test_various_points_in_square
def test_various_points_in_square(self):
square = Polygon(
vertex_positions=[
(1.0, -1.0),
(1.0, 1.0),
(-1.0, 1.0),
(-1.0, -1.0),
]
)
test_points = []
for x in range(-3, 4):
for y in range(-3, 4):
test_points.append((0.5*x, 0.5*y))
for point in test_points:
x, y = point
if -1 < x < 1 and -1 < y < 1:
# Point is inside.
self.assertEqual(square.winding_number(point), 1)
elif x < -1 or x > 1 or y < -1 or y > 1:
# Point outside.
self.assertEqual(square.winding_number(point), 0)
else:
with self.assertRaises(ValueError):
square.winding_number(point)
示例5: generate_new_poly
def generate_new_poly(self, ev):
points = get_random_polygon()
self.set_points(points)
poly = Polygon()
poly.set_points(points)
self.canvas.delete("all")
self.draw_polygon_points(poly)
self.set_result(0)
示例6: __init__
def __init__(self, position, rotation, color):
p1 = Point(0,-4)
p2 = Point(0,4)
p3 = Point(20,0)
self.outline = [p3, p1, p2]
self.position = position
self.rotation = rotation
self.color = color
Polygon.__init__(self, self.outline, self.position, self.rotation, self.color)
示例7: make_square
def make_square( self, top_left, bottom_right, z ):
colour = 255 - z % 100
a, b = top_left
c, d = bottom_right
square = Polygon( ( colour, colour, colour ) ).add( Point( a, b, z ) ) \
.add( Point( b, c, z ) ).add( Point( c, d, z ) ) \
.add( Point( d, a, z ) )
square.set_width( 1 )
return square
示例8: create_linked_list
def create_linked_list(filename='input.txt'):
points = read_from_file(filename)
poly = Polygon()
poly.set_points(points)
points = poly.get_linked_list()
return points[0], len(points)
示例9: test_clockwise_square
def test_clockwise_square(self):
square = Polygon(
vertex_positions=[
(1.0, -1.0),
(1.0, 1.0),
(-1.0, 1.0),
(-1.0, -1.0),
][::-1]
)
origin = (0.0, 0.0)
self.assertEqual(square.winding_number(origin), -1)
self.assertEqual(square.area(), -4.0)
示例10: test_double_square
def test_double_square(self):
square = Polygon(
vertex_positions=[
(1.0, -1.0),
(1.0, 1.0),
(-1.0, 1.0),
(-1.0, -1.0),
] * 2
)
origin = (0.0, 0.0)
self.assertEqual(square.winding_number(origin), 2)
self.assertEqual(square.area(), 8.0)
示例11: test_simple_square
def test_simple_square(self):
square = Polygon(
vertex_positions=[
(1.0, -1.0),
(1.0, 1.0),
(-1.0, 1.0),
(-1.0, -1.0),
]
)
origin = (0.0, 0.0)
self.assertEqual(square.winding_number(origin), 1)
self.assertEqual(square.area(), 4.0)
示例12: create_random
def create_random(self, n):
""" Create n polygons with random vertices. The dimensions of each
picture should be specified with max_x and may_y.
"""
self.polygons = []
for i in xrange(0, n):
p = Polygon()
# 3 to 5 vertices
Polygon.create_random(p, random.randint(3,5))
self.polygons.append(p)
return self
示例13: __init__
def __init__(self):
shape = [Point(24, 0), Point(-12, -12), Point(0, 0), Point(-12, 12)]
position = Point(config.SCREEN_X/2, config.SCREEN_Y/2)
self.rotation = config.SHIP_INITIAL_DIRECTION
color = config.SHIP_COLOR
Polygon.__init__(self, shape, position, self.rotation, color)
self.accelerate = (0, 0)
self.stop = Point(0, 0)
pygame.mixer.init()
self.fire_sfx = pygame.mixer.Sound("laser.wav")
self.count = 5
self.shield_health = 100
self.nuke_count = 1
示例14: __init__
def __init__(self, position, rotation, color, rotation_speed, motion):
self.outline = []
for angle in range(0, 360, 360/config.ROCK_POLYGON_SIZE):
radius = random.uniform(config.ROCK_MIN_RADIUS, config.ROCK_MAX_RADIUS)
angle_rad = math.radians(angle)
(x,y) = math.cos(angle_rad) * radius, math.sin(angle_rad) * radius
p = Point(x,y)
self.outline.append(p)
self.position = position
self.rotation = rotation
self.color = color
self.rotation_speed = rotation_speed
self.motion = motion
Polygon.__init__(self, self.outline, self.position, self.rotation, self.color)
self.accelerate(self.motion)
示例15: test_numpy_compatibility
def test_numpy_compatibility(self):
square = Polygon(
vertex_positions=numpy.array(
[
[1.0, -1.0],
[1.0, 1.0],
[-1.0, 1.0],
[-1.0, -1.0],
],
dtype=numpy.float64,
)
)
origin = numpy.array([0.0, 0.0], dtype=numpy.float64)
self.assertEqual(square.winding_number(origin), 1)
self.assertEqual(square.area(), 4.0)