本文整理汇总了Python中sympy.geometry.convex_hull函数的典型用法代码示例。如果您正苦于以下问题:Python convex_hull函数的具体用法?Python convex_hull怎么用?Python convex_hull使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了convex_hull函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_convex_hull
def test_convex_hull():
p = [Point(-5,-1), Point(-2,1), Point(-2,-1), Point(-1,-3), Point(0,0),
Point(1,1), Point(2,2), Point(2,-1), Point(3,1), Point(4,-1), Point(6,2)]
ch = Polygon(p[0], p[3], p[9], p[10], p[6], p[1])
assert convex_hull(p) == ch
assert convex_hull(p[0]) == p[0]
assert convex_hull(p[0], p[1]) == Segment(p[0], p[1])
示例2: test_convex_hull
def test_convex_hull():
p = [Point(-5,-1), Point(-2,1), Point(-2,-1), Point(-1,-3), Point(0,0),
Point(1,1), Point(2,2), Point(2,-1), Point(3,1), Point(4,-1), Point(6,2)]
ch = Polygon(p[0], p[3], p[9], p[10], p[6], p[1])
#test handling of duplicate points
p.append(p[3])
#more than 3 collinear points
another_p = [Point(-45, -85), Point(-45, 85), Point(-45,26),Point(-45,-24)]
ch2 = Segment(another_p[0],another_p[1])
assert convex_hull(another_p) == ch2
assert convex_hull(p) == ch
assert convex_hull(p[0]) == p[0]
assert convex_hull(p[0], p[1]) == Segment(p[0], p[1])
示例3: test_convex_hull
def test_convex_hull():
p = [
Point(-5, -1),
Point(-2, 1),
Point(-2, -1),
Point(-1, -3),
Point(0, 0),
Point(1, 1),
Point(2, 2),
Point(2, -1),
Point(3, 1),
Point(4, -1),
Point(6, 2),
]
ch = Polygon(p[0], p[3], p[9], p[10], p[6], p[1])
# test handling of duplicate points
p.append(p[3])
# more than 3 collinear points
another_p = [Point(-45, -85), Point(-45, 85), Point(-45, 26), Point(-45, -24)]
ch2 = Segment(another_p[0], another_p[1])
assert convex_hull(*another_p) == ch2
assert convex_hull(*p) == ch
assert convex_hull(p[0]) == p[0]
assert convex_hull(p[0], p[1]) == Segment(p[0], p[1])
# no unique points
assert convex_hull(*[p[-1]] * 3) == p[-1]
# collection of items
assert convex_hull(*[Point(0, 0), Segment(Point(1, 0), Point(1, 1)), RegularPolygon(Point(2, 0), 2, 4)]) == Polygon(
Point(0, 0), Point(2, -2), Point(4, 0), Point(2, 2)
)
示例4: __init__
def __init__(self, dim, polygon=None, point=None):
"""
Construct OBB from either the polygon which represents the convex hull or from a list of point.
:param polygon: the sympy.geometry.Polygon which represents the convex hull of a set of points.
:param point: list of sympy,geometry.Point.
:modify: if successful diagonal coordinates of OBB where
r[0]: x_min
r[1]: y_min
r[2]: x_max
r[3]: y_max.
:error: if dim is not 2 or both polygon and point are None raise ValueError.
"""
if dim != 2:
raise ValueError('only 2D is supported.')
if point is None and polygon is not None:
for _ in range(2*dim):
self.r.append(polygon.bounds[_])
elif point is not None and polygon is None:
symgeo.convex_hull(point)
else:
raise ValueError('both polygon and point are None.')
示例5: test_util
def test_util():
# coverage for some leftover functions in sympy.geometry.util
assert intersection(Point(0, 0)) == []
raises(ValueError, lambda: intersection(Point(0, 0), 3))
raises(ValueError, lambda: convex_hull(Point(0, 0), 3))
示例6: test_convex_hull
def test_convex_hull():
raises(TypeError, lambda: convex_hull(Point(0, 0), 3))
points = [(1, -1), (1, -2), (3, -1), (-5, -2), (15, -4)]
assert convex_hull(*points, **dict(polygon=False)) == (
[Point2D(-5, -2), Point2D(1, -1), Point2D(3, -1), Point2D(15, -4)],
[Point2D(-5, -2), Point2D(15, -4)])