Results 1 to 7 of 7

Math Help - Modify function from linear to an increasing curve

  1. #1
    Newbie
    Joined
    Oct 2012
    From
    Österreich
    Posts
    4

    Post Modify function from linear to an increasing curve

    Hi, I have a little problem with functions and curves. When it comes to statistics, functions and curves I'm a really noob, so I hope this is the right forum.

    Some background information: I'm developing a game where objects move across the y-axis according to the passed time. These objects are stored in a 2d matrix. If I move them by one position in the matrix, the objects would "jump" from y(5) to y(6) but I want fluent animation between y(5) and y(6).

    So I have created this function: y = (S / D x) - S
    S and D are two constants: The size of the moving object and the duration of one gamestep in ms.
    x describes the passed time.

    I've decreased by S because I needed the result to be negative to zero.

    The object moves fluently but this is not exactly what I wanted. I want the movement between two matrix positions start rather slowly (nearly stop at the begin) and get very fast to the end. This way the user can better distinguish if the block is actually at y(5) or y(6) and also get the illusion of fluent animation.

    This image should make it clearer: (S = 25; D = 100)

    Modify function from linear to an increasing curve-c3f32ac11a9428a2df43f6b1c804adf5.png

    The black line is what I have now. The red line is what I would like to have (or similar).


    As I already said I'm really bad at such things, so I hope someone can help me with that problem.

    Thanks in advance!
    Last edited by DevGuy; October 21st 2012 at 03:27 AM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Newbie
    Joined
    Oct 2012
    From
    Österreich
    Posts
    4

    Re: Modify function from linear to an increasing curve

    Nevermind got the solution myself.

    While looking at mathematical functions and graphs I found the power function, which seemed perfectly for my problem. Now I needed to get it to cross my two points P(0|-25) and Q(100|0).

    I started with the normal formula y = a * xn. Using 4 as n would make the curve start very late and make that nice stop effect at the beginning of every movement.
    Now inserting the two known constants, I get: 25 = a * 1004. Reforming that sentence gives me a = 0.00000025.

    With that I was able to recreate my formula and use it in my game:

    y = S / D4 * x4 - S
    Follow Math Help Forum on Facebook and Google+

  3. #3
    MHF Contributor
    Joined
    May 2010
    Posts
    1,027
    Thanks
    28

    Re: Modify function from linear to an increasing curve

    if you make the speed get very fast towards the end then it is going to stop rather abruptly at that point, perhaps you should consider nan animation which is slow at both ends.

    In any case, for something that starts slow and ends fast, you can do this:

    define:
    t = the current time (0 at start of animation)
    T = the total desired time for the animation
    x_start = the starting x coord
    x_finish = the finishing x coord
    y_start = the starting x coord
    y_finish = the finishing y coord
    x(t),y(t) the coordinates at time t.

    let w(t) = \frac{e^t - e^T }{1-e^T}

    and finally:
    x(t) = w(t)x_{start} + \left(1-w(t) \right)x_{finish}
    y(t) = w(t)y_{start} + \left(1-w(t) \right)y_{finish}

    edit: this was written while you were doing post#2 so you can ignore it.
    Last edited by SpringFan25; October 21st 2012 at 11:31 AM.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    Oct 2012
    From
    Österreich
    Posts
    4

    Re: Modify function from linear to an increasing curve

    Thank you very much! Your solution works also very good.

    I'm interested in "nan" animation? Could you explain that?
    Follow Math Help Forum on Facebook and Google+

  5. #5
    MHF Contributor
    Joined
    May 2010
    Posts
    1,027
    Thanks
    28

    Re: Modify function from linear to an increasing curve

    "nan" is a typo. my post should have said "an animation that is slow at both ends".

    To implement this you could change the definition of w(t) to:
    w(t) = \frac{1-\sin(\frac{\pi t}{T} -0.5 \pi)}{2}

    Make sure that whatever programming language you use expects the argument of the sin() function to be measured in radians not degrees, otherwise the above wont work.
    Last edited by SpringFan25; October 21st 2012 at 03:25 PM.
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Newbie
    Joined
    Oct 2012
    From
    Österreich
    Posts
    4

    Re: Modify function from linear to an increasing curve

    Hadn't thought of a typo

    That new formula also makes a very nice effect but I think I will stick to the simpler formula.
    Sinus operations are way too heavy for such a trivial feature (especially on mobile devices).

    Thanks for all SpringFan!
    Follow Math Help Forum on Facebook and Google+

  7. #7
    MHF Contributor
    Joined
    May 2010
    Posts
    1,027
    Thanks
    28

    Re: Modify function from linear to an increasing curve

    something slow at both ends but not computationally intensive would be:

    w(t) = 3\frac{t^2}{T^2} - 2\frac{t^3}{T^3}
    Last edited by SpringFan25; October 25th 2012 at 03:26 AM.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 1
    Last Post: November 14th 2010, 06:45 PM
  2. Replies: 5
    Last Post: September 15th 2010, 08:12 AM
  3. Increasing Function
    Posted in the Calculus Forum
    Replies: 1
    Last Post: September 16th 2009, 04:51 AM
  4. increasing function
    Posted in the Differential Geometry Forum
    Replies: 8
    Last Post: August 11th 2009, 08:04 PM
  5. Modify TI89 Menus
    Posted in the Calculators Forum
    Replies: 2
    Last Post: May 6th 2009, 04:35 PM

Search Tags


/mathhelpforum @mathhelpforum