diff --git a/Karto/assignment4/draw.py b/Karto/assignment4/draw.py index f8ba95d..5a0e1cf 100755 --- a/Karto/assignment4/draw.py +++ b/Karto/assignment4/draw.py @@ -1,6 +1,9 @@ #!/usr/bin/env python3 +import numpy as np import matplotlib.pyplot as plt -from shapely.geometry import LineString +from shapely.geometry import LineString, asPolygon +from shapely.coords import CoordinateSequence +from descartes import PolygonPatch from measure import * @@ -9,19 +12,23 @@ fig, ax = plt.subplots() A08_l = LineString([Points[i].xy for i in [1,2,3] ]) A08_multiplier = A08_plotis/(L4+L5+L6+L7+L8+L9) -A08_offsetR1 = A08_l.parallel_offset(L6*A08_multiplier, 'right', join_style=2) -A08_offsetR2 = A08_l.parallel_offset((L6+L5)*A08_multiplier, 'right', join_style=2) -A08_offsetR3 = A08_l.parallel_offset((L6+L5+L4)*A08_multiplier, 'right', join_style=2) -A08_offsetL1 = A08_l.parallel_offset(L7*A08_multiplier, 'left', join_style=2) -A08_offsetL2 = A08_l.parallel_offset((L7+L8)*A08_multiplier, 'left', join_style=2) -A08_offsetL3 = A08_l.parallel_offset((L7+L8+L9)*A08_multiplier, 'left', join_style=2) -ax.plot(*A08_l.xy, linewidth=2, dashes=[5,2,2,5], color='red', zorder=KAT3) -ax.plot(*A08_offsetR1.xy, linewidth=.5, zorder=KAT1, color='black') -ax.plot(*A08_offsetR2.xy, linewidth=.5, dashes=[5,3], color='lightgreen', zorder=KAT1) -ax.plot(*A08_offsetR3.xy, linewidth=.5, dashes=[5,3], color='lightgreen', zorder=KAT1) -ax.plot(*A08_offsetL1.xy, linewidth=.5, zorder=KAT1, color='black') -ax.plot(*A08_offsetL2.xy, linewidth=.5, dashes=[5,3], color='lightgreen', zorder=KAT1) -ax.plot(*A08_offsetL3.xy, linewidth=.5, dashes=[5,3], color='lightgreen', zorder=KAT1) +def offset(width, direction): + return A08_l.parallel_offset(width * A08_multiplier, direction, join_style=2) +offsets = ( + (offset(L6+L5+L4, 'right'), (5,3), 'lightgreen'), + (offset(L6+L5, 'right'), (5,3), 'lightgreen'), + (offset(L6, 'right'), (1,0), 'black'), + (offset(L7, 'left'), (1,0), 'black'), + (offset(L7+L8, 'left'), [5,3], 'lightgreen'), + (offset(L7+L8+L9, 'left'), [5,3], 'lightgreen'), +) +for line, dashes, color in offsets: + ax.plot(*line.xy, linewidth=.5, dashes=dashes, color=color, zorder=KAT1) + +A08_poly = np.vstack((offsets[0][0].coords, offsets[-1][0].coords)) +ax.add_patch(PolygonPatch(asPolygon(A08_poly), fc='white', zorder=KAT1, linewidth=0)) +ax.plot(*A08_l.xy, linewidth=2, dashes=[5,2,2,5], color='red', zorder=KAT1) + A03_l = LineString([Points[i].xy for i in [11,12,13,14,15,16,17,18] ]) A03_offsetR = A03_l.parallel_offset(A03_plotis, 'right', join_style=2)