Search code examples
algorithmmathanimationplatform-independent

what is the algorithm to determine x and y for something so that it follows a curve between 2 keyframes?


back in uni i remember there being an algorithm that's use to calculate the x and y position of point between the x and y values of 2 key frames, i know the one for a straight line

x = ((KeyFrame2.x - KeyFrame1.x)/duration)*time

my understanding is that the difference between the the 2 key frames divided by the duration give you how how many units of measurement (be it pixels mostly), for every unit of time (normally 1 frame) so you just multiply that value by how far though the timeline is

ie. x = ((KeyFrame2.x - KeyFrame1.x)/duration)*time
x = ((10 - 0)/10)*3
x = (10/10)*3
x = 1*3
x = 3 (after 3 units of time, the object's position will be +3 pixels along the x axis from KeyFrame1)

this one i understand however there i was also told about one that it used for curve paths, say a ball bouncing foward and the keyframes are when it hits the ground and when it's at the peek of it's bounce, this one is what i've forgotten and i have no idea where the hell my notes are for it

what i am asking is the algorithm used to calculate the x and y positions for an object with a path like this, i am asking for the mathematical algorithm which is code interdependent, what i'm trying to do is animate a number of orbs that will circle the center of the screen for a logo, i've got the objects in code to move however i need to adjust the calculations between keyframes

NOTE: even though i'm not asking for code, the algorithms are used in animation programming and as such my question relates to programming in general

NOTE2: KeyFrame2.x and KeyFrame1.x are not code, i see keyframes as an instance of a class which holds values such as x ,y, z, duration from previous frame ect


Solution

  • You're not asking for algorithms, you're asking for equations. You can use various equations based on what kind of motion you're simulating; for example, projectile motion under gravity is described by a parabola -- a curve of the form

    x = a * y^2 + b
    

    For motion controlled by some intelligent force, curve-fitting based on higher-order polynomials or Bezier curves are more appropriate. Google is your friend here.