在 Catmull-Rom 样条中使用相同坐标两次时出现的问题

Problems when using same coordinate twice in a Catmull-Rom Spline

我目前正在研究 Catmull-Rom 样条曲线,发现了一个我不确定如何解决的问题。所以当我用一个方法做Catmull的东西时,我必须给一个4分的ArrayList。但在某些情况下,我并不总是拥有这 4 个点,有时只有 2 个或 3 个。我认为我可以(在 2 个点的情况下)我可以将两个点相加两次以创建一条直线。每当我这样做时,我什么也没得到。我尝试调试,得到输出“NaN”。你们有人知道我能做什么吗?这是我用于公式的代码:

        ArrayList<Vector> newpoints = new ArrayList<>();
        Vector p0 = points.get(0);
        Vector p1 = points.get(1);
        Vector p2 = points.get(2);
        Vector p3 = points.get(3);

        double t0 = 0.0f;
        double t1 = getT(t0, p0, p1);
        double t2 = getT(t1, p1, p2);
        double t3 = getT(t2, p2, p3);

        for (double t=t1; t<t2; t+=((t2-t1)/(float)numberOfPoints))
        {
            Vector a1 = p0.clone().multiply((t1-t)/(t1-t0)).add(p1.clone().multiply((t-t0)/(t1-t0)));
            Vector a2 = p1.clone().multiply((t2-t)/(t2-t1)).add(p2.clone().multiply((t-t1)/(t2-t1)));
            Vector a3 = p2.clone().multiply((t3-t)/(t3-t2)).add(p3.clone().multiply((t-t2)/(t3-t2)));

            Vector b1 = a1.clone().multiply((t2-t)/(t2-t0)).add(a2.clone().multiply((t-t0)/(t2-t0)));
            Vector b2 = a2.clone().multiply((t3-t)/(t3-t1)).add(a3.clone().multiply((t-t1)/(t3-t1)));

            Vector c = b1.clone().multiply((t2-t)/(t2-t1)).add(b2.clone().multiply((t-t1)/(t2-t1)));

            newpoints.add(c);
        }
        return newpoints;
    }
    int numberOfPoints = 10;
    public double alpha = 0.5f;
    public double getT(double t, Vector p0, Vector p1) {
        double a = Math.pow((p1.getX()-p0.getX()), 2.0f) + Math.pow((p1.getY()-p0.getY()), 2.0f);
        double b = Math.pow(a, alpha * 0.5f);
        return (b + t);
    }```

尝试将“alpha”更改为 0.0f