File: convex_hull.py

package info (click to toggle)
python-shapely 2.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 2,564 kB
  • sloc: python: 18,650; ansic: 6,615; makefile: 88; sh: 62
file content (35 lines) | stat: -rw-r--r-- 808 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import matplotlib.pyplot as plt
from shapely.geometry import MultiPoint
from shapely.plotting import plot_polygon, plot_line, plot_points

from figures import GRAY, BLUE, SIZE, set_limits

fig = plt.figure(1, figsize=SIZE, dpi=90)

# 1
ax = fig.add_subplot(121)

points2 = MultiPoint([(0, 0), (2, 2)])
plot_points(points2, ax=ax, color=GRAY)

hull2 = points2.convex_hull
plot_line(hull2, ax=ax, add_points=False, color=BLUE, zorder=3)

ax.set_title('a) N = 2')

set_limits(ax, -1, 4, -1, 3)

#2
ax = fig.add_subplot(122)

points1 = MultiPoint([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])
plot_points(points1, ax=ax, color=GRAY)

hull1 = points1.convex_hull
plot_polygon(hull1, ax=ax, add_points=False, color=BLUE, zorder=3, alpha=0.5)

ax.set_title('b) N > 2')

set_limits(ax, -1, 4, -1, 3)

plt.show()