2019-11-28 18:54:24 +02:00
|
|
|
#!/usr/bin/env python3
|
2019-11-29 16:28:14 +02:00
|
|
|
from math import atan, pi
|
2019-11-29 00:08:08 +02:00
|
|
|
import numpy as np
|
2019-11-28 18:54:24 +02:00
|
|
|
import matplotlib.pyplot as plt
|
2019-11-29 00:34:41 +02:00
|
|
|
|
|
|
|
from collections import namedtuple
|
2019-11-29 19:37:42 +02:00
|
|
|
from shapely.geometry import LineString, asPolygon, Point as sPoint, asLineString
|
2019-11-29 00:08:08 +02:00
|
|
|
from descartes import PolygonPatch
|
2019-11-28 18:54:24 +02:00
|
|
|
|
2019-11-28 19:55:27 +02:00
|
|
|
from measure import *
|
2019-11-28 18:54:24 +02:00
|
|
|
|
2019-11-29 00:46:31 +02:00
|
|
|
juosta = namedtuple('juosta', ['plotis', 'kryptis', 'dashes', 'spalva'])
|
2019-11-29 16:28:14 +02:00
|
|
|
kelias = namedtuple('kelias', ['id', 'virsunes', 'plotis', 'kat', 'dashes', 'spalva', 'juostos'])
|
|
|
|
|
|
|
|
# nubraižytos kelio linijos ir jų nubrėžti offset'ai iš dešinės į kairę.
|
|
|
|
kelias_l = namedtuple('kelias_l', ['id', 'line', 'offsets'])
|
2019-11-28 18:54:24 +02:00
|
|
|
|
2019-11-29 00:59:37 +02:00
|
|
|
CONTINUOUS = (1,0)
|
|
|
|
DASHDOTX2 = (10,3,2,3)
|
|
|
|
DASHED = (100,20)
|
|
|
|
|
2019-11-29 16:28:14 +02:00
|
|
|
keliai = [
|
|
|
|
kelias(
|
|
|
|
id='A-08',
|
2019-11-29 00:46:31 +02:00
|
|
|
virsunes=[1,2,3],
|
|
|
|
plotis=A08_plotis,
|
2019-11-29 00:34:41 +02:00
|
|
|
kat=KAT1,
|
2019-11-29 00:59:37 +02:00
|
|
|
dashes=DASHDOTX2,
|
2019-11-29 18:13:28 +02:00
|
|
|
spalva='xkcd:red',
|
2019-11-29 00:46:31 +02:00
|
|
|
juostos=(
|
2019-11-29 18:13:28 +02:00
|
|
|
juosta(L6+L5+L4, 'right', DASHED, 'xkcd:lightgreen'),
|
|
|
|
juosta(L6+L5, 'right', DASHED, 'xkcd:lightgreen'),
|
|
|
|
juosta(L6, 'right', CONTINUOUS, 'xkcd:black'),
|
|
|
|
juosta(L7, 'left', CONTINUOUS, 'xkcd:black'),
|
|
|
|
juosta(L7+L8, 'left', DASHED, 'xkcd:lightgreen'),
|
|
|
|
juosta(L7+L8+L9, 'left', DASHED, 'xkcd:lightgreen'),
|
2019-11-29 00:59:37 +02:00
|
|
|
),
|
2019-11-29 16:28:14 +02:00
|
|
|
),
|
|
|
|
kelias(
|
|
|
|
id='A-05',
|
2019-11-29 00:59:37 +02:00
|
|
|
virsunes=[4,5,6,7,8,9,10],
|
|
|
|
plotis=A05_plotis,
|
|
|
|
kat=KAT2,
|
|
|
|
dashes=DASHDOTX2,
|
2019-11-29 18:13:28 +02:00
|
|
|
spalva='xkcd:red',
|
2019-11-29 00:59:37 +02:00
|
|
|
juostos=(
|
2019-11-29 18:13:28 +02:00
|
|
|
juosta(L3, 'right', CONTINUOUS, 'xkcd:brown'),
|
|
|
|
juosta(L2, 'left', CONTINUOUS, 'xkcd:brown'),
|
2019-11-29 00:34:41 +02:00
|
|
|
),
|
2019-11-29 16:28:14 +02:00
|
|
|
),
|
|
|
|
kelias(
|
|
|
|
id='A-03',
|
2019-11-29 00:46:31 +02:00
|
|
|
virsunes=[11,12,13,14,15,16,17,18],
|
|
|
|
plotis=A03_plotis,
|
|
|
|
kat=KAT3,
|
2019-11-29 00:59:37 +02:00
|
|
|
dashes=CONTINUOUS,
|
2019-11-29 18:13:28 +02:00
|
|
|
spalva='xkcd:magenta',
|
2019-11-29 00:46:31 +02:00
|
|
|
juostos=(
|
2019-11-29 18:13:28 +02:00
|
|
|
juosta(L1, 'right', DASHED, 'xkcd:magenta'),
|
|
|
|
juosta(0, 'left', DASHED, 'xkcd:white'),
|
2019-11-29 00:46:31 +02:00
|
|
|
),
|
2019-11-29 16:28:14 +02:00
|
|
|
),
|
|
|
|
kelias(
|
|
|
|
id='G-11',
|
2019-11-29 19:37:42 +02:00
|
|
|
virsunes=[19,20,21,22,23,24],
|
2019-11-29 00:59:37 +02:00
|
|
|
plotis=G11_plotis,
|
|
|
|
kat=KAT4,
|
|
|
|
dashes=CONTINUOUS,
|
2019-11-29 18:13:28 +02:00
|
|
|
spalva='xkcd:red',
|
2019-11-29 00:59:37 +02:00
|
|
|
juostos=(
|
2019-11-29 18:13:28 +02:00
|
|
|
juosta(L10+L11, 'right', CONTINUOUS, 'xkcd:blue'),
|
|
|
|
juosta(L11, 'right', CONTINUOUS, 'xkcd:lightblue'),
|
|
|
|
juosta(L12, 'left', CONTINUOUS, 'xkcd:lightblue'),
|
|
|
|
juosta(L12+L13, 'left', CONTINUOUS, 'xkcd:blue'),
|
2019-11-29 00:59:37 +02:00
|
|
|
),
|
2019-11-29 16:28:14 +02:00
|
|
|
),
|
|
|
|
]
|
2019-11-29 00:46:31 +02:00
|
|
|
|
2019-11-29 16:28:14 +02:00
|
|
|
N, E, S, W = (0,10), (10,0), (0,-10), (-10,0)
|
2019-11-29 14:11:51 +02:00
|
|
|
point_annotations = {
|
2019-11-29 16:28:14 +02:00
|
|
|
1: S, 2: E, 3: N, 4: W,
|
2019-11-29 14:11:51 +02:00
|
|
|
5: N, 6: S, 7: S, 8: N,
|
2019-11-29 16:28:14 +02:00
|
|
|
9: E, 10: N, 11: S, 12: N,
|
2019-11-29 14:11:51 +02:00
|
|
|
13: S, 14: W, 15: N, 16: N,
|
|
|
|
17: N, 18: E, 19: N, 20: S,
|
2019-11-29 16:28:14 +02:00
|
|
|
21: N, 22: S, 23: E, 24: N,
|
2019-11-29 14:11:51 +02:00
|
|
|
}
|
2019-11-29 16:53:41 +02:00
|
|
|
road_annotations = {'A-08':W, 'A-05':N, 'A-03':N, 'G-11':E}
|
2019-11-29 16:28:14 +02:00
|
|
|
|
2019-11-29 00:59:37 +02:00
|
|
|
# implementacija
|
|
|
|
fig, ax = plt.subplots()
|
2019-11-29 18:13:28 +02:00
|
|
|
ax.set_aspect('equal')
|
2019-11-29 14:11:51 +02:00
|
|
|
plt.grid(True)
|
2019-11-29 00:59:37 +02:00
|
|
|
|
2019-11-29 14:11:51 +02:00
|
|
|
# taškų anotacijos
|
|
|
|
for v in vertices:
|
2019-11-29 18:13:28 +02:00
|
|
|
ax.annotate(v.point, xy=v.xy, zorder=KAT0, textcoords='offset points',
|
|
|
|
fontsize='small', xytext=point_annotations[v.point])
|
2019-11-29 14:11:51 +02:00
|
|
|
|
2019-11-29 16:28:14 +02:00
|
|
|
keliai_l = {}
|
2019-11-29 14:11:51 +02:00
|
|
|
# kelių piešimas
|
2019-11-29 16:28:14 +02:00
|
|
|
for kelias in keliai:
|
2019-11-29 00:34:41 +02:00
|
|
|
# ašis
|
2019-11-29 16:28:14 +02:00
|
|
|
kelias_line = LineString([Points[i].xy for i in kelias.virsunes])
|
2019-11-29 00:46:31 +02:00
|
|
|
ax.plot(*kelias_line.xy, linewidth=2, dashes=kelias.dashes, color=kelias.spalva, zorder=kelias.kat)
|
2019-11-29 00:34:41 +02:00
|
|
|
# offset'ai
|
2019-11-29 00:46:31 +02:00
|
|
|
offset_multiplier = kelias.plotis/(kelias.juostos[0].plotis + kelias.juostos[-1].plotis)
|
2019-11-29 00:34:41 +02:00
|
|
|
offset_lines = []
|
2019-11-29 00:46:31 +02:00
|
|
|
for offset in kelias.juostos:
|
2019-11-29 16:28:14 +02:00
|
|
|
l = kelias_line.parallel_offset(offset.plotis*offset_multiplier, offset.kryptis, join_style=2)
|
2019-11-29 00:34:41 +02:00
|
|
|
offset_lines.append(l)
|
2019-11-29 00:46:31 +02:00
|
|
|
ax.plot(*l.xy, linewidth=.5, dashes=offset.dashes, color=offset.spalva, zorder=kelias.kat)
|
2019-11-29 00:34:41 +02:00
|
|
|
# kelio poligonas su plotu
|
|
|
|
kelias_poly = np.vstack((offset_lines[0].coords, offset_lines[-1].coords))
|
|
|
|
ax.add_patch(PolygonPatch(asPolygon(kelias_poly), fc='white', zorder=kelias.kat, linewidth=0))
|
2019-11-29 16:28:14 +02:00
|
|
|
keliai_l[kelias.id] = kelias_l(id=kelias.id, line=kelias_line, offsets=offset_lines)
|
2019-11-29 00:34:41 +02:00
|
|
|
|
2019-11-29 16:28:14 +02:00
|
|
|
# kelių anotacijos
|
|
|
|
for id, kelias in keliai_l.items():
|
|
|
|
linestart, lineend = np.array(kelias.offsets[-1].coords)[0:2]
|
|
|
|
delta = lineend - linestart
|
|
|
|
angle = atan(delta[1]/delta[0])*180/pi
|
|
|
|
offset = road_annotations[id]
|
2019-11-29 18:13:28 +02:00
|
|
|
ax.annotate(id, kelias.offsets[-1].coords[0], zorder=KAT0, textcoords='offset points',
|
|
|
|
fontsize='small', xytext=offset, rotation=angle)
|
2019-11-29 00:08:08 +02:00
|
|
|
|
2019-11-29 16:53:41 +02:00
|
|
|
# septynkampis
|
|
|
|
prev_dirang = float(K1)*pi/180
|
2019-11-29 18:13:28 +02:00
|
|
|
step = 5/7*pi
|
2019-11-29 16:53:41 +02:00
|
|
|
heptagon = [np.array(Points[6].xy)]
|
|
|
|
for i in range(1, 7):
|
|
|
|
dxy = np.array([float(D1)*cos(prev_dirang), float(D1)*sin(prev_dirang)])
|
|
|
|
heptagon.append(heptagon[i-1] + dxy)
|
2019-11-29 18:13:28 +02:00
|
|
|
prev_dirang += pi - step
|
|
|
|
ax.add_patch(PolygonPatch(asPolygon(heptagon), linewidth=2, fc='xkcd:white', ec='xkcd:magenta'))
|
2019-11-29 16:53:41 +02:00
|
|
|
|
2019-11-29 18:52:12 +02:00
|
|
|
# septynkampio centras
|
|
|
|
x0, y0 = Points[6].xy
|
|
|
|
x = x0 + float(D1)/(2*sin(pi/7))*sin(pi/7-float(K1)*pi/180)
|
|
|
|
y = y0 + float(D1)/(2*sin(pi/7))*cos(pi/7-float(K1)*pi/180)
|
2019-11-29 19:37:42 +02:00
|
|
|
center = sPoint(x, y)
|
|
|
|
ax.add_patch(PolygonPatch(center.buffer(5)))
|
2019-11-29 18:52:12 +02:00
|
|
|
|
2019-11-29 19:37:42 +02:00
|
|
|
radius = float(D1)/2/sin(pi/7)-float(A1)
|
|
|
|
circle = center.buffer(radius)
|
|
|
|
angles = np.linspace(0, 2*pi, num=360)
|
|
|
|
circle_y = y + np.sin(angles) * radius
|
|
|
|
circle_x = x + np.cos(angles) * radius
|
|
|
|
ax.plot(circle_x, circle_y)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
plt.show()
|