Monday, January 13, 2020

mathematics - non-linear interpolation


I have an object, and i want to interpolate its position between two points over a given time period; but i dont want it to be a linear interpolation. I'm not sure if i'm phrasing this right.


vector posA; // Where we start
vector posB; // Where we end
float timeI; // An interval from 0 - 1

normally i would just do it linearly



vector currentPos = posA  + (posB - posA) * timeI

but i want the object to either:



  • a) move faster at the start and slower at the end

  • b) move slower at the start and faster at the end


Can anybody point me in the right direction



Answer



One way to move slower at the start and faster towards the end would be to square the time:



vector currentPos = posA  + (posB - posA) * (timeI * timeI)

If you look at this graph (wolfram) you can see why this works.


To move faster at the start and slower at the end:


float t = 1 - timeI
vector currentPos = posA + (posB - posA) * t * t

No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...