gpt4 book ai didi

python - 绘制连接两点的曲线而不是直线

转载 作者:太空狗 更新时间:2023-10-30 02:44:20 36 4
gpt4 key购买 nike

我想做这样的事情:
enter image description here

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

谢谢。

最佳答案

对于对这个问题感兴趣的人,我听从了 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)

§1

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

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com