Maya ease in/out - maximum tangent angle

Hey guys, I’m a long time lurker, and I’ve come across a problem that I can’t seem to google my way out of.

I’m trying to create a button to set a tangent to the maximum angle it can be without the value of the curve exceeding the value of the next keyframe.

Default spline in, flat out:
http://i.imgur.com/eofHeYf.png

What I’d like to achieve:
http://i.imgur.com/f6HG8WU.png

Without the value of the curve exceeding the value of the next keyframe:
http://i.imgur.com/4yNZlhn.png

Assuming the next tangent is flat and I have unweighted curves, is there an equation I can use to calculate the maximum angle of the tangent on the first keyframe?

with weighted tangents?

Weighted tangents aren’t quite what I’m after, as it still results in a bit of an “S” shape in the curve, which I’m trying to avoid.


If you use weighted tangents, figure out the position of the handles for the second key (it will be time - weight, value). The tangent handle for the first key should be in the same spot as that handle: I think (back of the envelope and not tested) you want:

target_pos = (end time - end weight, end value)
start pos = (start_time + start weight, start value)
delta value = end_value - start value
deltat_time = start_time - target_pos.x
rotation = atan2( normalize(target_pos) - (0,1))
weight = sqrt of (delta time ^2) + (delta value ^ 2)

will give you the rotation and weight you need.

Any combination of rotation and weight that doesn’t put the first tangent’s handle higher than the value of the second keyframe will not overshoot