From 829b93317c38b9824f391f44ddce6e9fea4973cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Fri, 29 Nov 2019 16:28:14 +0200 Subject: [PATCH] line annotations --- Karto/assignment4/draw.py | 59 ++++++++++++++++++++++++------------ Karto/assignment4/measure.py | 2 +- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/Karto/assignment4/draw.py b/Karto/assignment4/draw.py index 2136253..024d95c 100755 --- a/Karto/assignment4/draw.py +++ b/Karto/assignment4/draw.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +from math import atan, pi import numpy as np import matplotlib.pyplot as plt @@ -9,14 +10,19 @@ from descartes import PolygonPatch from measure import * juosta = namedtuple('juosta', ['plotis', 'kryptis', 'dashes', 'spalva']) -kelias = namedtuple('kelias', ['virsunes', 'plotis', 'kat', 'dashes', 'spalva', 'juostos']) +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']) CONTINUOUS = (1,0) DASHDOTX2 = (10,3,2,3) DASHED = (100,20) -a08 = kelias( +keliai = [ + kelias( + id='A-08', virsunes=[1,2,3], plotis=A08_plotis, kat=KAT1, @@ -30,9 +36,9 @@ a08 = kelias( juosta(L7+L8, 'left', DASHED, 'lightgreen'), juosta(L7+L8+L9, 'left', DASHED, 'lightgreen'), ), -) - -a05 = kelias( + ), + kelias( + id='A-05', virsunes=[4,5,6,7,8,9,10], plotis=A05_plotis, kat=KAT2, @@ -42,9 +48,9 @@ a05 = kelias( juosta(L3, 'right', CONTINUOUS, 'brown'), juosta(L2, 'left', CONTINUOUS, 'brown'), ), -) - -a03 = kelias( + ), + kelias( + id='A-03', virsunes=[11,12,13,14,15,16,17,18], plotis=A03_plotis, kat=KAT3, @@ -52,10 +58,11 @@ a03 = kelias( spalva='pink', juostos=( juosta(L1, 'right', DASHED, 'pink'), + juosta(0, 'left', DASHED, 'white'), ), -) - -g11 = kelias( + ), + kelias( + id='G-11', virsunes=[19,20,21,22,23], plotis=G11_plotis, kat=KAT4, @@ -67,41 +74,53 @@ g11 = kelias( juosta(L12, 'left', CONTINUOUS, 'lightblue'), juosta(L12+L13, 'left', CONTINUOUS, 'blue'), ), -) + ), +] -N, E, S, W = (0,15), (15,0), (0,-15), (-15,0) +N, E, S, W = (0,10), (10,0), (0,-10), (-10,0) point_annotations = { - 1: S, 2: E, 3: N, 4: E, + 1: S, 2: E, 3: N, 4: W, 5: N, 6: S, 7: S, 8: N, - 9: E, 10: N, 11: N, 12: N, + 9: E, 10: N, 11: S, 12: N, 13: S, 14: W, 15: N, 16: N, 17: N, 18: E, 19: N, 20: S, - 21: N, 22: N, 23: E, 24: N, + 21: N, 22: S, 23: E, 24: N, } +road_annotations = { 'A-08': W, 'A-05': N, 'A-03': N, 'G-11': E } + # implementacija fig, ax = plt.subplots() plt.grid(True) # taškų anotacijos for v in vertices: - ax.annotate(v.point, xy=v.xy, zorder=99, textcoords='offset points', xytext=point_annotations[v.point]) + ax.annotate(v.point, xy=v.xy, zorder=KAT0, textcoords='offset points', xytext=point_annotations[v.point]) +keliai_l = {} # kelių piešimas -for kelias in [a08, a05, a03, g11]: +for kelias in keliai: # ašis - kelias_line = LineString([Points[i].xy for i in kelias.virsunes ]) + kelias_line = LineString([Points[i].xy for i in kelias.virsunes]) ax.plot(*kelias_line.xy, linewidth=2, dashes=kelias.dashes, color=kelias.spalva, zorder=kelias.kat) # offset'ai offset_multiplier = kelias.plotis/(kelias.juostos[0].plotis + kelias.juostos[-1].plotis) offset_lines = [] for offset in kelias.juostos: - l = kelias_line.parallel_offset(offset.plotis * offset_multiplier, offset.kryptis, join_style=2) + l = kelias_line.parallel_offset(offset.plotis*offset_multiplier, offset.kryptis, join_style=2) offset_lines.append(l) ax.plot(*l.xy, linewidth=.5, dashes=offset.dashes, color=offset.spalva, zorder=kelias.kat) # 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)) + keliai_l[kelias.id] = kelias_l(id=kelias.id, line=kelias_line, offsets=offset_lines) +# 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] + ax.annotate(id, kelias.offsets[-1].coords[0], zorder=KAT0, textcoords='offset points', xytext=offset, rotation=angle) plt.show() diff --git a/Karto/assignment4/measure.py b/Karto/assignment4/measure.py index 68a04e0..c1a87de 100755 --- a/Karto/assignment4/measure.py +++ b/Karto/assignment4/measure.py @@ -40,7 +40,7 @@ class Vertex: return (self.coords.lksx, self.coords.lksy) # Kategorijos -KAT1, KAT2, KAT3, KAT4 = range(4,0,-1) +KAT0, KAT1, KAT2, KAT3, KAT4 = range(5,0,-1) A = Dec('6.094') B = Dec('-2.923')