Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions formula of linear interpolation

  • formula of linear interpolation

    Posted by Micheel Leavitt on September 1, 2009 at 6:43 am

    I am curious as to how the linear() interpolation method works in After Effects. I did a little research on interpolation and everything I saw assumed you were simply finding all of the values between two known points, not what the newly “remapped” points were. I guess I’m asking what the formula is to turn t_min and t_max to value1 and value2, in algebra, or where I could find this formula online. I have probably seen it but did not recognize it for what it was, so I thank anyone in advance for any insight on this!

    Micheel Leavitt replied 16 years, 8 months ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    September 1, 2009 at 1:06 pm

    Hmmm…. I’m not really sure what you’re asking. A formula that does the same thing as linear would look like this:

    result = value1 + ((t – t_min)/(t_max – t_min))*(value2 – value1);

    Except that linear() clamps the values so you’d really have to add something like this:

    clamp(result,value1,value2)

    Dan

  • Micheel Leavitt

    September 1, 2009 at 6:03 pm

    I suppose I should have made it clear that I was looking to explain this on paper, rather than in code. However, I think what you showed is what I am looking for, and I noticed while doing some research that linear interpolation is not exact, so that must be why you said to use clamp() to constrain the values. If it helps people understand what I’m asking, I was working on farenheit/celcius conversions and I was curious as to how they came across the formula for conversion, and if there was a function that would take any set of values and “remap” it to another set of values. I know this is basically what interpolation methods do, so like I said I think you answered my question. Thanks a lot Dan!

  • Dan Ebberts

    September 1, 2009 at 8:10 pm

    >…linear interpolation is not exact, so that must be why you said to use clamp() to constrain the values.

    No, you would use clamp if you really wanted to mimic the functinality of linear(), which will only generate values between value1 and value2, unlike the equation for a line, which will generate values anywhere on the line.

    If you’re interested in doing Farenheit/Celsius conversions, you’d be better off with the eqations for the lines, like this:

    degreesC = (degreesF – 32)*(5/9);

    and,

    degreesF = 1.8*degreesC + 32;

    Dan

  • Micheel Leavitt

    September 2, 2009 at 6:37 am

    Thank you for the conversion formula, but it was in the book already 🙂
    However, the formula you provided earlier:

    result = value1 + ((t – t_min)/(t_max – t_min))*(value2 – value1);

    was exactly what I was looking for, but I am still a little lost as to what exactly the need for clamp is. If result would always be between value1 and value2, then why would you have to clamp it? So there must be certain situations where this formula would generate numbers slightly higher or lower than value1 and value2, right? Thats what I meant by it not being exact. This code looks very similar to the formula at

    https://en.wikipedia.org/wiki/Linear_interpolation

    and it also talked about an error margin, but I don’t think they were the same. But thank you Dan for your insight so far, and if you have another way to explain the need for clamp that would be great!

  • Filip Vandueren

    September 2, 2009 at 10:23 am

    as long as t is within tmin and tmax the output is naturally clamped, meaning results will always be within value1 and value2

    But what happens when you keep increasing t ?
    Using the formula, results keep going ‘in the same direction’ as between tmin and tmax, resulting in values beyond value1 and value2. Because the formula describes a line.

    clamping t or clamping value has the same effect as the linear() method.
    Actually clamping t is a bit easier, because you know it’s always going to be a 1dimensional number.

  • Micheel Leavitt

    September 2, 2009 at 5:15 pm

    Ah, I see the connection now. When you calculate this in AE, it will continue on without stopping because time is not constrained. Thank you for the help, I was having trouble grasping that for some reason. I’m doing most of this on paper and proving it in After Effects. I was talking to my teacher about it and she couldn’t understand what I was asking, so now I can explain what my babbling was about on Monday 🙂 Thanks for the help Dan and Filip!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy