def random_polygon(segments=8, radius=1.0):
'''
Generate a random polygon with a maximum number of sides and approximate radius.
Arguments
---------
segments: int, the maximum number of sides the random polygon will have
radius: float, the approximate radius of the polygon desired
Returns
---------
polygon: shapely.geometry.Polygon object with random exterior, and no interiors.
'''
angles = np.sort(np.cumsum(np.random.random(segments)*np.pi*2) % (np.pi*2))
radii = np.random.random(segments)*radius
points = np.column_stack((np.cos(angles), np.sin(angles)))*radii.reshape((-1,1))
points = np.vstack((points, points[0]))
polygon = Polygon(points).buffer(0.0)
if is_sequence(polygon):
return polygon[0]
return polygon
评论列表
文章目录