Sign in to follow this  
Merlino

Animation Math

Recommended Posts

Merlino    122
Hi, I am rather new to programming and I have a question about animation. Here's a theoric example: imagine that there are 2 variables and one evolves based on the other one, let's say that the width of a rectangle on screen evolves based on time.
So, when time is equal to a, width is equal to d, when time is equal to b, width is equal to e and so on. Imagine I know the values of a, b, c, d and f. How do I calculate e based on these values? Thanks in advance, Merlino Edit: please post only once; the Forum FAQ contains useful information about how to format your post (I mean, images are enclosed by normal <img> tags) -- .ED

Share this post


Link to post
Share on other sites
It really depends on the function F that maps a to d: F(a) = d, F(c) = f;

If you know F(), it'q quite easy to compute F(b) = e. If you don't know F(), it's tricky, maybe impossible.

Share this post


Link to post
Share on other sites
gjoel    144
This depends on how it "evolves". What you're getting into here is called "interpolation", and there are several different ways to do this.



Assuming you just want to do linear interpolation (the first one), simply find the interval you're in, and weigh each point with the distance (in time) from you current point... something like:

//data
float a = 0.0f;
float b = 1.0f;
float d = 14.0f;
float e = 20.0f;

//interpolation
float cur_point = 0.5f;
float t = (cur_point-a)/(b-a); //you need to find a and b first...
float width_e = t*e + (1.0f-t)*d; //linear interpolation (lerp)


Hope this helps

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this