Java CATM样条曲线和其他平滑路径

Java CATM样条曲线和其他平滑路径,java,math,libgdx,curve,catmull-rom-curve,Java,Math,Libgdx,Curve,Catmull Rom Curve,我一直在研究如何让一个物体在二维平面上沿着由几个控制点定义的平滑曲线运动。根据我的发现,我正在寻找一条曲线 我一直在为我的项目使用LibGDX,它有自己的Catmull-Rom样条线实现,但我很难理解它是如何工作的,因为我很难找到使用LibGDX实现Catmull-Rom样条线的文档或其他源代码 我正在寻找LibGDX-Catmull-Rom样条线实现的解释,或者寻找使用Catmull-Rom样条线或其他方法实现平滑路径的另一种方法,该路径实现控制点。我要寻找的是生成路径并传回该路径上点的x和y

我一直在研究如何让一个物体在二维平面上沿着由几个控制点定义的平滑曲线运动。根据我的发现,我正在寻找一条曲线

我一直在为我的项目使用LibGDX,它有自己的Catmull-Rom样条线实现,但我很难理解它是如何工作的,因为我很难找到使用LibGDX实现Catmull-Rom样条线的文档或其他源代码

我正在寻找LibGDX-Catmull-Rom样条线实现的解释,或者寻找使用Catmull-Rom样条线或其他方法实现平滑路径的另一种方法,该路径实现控制点。我要寻找的是生成路径并传回该路径上点的x和y坐标的能力。如果有人有任何建议或建议,我们将不胜感激。谢谢

libgdx路径类(包括CatmullRomSpline)适用于二维和三维。因此,在创建CatmullRomSpline时,必须指定要使用的向量(Vector2或Vector3):

例如:

float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
Vector2 cp[] = new Vector2[]{
    new Vector2(0, 0), new Vector2(w * 0.25f, h * 0.5f), new Vector2(0, h), new Vector2(w*0.5f, h*0.75f),
    new Vector2(w, h), new Vector2(w * 0.75f, h * 0.5f), new Vector2(w, 0), new Vector2(w*0.5f, h*0.25f)
};
CatmullRomSpline<Vector2> path = new CatmullRomSpline<Vector2>(cp, true);
Vector2 position = new Vector2();
float t = 0;
public void render() {
    t = (t + Gdx.graphics.getDeltaTime()) % 1f;
    path.valueAt(position, t);
    // Now you can use the position vector
}

这里有一个例子:

我发现Catmull Rom产生了我不想要的循环和工件。这里讨论的向心参数化版本提供了更好的结果:可用的DerivativeEat可以做什么?你能指出一些对此有很好理解的地方吗?这个(CatmullRomSpline)似乎不再起作用了:CatmullRomSpline类型不是泛型;无法使用参数对其进行参数化。@MennoGouw截至此注释,它已由Vector类参数化。
Vector2 position = new Vector2();
float t = a_vulue_between_0_and_1;
path.valueAt(position, t);
Vector2 position = new Vector2();
float t = 0;
public void render() {
    t = (t + Gdx.graphics.getDeltaTime()) % 1f;
    path.valueAt(position, t);
    // Now you can use the position vector
}