2
votes

I'm developing a 3D chess game in which I need to be able to calculate positions X,Y,Z of a trajectory in a way that this trajectory will describe a parabola (for the pieces animation).

Thus I need the formulas below (or the general formula) for the given equidistant points p1=(x1,y1,z1), p2=(x2,y2,z2) and p3(x3,y3,z3):

x=f(y,z)=???  
y=f(x,z)=???   
z=f(x,y)=???
2
p1, p2 and p3 lie on the parabola and p2 is the apex? - Ani
exacly!! p1 is the origin, p2 the apex, and p3 the end. - Andrade
The problem is over-constrained if p2 is exactly the apex. You need to consider them just three points in space belonging to a parabola. - John Alexiou
I think this other SO post will answer the question for you. stackoverflow.com/questions/4039039/… - Ani
Do you mean 3d chess as in multiple boards at different elevations, as seen on star trek for example? Or is it a normal single flat board, but rendered in 3d? The equations are easier to derive if the board is flat, e.g. y1 == y3 - Kevin

2 Answers

4
votes

For each component x, y and z consider a separate parabola defined by

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

at t=0 then x=x1, at t=0.5 then x=x2 and at t=1 then x=x2. Similarly for y(t) and z(t).

3
votes

If the beginning and ending y values are the same, you can describe the parabola using a parametric equation which can be derived in a few steps.

given startingHeight and apexHeight,

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

Now that you know A,B, and C, you can write the method for y:

function y(startingHeight, apexHeight, t){
    B = (apexHeight - startingHeight) / 4;
    A = -B;
    C = startingHeight;
    return A*t*t + B*t + C;
}

x and z are easier, since they just increase linearly from start to end:

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 has a formula identical to x - just replace all x's with z's)

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;
}

Now you can find the 3d position of the chess piece at time t:

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