File: parallel_offset.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 (58 lines) | stat: -rw-r--r-- 1,704 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import matplotlib.pyplot as plt
from shapely import LineString, get_point
from shapely.plotting import plot_line, plot_points

from figures import SIZE, BLUE, GRAY, set_limits

line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])
line_bounds = line.bounds
ax_range = [int(line_bounds[0] - 1.0), int(line_bounds[2] + 1.0)]
ay_range = [int(line_bounds[1] - 1.0), int(line_bounds[3] + 1.0)]

fig = plt.figure(1, figsize=(SIZE[0], 1.5 * SIZE[1]), dpi=90)

# 1
ax = fig.add_subplot(221)

plot_line(line, ax, add_points=False, color=GRAY)
plot_points(get_point(line, 0), ax=ax, color=GRAY)
offset = line.parallel_offset(0.5, 'left', join_style=1)
plot_line(offset, ax=ax, add_points=False, color=BLUE)

ax.set_title('a) left, round')
set_limits(ax, -2, 4, -1, 3)

#2
ax = fig.add_subplot(222)

plot_line(line, ax, add_points=False, color=GRAY)
plot_points(get_point(line, 0), ax=ax, color=GRAY)
offset = line.parallel_offset(0.5, 'left', join_style=2)
plot_line(offset, ax=ax, add_points=False, color=BLUE)

ax.set_title('b) left, mitred')
set_limits(ax, -2, 4, -1, 3)

#3
ax = fig.add_subplot(223)

plot_line(line, ax, add_points=False, color=GRAY)
plot_points(get_point(line, 0), ax=ax, color=GRAY)
offset = line.parallel_offset(0.5, 'left', join_style=3)
plot_line(offset, ax=ax, add_points=False, color=BLUE)

ax.set_title('c) left, beveled')
set_limits(ax, -2, 4, -1, 3)

#4
ax = fig.add_subplot(224)

plot_line(line, ax, add_points=False, color=GRAY)
plot_points(get_point(line, 0), ax=ax, color=GRAY)
offset = line.parallel_offset(0.5, 'right', join_style=1)
plot_line(offset, ax=ax, add_points=False, color=BLUE)

ax.set_title('d) right, round')
set_limits(ax, -2, 4, -1, 3)

plt.show()