Skip to content

Commit 34db4aa

Browse files
committed
add plot_poly() primitive
1 parent 913c9b9 commit 34db4aa

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎spatialmath/base/graphics.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,26 @@ def plot_box(
382382

383383
return [r]
384384

385+
def plot_poly(vertices, *fmt, close=False,**kwargs):
386+
387+
if close:
388+
vertices = np.hstack((vertices, vertices[:, [0]]))
389+
return _render2D(vertices, fmt=fmt, **kwargs)
390+
391+
392+
def _render2D(vertices, pose=None, filled=False, ax=None, fmt=(), **kwargs):
393+
394+
ax = axes_logic(ax, 2)
395+
if pose is not None:
396+
vertices = pose * vertices
397+
398+
if filled:
399+
r = plt.Polygon(vertices.T, closed=True, **kwargs)
400+
ax.add_patch(r)
401+
else:
402+
r = plt.plot(vertices[0, :], vertices[1, :], *fmt, **kwargs)
403+
return r
404+
385405

386406
def circle(centre=(0, 0), radius=1, resolution=50):
387407
"""

0 commit comments

Comments
 (0)