Python 有限差分样条

标签 python python-3.x spline

我正在尝试制作一个程序,可以使用有限差分方法在它们之间进行点和插值。它必须能够返回 xy 坐标,以便可以将其绘制到屏幕

我的样条线类:

class Spline():
    def __init__(self):
        self.x = 1
        self.y = 1
        self.p = []
        self.l = []
        self.s = []
        self.Width = 2
        self.Color = "#000"
    def AddPoints(self,*a):
        self.p.append(a)

    def DefineCurve(self,*a):
        for pp in a:
            self.s.append(pp)

    def DefineLine(self,*a):
        for pp in a:
            self.l.append(pp)

    def GetSpline(self):
        return self.s

    def GetLine(self):
        tL = []
        for a in self.l:
            tL.append(self.l[a])
        return tL

我愿意接受任何建议

最佳答案

这不是一个完整的答案,而是您开始之前的 Python 入门知识。也就是说,您应该更具体地阐述您的问题 - 它太宽泛,并且脱离上下文没有意义。
您打算用什么将其绘制到屏幕上?

class Spline():
    x = 1
    y = 1
    p = []
    l = []
    s = []
    Width = 2
    Color = "#000"
    def AddPoints(self,*a):
        self.p.append(a)

您知道,当您声明这样的属性时,它们是在此类的所有实例之间共享的 class 属性,不是吗?

要将它们正确声明为实例属性,您必须在方法内声明 then (__init__ 方法是一个不错的地方)

class Spline():
    def __init__(self):
        self.x = 1
        self.y = 1
        self.p = []
        self.l = []
        self.s = []
        self.Width = 2
        self.Color = "#000"

    def AddPoints(self,*a):
        self.p.append(a)

关于Python 有限差分样条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33115782/

相关文章:

python - 正则表达式 : Efficiently matching words that are the same except for last character

python - 从python多进程返回变量

python - Python 中的 SimpleQueue 与 Queue - 使用 SimpleQueue 的优势是什么?

python - 样条滤波和样条插值有什么区别?

3d - 根据与另一点的距离在贝塞尔曲线上查找点

scipy - scipy.interpolate.InterpolatedUnivariateSpline.get_coeffs 返回什么?

python pygame 如何淡入音量?

python - 关闭 QMainWindow 的正确方法

python - 如何使用 scikit-learn 对约束进行交叉验证

jquery - Python 脚本的 Web (Django) 中的 GUI