生成曲线多边形

2024-10-17 06:25:08 发布

您现在位置:Python中文网/ 问答频道 /正文

如何向多边形的顶点和边添加曲率

我正在尝试创建一些曲线多边形,例如curved verticescurved edge shapeseven both

您将如何生成这些形状。 我已经研究过贝塞尔曲线,但它们似乎非常复杂,我想知道在我使用这种方法之前是否有更简单的解决方案

如果有人需要一个起点,下面是我生成多边形的代码

def gen_poly(sides, radius=1, rotation=0):
    seg = math.pi * 2 / sides
    x_list = []
    y_list = []
    for i in range(sides): 
        x = math.sin(seg * i + rotation) * radius
        y = math.cos(seg * i + rotation) * radius
        x_list.append(x)
        y_list.append(y)
    x_list.append(x_list[0])
    y_list.append(y_list[0]) 
    return x_list,y_list
x,y=polygon(5) 

fig = plt.figure()
ax = plt.subplot(111)
ax.plot(x, y, marker='.')
plt.xlabel('x')
plt.ylabel('y')
plt.show()

Tags: pltmathax多边形曲线list顶点vertices