我想做这样的事情:

我有要点,但不知道如何绘制曲线而不是直线。

谢谢你。

最佳答案

对于对此问题感兴趣的人,我遵循了Matthew的建议并提出了以下实现方案:

def hanging_line(point1, point2):
    import numpy as np

    a = (point2[1] - point1[1])/(np.cosh(point2[0]) - np.cosh(point1[0]))
    b = point1[1] - a*np.cosh(point1[0])
    x = np.linspace(point1[0], point2[0], 100)
    y = a*np.cosh(x) + b

    return (x,y)

结果如下所示:
import matplotlib.pyplot as plt

point1 = [0,1]
point2 = [1,2]
x,y = hanging_line(point1, point2)

plt.plot(point1[0], point1[1], 'o')
plt.plot(point2[0], point2[1], 'o')
plt.plot(x,y)

python - 画一条连接两个点而不是一条直线的曲线-LMLPHP

关于python - 画一条连接两个点而不是一条直线的曲线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30008322/

10-12 23:06