Home > Mobile >  How to measure and modify length of path?
How to measure and modify length of path?

Time:03-10

I am trying to create paths with mathplotlib.path, more precisely n-gons. Although I would like to add the constraint that all polygons have the same perimeter. In order to do that I would have to calculate the perimeter of the polygon, and the adjust the path length to a fixed variable.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.path as mpltPath

N = 10000
points = np.random.rand(N,2)

# regular polygon
sidepoly = 5
polygon = [[np.sin(x),np.cos(x)] for x in np.linspace(0, 2*np.pi, sidepoly)[:sidepoly]]

# Matplotlib mplPath

path = mpltPath.Path(polygon)

fig, ax = plt.subplots()
patch = patches.PathPatch(path, facecolor='none', lw=2)

ax.add_patch(patch)
ax.axis('equal')
ax.set_xlim(-1,1)
ax.set_ylim(-1,1)

plt.show()

Any recomendations?

CodePudding user response:

The side length of a regular polygon can be calculated via twice the sine of half the angle (see e.g. regular polygons with fixed perimeter

  • Related