使用Python Matplotlib,使用起点、终点、中心和半径将圆弧绘制为多边形

使用Python Matplotlib,使用起点、终点、中心和半径将圆弧绘制为多边形,python,matplotlib,Python,Matplotlib,我使用了以下代码,仅输入了起点和终点: import matplotlib.pyplot as plt from matplotlib.path import Path import matplotlib.patches as patches start_point = (25, 50) end_point = (50, 25) center = (25, 25) radius = (25 # We need to some how automatically calculate this m

我使用了以下代码,仅输入了
起点
终点

import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches

start_point = (25, 50)
end_point = (50, 25)
center = (25, 25)
radius = (25
# We need to some how automatically calculate this midpoint
mid_point = (45, 45)
verts = [start_point, mid_point, end_point]
codes = [Path.MOVETO, Path.CURVE3, Path.CURVE3]#, Path.CLOSEPOLY]

path = Path(verts, codes)
shape = patches.PathPatch(path, facecolor='none', lw=0.75)
plt.gca().add_patch(shape)
plt.axis('scaled')
我得到以下输出

我需要以下输出(我使用
MS Paint
创建了以下输出)

[说明:将圆弧转换为以直线连接的点集。我需要这些点集作为列表]


要获得通过曲线(
CURVE3
CURVE4
)定义的路径上的坐标,可以使用
路径
.To_polygons()
方法。这将给出一个
nx2
形状的坐标数组

poly, = path.to_polygons()
plt.plot(*zip(*poly), marker="o", ls="None")


无法操纵由
.to\u polygon
创建的点数。如果这是一项要求,您可以改为从如下所示的给定点创建。在这里,我们沿着路径选择32个点

import matplotlib.pyplot as plt
import numpy as np
from scipy.special import binom

bernstein = lambda n, k, t: binom(n,k)* t**k * (1.-t)**(n-k)

def bezier(points, num=200):
    N = len(points)
    t = np.linspace(0, 1, num=num)
    curve = np.zeros((num, 2))
    for i in range(N):
        curve += np.outer(bernstein(N - 1, i, t), points[i])
    return curve

start_point = (25, 50)
end_point = (50, 25)
mid_point = (45, 45)

nodes1 = np.array([start_point, mid_point, end_point])
curve1 = bezier(nodes1, num=32)

plt.plot(curve1[:,0], curve1[:,1], color="red", ls="", marker="o", ms=3)
plt.axis('scaled')

plt.show()

我不明白这个问题。如果您已经创建了所需的输出,您需要什么帮助?我使用MS Paint创建了所需的输出(我已使用该信息编辑了问题)。我需要在
python
中使用
matplotlib
进行输出,谢谢您的快速回答。我们能决定在弧上形成的坐标数吗?这有什么参数吗?不幸的是,这似乎不可能。但是,您当然可以使用贝塞尔曲线创建自己的多边形。我更新了答案。太好了。这正是我需要的。干杯@ImportanceOfBeingErnest