2
$\begingroup$

OK, so I got my ships moving along the bezier in time T, now I need to factor in acceleration, but I don't really know how to do it.

I'm using the DeCasteljau Algorithm, that's what my code looks like:

function linp(d, a, b, t) {
    d.x = a.x + (b.x - a.x) * t;
    d.y = a.y + (b.y - a.y) * t;
}

// a, b, c, d are the 4 controls points, dest will contain the x/y coordinates and t is the time value from 0.0 to 1.0
Ship.prototype.bezier = function(dest, a, b, c, d, delta) {
    var ab = {x:0, y: 0}, bc = {x:0, y: 0}, cd = {x:0, y: 0};
    var abbc = {x:0, y: 0}, bccd = {x:0, y: 0};
    linp(ab, a, b, t);
    linp(bc, b, c, t);
    linp(cd, c, d, t);
    linp(abbc, ab, bc, t);
    linp(bccd, bc, cd, t);
    linp(dest, abbc, bccd, t);
};

So the question is, what is a simple way to factor in the acceleration from the starting speed to the end speed?

Update:
Here's a small video how the thing looks when it's not working. I hope this helps.

http://www.youtube.com/watch?v=EIJg1WFbjh4

  • 0
    Could you please clarify what exactly do you mean by "factoring in the acceleration"? The expression for curvature (and thus acceleration) will depend on what parametrization you're using.2010-11-05
  • 0
    The object starts to move along the bezier with speed X and then accelerates until it reaches speed Y at the end. Right now the object moves along the path with constant speed based on time T. I hope that's a bit more clear.2010-11-05
  • 0
    What sort of acceleration are you expecting? Replacing the parameter t with any smooth function like $t^{\alpha}$ (I'm assuming here that $0\leq t\leq 1$ as is usual with such applications) should allow you to vary the acceleration as you please.2010-11-05
  • 0
    Linear acceleration would be just fine, I gonna look up smooth functions, and yes I admit, I'm not that big into maths, so sorry if the question maybe really simple.2010-11-05
  • 0
    OK so I looked up smooth functions but I can't find one that behaves like I want, the object has a long movement pause at the beginning and the end when I use something like: `x * x * (3 - 2 * x)`2010-11-05
  • 0
    Here's a video of my problem: http://www.youtube.com/watch?v=EIJg1WFbjh4 Just take a look at the ship when it travels between planets.2010-11-05
  • 0
    Well, if you're going to try out a bunch of smooth functions, you would want them to satisfy certain constraints. For instance, if the original range of the parameter is $[0,1]$, then you would want your smooth function to return 0 for 0 argument, and similarly for the other end.2010-11-05
  • 0
    I had such a function, but it still didn't work correctly the ship still had those long pauses at the beginning / end, for my part I've given up on this, I spent 4 hours on it, that's just too much, hope somebody posts a solution because google doesn't help in any way, at least not for me, as I don't really know what to search for.2010-11-05
  • 0
    Have you tried parametrizing with $\sqrt{t}$? Or exponents less than 1 in general?2010-11-05

2 Answers 2

2

OK, got it figured out my self, before including the acceleration I first had to parameterize the curve itself, you can read all the stuff over at my gamedev question:

https://gamedev.stackexchange.com/questions/5373/moving-ships-between-two-planets-along-a-bezier-missing-some-equations-for-accel

1

For each component (x,y)

linp(acc, 6*(a-2*b+c), 6*(b-2*c+d), t)

Obviously linp is the linear interpolation between two values. The bezier is constructed form a sequence of linear inerpolations as shown here. Bezier Definition

The linp module can be made into a well defined function $\mathrm{L}(a,b,t)=a+t\,(b-a)$, with known derivatives. All you have to do is calculate the following

$$ \mathrm{bez}(a,b,c,d,t)=\mathrm{L}( \mathrm{L}( \mathrm{L}(a,b,t), \mathrm{L}(b,c,t), t), \mathrm{L}( \mathrm{L}(b,c,t), \mathrm{L}(c,d,t), t) ) $$ $$ \mathrm{acc}(a,b,c,d,t)=\frac{\mathrm{d}^2}{\mathrm{d}t^2}{\mathrm{bez}(a,b,c,d,t)} $$

With the derivative

$$ \frac{\mathrm{d}}{\mathrm{d}t}{L(f(t),g(t),t) = (1-t)\frac{\mathrm{d}f}{\mathrm{d}t}+t\frac{\mathrm{d}g}{\mathrm{d}t}-f(t)+g(t)} $$

The rest is just math.