@@ -133,27 +133,25 @@ def offset_polygon(polygon, distance):
133133 distances = [distance ] * p
134134
135135 d = len (distances )
136+
136137 if d < p :
137138 distances .extend (distances [- 1 :] * (p - d ))
138139
139140 normal = normal_polygon (polygon )
140141
141- lines = pairwise (polygon + polygon [:1 ])
142-
143- lines_offset = []
144- for line , distance in zip (lines , distances ):
145- lines_offset .append (offset_line (line , distance , normal ))
142+ offset = []
143+ for line , distance in zip (pairwise (polygon + polygon [:1 ]), distances ):
144+ offset .append (offset_line (line , distance , normal ))
146145
147- polygon_offset = []
148- for l1 , l2 in pairwise (lines_offset + lines_offset [: 1 ] ):
146+ points = []
147+ for l1 , l2 in pairwise (offset [ - 1 :] + offset ):
149148 x1 , x2 = intersection_line_line (l1 , l2 )
150-
151149 if x1 and x2 :
152- polygon_offset .append (centroid_points ([x1 , x2 ]))
150+ points .append (centroid_points ([x1 , x2 ]))
153151 else :
154- polygon_offset .append (x1 )
152+ points .append (x1 )
155153
156- return polygon_offset
154+ return points
157155
158156
159157def offset_polyline (polyline , distance , normal = [0. , 0. , 1. ]):
@@ -216,10 +214,24 @@ def offset_polyline(polyline, distance, normal=[0., 0., 1.]):
216214
217215 mesh = Mesh .from_obj (compas .get ('faces.obj' ))
218216
219- polygons = [{'points' : offset_polygon (mesh .face_coordinates (fkey ), 0.1 ), 'edgecolor' : '#ff0000' } for fkey in mesh .faces ()]
220- # polygons = [{'points': offset_polygon(mesh.face_coordinates(mesh.get_any_face()), -0.1), 'edgecolor': '#ff0000'}]
217+ polygons = []
218+ lines = []
219+ for fkey in mesh .faces ():
220+ points = mesh .face_coordinates (fkey )
221+ offset = offset_polygon (points , 0.1 )
222+ polygons .append ({
223+ 'points' : offset ,
224+ 'edgecolor' : '#ff0000'
225+ })
226+ for a , b in zip (points , offset ):
227+ lines .append ({
228+ 'start' : a ,
229+ 'end' : b ,
230+ 'color' : '#00ff00'
231+ })
221232
222233 plotter = MeshPlotter (mesh )
223234 plotter .draw_faces ()
224235 plotter .draw_polygons (polygons )
236+ plotter .draw_lines (lines )
225237 plotter .show ()
0 commit comments