听起来你的"弧"是两个已知点之间的曲线的圆形近似.我在你的帖子中用"直径"(这是半径的两倍)这个词来猜测.要执行此操作,请参考从哪里开始的圆圈 .给定一个中心,两个端点和一个半径,我们可以近似曲线的一部分,如下所示:(t) -> (x,y)
t
0..2pi
from numpy import cos,sin,arccos
import numpy as np
def parametric_circle(t,xc,yc,R):
x = xc + R*cos(t)
y = yc + R*sin(t)
return x,y
def inv_parametric_circle(x,xc,R):
t = arccos((x-xc)/R)
return t
N = 30
R = 3
xc = 1.0
yc = 3.0
start_point = (xc + R*cos(.3), yc + R*sin(.3))
end_point = (xc + R*cos(2.2), yc + R*sin(2.2))
start_t = inv_parametric_circle(start_point[0], xc, R)
end_t = inv_parametric_circle(end_point[0], xc, R)
arc_T = np.linspace(start_t, end_t, N)
from pylab import *
X,Y = parametric_circle(arc_T, xc, yc, R)
plot(X,Y)
scatter(X,Y)
scatter([xc],[yc],color='r',s=100)
axis('equal')
show()
Run Code Online (Sandbox Code Playgroud)
此示例仅在2D中,但它很容易适应,因为曲线始终位于两点和中心之间的平面上.