Animation curve interpolation

Many application use angle-based tangents instead of proper weighted tangents with bezier interpolation. Maya can support weighted tangents and you’ll notice that although they require more performance to evaluate it is much, much more flexible.

Maya without weighted tangents & other software such as Unity3, apparently facefx and I think also Motion Builder use radians to define in and outgoing tangents. They are interpolated using hermit curves, which – if you Google them – are explained in a very confusing mathematical way.

So here’s a python function taking two key objects of type {‘time'<float>: time in arbitrary time unit (I use seconds), ‘value'<float>: value at this time, ‘inAngleRad'<float>: radians of incoming tangent, ‘outAngleRad'<float>: radians of outgoing tangent

def __inteprolateCubicHermiteSpline(self, key0, key1, worldTime):	
    # #
    duration = key1.time - key0.time
    parameter = (worldTime - key0.time) / duration
    p0 = key0.value
    m0 = (p0 + sin(key0.outAngleRad))
    p1 = key1.value
    m1 = (p1 + sin(key1.inAngleRad))
    # reusable time powers
    tt = parameter * parameter
    ttt = parameter * tt
    ttt2 = ttt * 2
    tt3 = tt * 3
    # Hermite basis functions
    h00t = ttt2 - tt3 + 1
    h10t = ttt - tt*2 + parameter
    h01t = -ttt2 + tt3
    h11t = ttt - tt
    return h00t * p0 + h10t * duration * m0 + h01t * p1 + h11t * duration * m1

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>