Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Math 具有3个给定点的三维插值(等距)_Math_Computational Geometry_Interpolation - Fatal编程技术网

Math 具有3个给定点的三维插值(等距)

Math 具有3个给定点的三维插值(等距),math,computational-geometry,interpolation,Math,Computational Geometry,Interpolation,我正在开发一个3D国际象棋游戏,其中我需要能够计算轨迹的位置X,Y,Z,这个轨迹将描述一条抛物线(用于棋子动画) 因此,对于给定的等距点p1=(x1,y1,z1),p2=(x2,y2,z2)和p3(x3,y3,z3),我需要下面的公式(或一般公式): 对于每个组件 x, y和 z >代码>考虑由定义的单独抛物线。 x(t) = x1 - t*(3*x1-4*x2+x3) + 2*t^2*(x1-2*x2+x3) //t=0..1 y(t) = y1 - t*(3*y1-4*y2+y3)

我正在开发一个3D国际象棋游戏,其中我需要能够计算轨迹的位置X,Y,Z,这个轨迹将描述一条抛物线(用于棋子动画)

因此,对于给定的等距点p1=(x1,y1,z1),p2=(x2,y2,z2)和p3(x3,y3,z3),我需要下面的公式(或一般公式):


对于每个组件<代码> x<代码>,<代码> y和<代码> z >代码>考虑由

定义的单独抛物线。
x(t) = x1 - t*(3*x1-4*x2+x3) + 2*t^2*(x1-2*x2+x3)     //t=0..1
y(t) = y1 - t*(3*y1-4*y2+y3) + 2*t^2*(y1-2*y2+y3)     //t=0..1
z(t) = z1 - t*(3*z1-4*z2+z3) + 2*t^2*(z1-2*z2+z3)     //t=0..1

t=0
然后
x=x1
,在
t=0.5
然后
x=x2
t=1
然后
x=x2
。类似地,对于
y(t)
z(t)

如果开始和结束的y值相同,则可以使用参数方程来描述抛物线,该方程可以通过几个步骤导出

给定起始高度和最大高度

y(t) = A(t^2) + B(t) + C
y(0) = startingHeight
y(0.5) = apexHeight
y(1) = startingHeight

y(0) = startingHeight = A*0 + B*0 + C
C = startingHeight
y(t) = A(t^2) + B(t) + startingHeight

y(1) = startingHeight = A + B + startingHeight
0 = A+B
A = -B
y(t) = -B(t^2) + B(t) + startingHeight

y(0.5) = apexHeight = -B(0.25) + B(0.5) + startingHeight
apexHeight = B(0.5 - 0.25) + startingHeight
apexHeight - startingHeight = B(0.25)
B = (apexHeight - startingHeight)/4.0
现在您知道了A、B和C,可以为y编写方法:

function y(startingHeight, apexHeight, t){
    B = (apexHeight - startingHeight) / 4;
    A = -B;
    C = startingHeight;
    return A*t*t + B*t + C;
}
x和z更容易,因为它们只是从开始到结束线性增加:

x(t) = At + B
x(0) = startX
x(1) = endX

x(0) = startX = A*0 + B
B = startX
x(t) = At + startX

x(1) = endX = A*1 + startX
A = endX - startX

x(t) = (endX - startX) * t + startX
(z的公式与x相同-只需将所有x替换为z即可)

现在您可以在时间t找到棋子的3d位置:

function parabola(xBegin, xEnd, zBegin, zEnd, yStart, yApex, t){
    return [x(xBegin,xEnd,t), y(yStart,yApex,t), z(zBegin,zEnd,t)];
}

p1、p2和p3位于抛物线上,p2是顶点?很明显!!p1是原点,p2是顶点,p3是终点。如果
p2
正好是顶点,那么问题就过度约束了。你需要把它们看成是抛物线中的三点,我想这篇文章会回答你的问题。你是说《星际迷航》中的3d国际象棋吗?或者它是一个普通的单平板,但渲染为3d?如果电路板是平面的,则方程式更容易推导,例如,
y1==y3
我上一节几何课已经很久了,但是。。。我怀疑(但无法证明)用多项式表示x(t)和z(t)会稍微扭曲抛物线,从侧面看。我想你需要x和z的线性函数来得到一条实际的抛物线。然而,我认为你的方程仍然会给出一个很好的曲线形状,这可能会满足OP的需要。非常感谢,它工作得很好。它非常简单明了。它甚至比我预期的要好,因为我只能通过测试t而不是当前点的X,Y,Z来停止动画。
function x(start, end, t){
    A = (end - start);
    B = start;
    return A*t + B;
}

function z(start, end, t){
    A = (end - start);
    B = start;
    return A*t + B;
}
function parabola(xBegin, xEnd, zBegin, zEnd, yStart, yApex, t){
    return [x(xBegin,xEnd,t), y(yStart,yApex,t), z(zBegin,zEnd,t)];
}