【问题标题】:Python Finite difference SplinePython 有限差分样条
【发布时间】:2016-01-11 23:28:16
【问题描述】:

我正在尝试使用有限差分方法制作一个可以在它们之间进行点和插值的程序。它必须能够返回 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 python-3.x spline


    【解决方案1】:

    这不是一个完整的答案——而是在您开始之前先了解一下 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有点陌生
    猜你喜欢
    • 2013-09-30
    • 2017-08-09
    • 1970-01-01
    • 2016-06-24
    • 2015-08-24
    • 2016-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多