Question

How can I calculate y in this curve ? t is the variable. Origin is (0|0) of course.

  • the tangents at t=0, t=0,5 and t=1 must be perfectly horizontal (incline = 0)
  • only basic mathematical operators are available (Java / Actionscript 3)

enter image description here

I have to calculate this a few hundred times each frame in Actionscript 3. So calculation needs good performance. Right now I'm actually failing at correctness of calculation (I'm not a mathematician).

Was it helpful?

Solution

Not sure about performance, but

-0.5 * cos(x * 2pi) + 0.5

AS3:

y = -0.5 * Math.cos(x * 2 * Math.PI) + 0.5;

seems to be the curve you are looking for.

enter image description here

You can view or edit the curve here: wolfram alfa curve

OTHER TIPS

The function suggested by bjornson (-0.5*cos(x) + 0.5) looks good.

One idea to improve performance is that you at the start of your application create a table of the values of that function at different times.

If you use fix timesteps, then the table is all you'll need. If you have variable time steps, then you can just do linear interpolation between the two closest times to the time you're calculating.

y(t) = 16 * t * t * (t - 1) * (t - 1)

I reckon that one satisfies your requirements

I tried my own way and I came up with a polynomial:

y = 16 * (t - 0.5)^4 - 8 * (t - 0.5)^2 + 1
y = 16 * Math.pow((t - 0.5), 4) - 8 * Math.pow((t - 0.5), 2) + 1;
// forgot to shift the curve 0.5 to the right, corrected
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top