Search code examples
performanceactionscript-3mathcurve

Curve Programmatically Calculated?


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).


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