本文介绍了画一条连接两个点而不是一条直线的曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情:

I want to do something like this:

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

I have the points but don't know how to plot the curves instead of straight lines.

谢谢.

推荐答案

对于对这个问题感兴趣的人,我按照 Matthew 的建议提出了这个实现:

For people interested in this question, I followed Matthew's suggestion and came up with this implementation:

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)

这篇关于画一条连接两个点而不是一条直线的曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 16:51