我正在使用贝塞尔曲线作为我的宇宙飞船进入车站停靠时的路径。我有一个简单的算法来计算船舶在时间 t 沿三次贝塞尔曲线的位置:
public class BezierMovement{
    public BezierMovement(){
        // start docking straight away in this test version
        initDocking();
    }
    private Vector3 p0;
    private Vector3 p1;
    private Vector3 p2;
    private Vector3 p3;
    private double tInc = 0.001d;
    private double t = tInc;
    protected void initDocking(){
        // get current location
        Vector3 location = getCurrentLocation();
        // get docking point
        Vector3 dockingPoint = getDockingPoint();
        // ship's normalised direction vector
        Vector3 direction = getDirection();
        // docking point's normalised direction vector
        Vector3 dockingDirection = getDockingDirection();
        // scalars to multiply normalised vectors by 
        // The higher the number, the "curvier" the curve
        float curveFactorShip = 10000.0f;
        float curveFactorDock = 2000.0f;
        p0 = new Vector3(location.x,location.y,location.z);
        p1 = new Vector3(location.x + (direction.x * curveFactorShip),
                         location.y + (direction.y * curveFactorShip),
                         location.z + (direction.z * curveFactorShip));
        p2 = new Vector3(dockingPoint.x + (dockingDirection.x * curveFactorDock),
                         dockingPoint.y + (dockingDirection.y * curveFactorDock),
                         dockingPoint.z + (dockingDirection.z * curveFactorDock));
        p3 = new Vector3(dockingPoint.x, dockingPoint.y, dockingPoint.z);
    }
    public void incrementPosition() {
        bezier(p0, p1, p2, p3, t, getCurrentLocation());
        // make ship go back and forth along curve for testing              
        t += tInc;
        if(t>=1){
            tInc = 0-tInc;
        } else if(t<0){
            tInc = 0-tInc;
        }
    }
    protected void bezier(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, double t, Vector3 outputVector){
        double a = (1-t)*(1-t)*(1-t);
        double b = 3*((1-t)*(1-t))*t;
        double c = 3*(1-t)*(t*t);
        double d = t*t*t;
        outputVector.x = a*p0.x + b*p1.x + c*p2.x + d*p3.x;
        outputVector.y = a*p0.y + b*p1.y + c*p2.y + d*p3.y;
        outputVector.z = a*p0.z + b*p1.z + c*p2.z + d*p3.z;
    }
}
曲线起点为飞船所在位置,终点为对接舱入口(图中红点)。宇宙飞船的方向有一个归一化向量,停靠舱有另一个归一化向量来指示飞船必须行进的方向,以便在它到达时直接对准停靠舱(图表上的黄线)
绿线是飞船的可能路径,紫色圆圈是飞船的半径。最后,黑框是车站的边界框。

我有两个问题:
- 宇宙飞船应该只能以每秒 r 弧度转动
- 宇宙飞船无法飞过空间站
我假设这转化为:
一种)。找到“曲线因素”(控制点长度),这将给出一条船不必转弯太紧的路径
乙)。找到它无法避免与空间站相撞的宇宙飞船位置/方向(并创建一条路径将其引导出该状态,因此它可以继续进行 a))
但是,对于这两种情况,我没有太多运气找到解决方案。我已经有代码来检测向量、框、点和球体之间的交叉点,但还没有贝塞尔曲线。我还有一些功能可以让我找到两点之间的距离。
非常感激任何的帮助
谢谢,詹姆斯