我只想按点绘制简单的形状,如下所示:
import matplotlib.pyplot as plt
rectangle = [(0,0),(0,1),(1,1),(1,0)]
hexagon = [(0,0),(0,1),(1,2),(2,1),(2,0),(1,-1)]
l_shape = [(0,0),(0,3),(1,3),(1,1),(3,1),(3,0)]
concave = [(0,0),(0,3),(1,3),(1,1),(2,1),(2,3),(3,3),(3,0)]
for points in [rectangle, hexagon, l_shape, concave]:
# 1. Can I get rid of the zip? plot directly by points
# 2. How can I make the shape complete?
xs, ys = zip(*points)
plt.plot(xs, ys, 'o')
plt.plot(xs, ys, '-')
automin, automax = plt.xlim()
plt.xlim(automin-0.5, automax+0.5)
automin, automax = plt.ylim()
plt.ylim(automin-0.5, automax+0.5)
# Can I display the shapes 2 in 1 line?
plt.show()
Run Code Online (Sandbox Code Playgroud)
我的问题是 …
我使用 Shapely 库来处理多边形。它有一个名为的类Polygon,它获取一组有序的坐标并将它们转换为多边形。
问题是我得到了一组无序坐标。我想要包裹所有点的多边形。
我一直在研究 Shapley 文档,但找不到任何有关如何操作的信息
在将点发送到之前是否有一种算法可以对点进行排序Polygon?或者还有其他方法可以做到这一点吗?