Ease In to Linear (range mapping problem)
I wrote this post in Cinema 4D forum because I want an Xpresso setup, but it could be done with AE expressions:
I want to write an Xpresso function to Ease In values at the beginning until normal linear interpolation, the very same way a car accelerates until it reaches constant speed, or the way you constraint 2 objects with a Spring Constraint in C4D.
Spline graph in Range Mapper (or Ease In in AE) doesn't work because at the end of spline mapping range there's always an angle.
In below picture I want to write an expression to get the blue curve from the green one (red one is range mapped)
Fun thought experiment, lets talk it through a bit.
Well, first let's think how we would draw this out in bezier curves.
It would be 3 points to create the blue line; one (A) at the origin, one (C) at the destination, and one stuck in the middle at the inflection point (B). I would want no out-tangent on the origin, and an in-tangent on the inflection point (B1) , and no point at the out point.
The in-tangent location (B1) would be on a straight line extended between (B-C), at an yet-undetermined distance.
For clarification, if we were going to decelerate, it would be another inflection point at the beginning of the deceleration, but it would have an out-tangent parallel to the slope of the (B-C).
to parse data like this, I would probably cannibalize a cubic Bezier function, https://cubic-bezier.com/#.17,.67,.83,.67.
Luckily for you, I've already rewritten this as a function for my own needs:
This works just like linear, where you parse (t,tMin,tMax,value1,value2), but then at the end we add an additional cubic-bezier handle [outTangent-X, outTangent-Y, inTangent-X, inTangent-Y].
So, what you really need to do now is make two sliders: one (Slider 1 or S1) that chooses the time (X-value) of the inflection point (B) relative to the position between A and C. This will be equivalent to your image's "range mapper" limit.
And then another slider that adjusts the acceleration intensity (which will adjust the inflection point's value (Y-value), C's value (Y-value), and also the distance between B1 and B on B-C. This will be a 'percentage' indicator.
So, where do we put B?
first, lets create our points:
B will be at:
Now, where do we put B1? Well, if we wanted maximum accelleration, B1 would be found at A. If we wanted minimum acceleration, B1 would be found at B. Neither of this are what you really want; you want something in-between.
So what we can do is this:
Now, to parse our handle through the cubic bezier function we need to normalize it from a factor of 0-1. So let's do this:
finally, we just need to determine what part gets parsed through the bezier-curve equation and what doesn't.
or parse that through the cubic bezier function:
I think that should do it. There are likely a ton of typos and maybe even a wrong thing or two, but this ought to be 80% of it. No idea how to do multiple keys off the top of my head, but it will likely be else/if functions and checking if things are linear. This is where I would start though. There's a chance you'll need to get B1 closer to B, I would just linearize it again prior to offsetting it if need be: B1 = linear(z,0,1,B1,B);
Note: none of this code was tested.
Wow, thank you for your reply, but I'll need "some" time to dig it.
I thought this had to be a very simple problem, given that this is how cars speed up and objects fall down.
Meanwhile I came up with a simple and empirical solution which I don't understand very well too:
First part of the curve is just a parabola, so Y.blue is Y.green dived by 10 and squared (1->0,01 2->0,04 3->0,09 4->0,16 ...); when Y.green reaches 50 Y.blue is 25 (50/10*50/10): at this point the blue parabola is tangent to the green line(!), so from now on Y.blue is just Y.green - 25.
This is working but don't know why... What do you think about this?
That's an interesting approach, there's lots of ways to deal with stuff like this I guess is the answer. Here is my working code that I've taken a stab at after lunch. The biggest change was I was having problems with the matrix math, I'm sure there are more appropriate ways to deal with this either as for loops or whatnot, but here it is:
Thank you very much for your code, but I don't even understand where I'm supposed to use it ☺
I see I need a "Shape layer 1" with 2 sliders S1, S2 but then I don't know where I should specify point A B C position etc.
Can you clarify a bit further please?
Set two keyframes, your beginning and end points. These will be A and C.
then have to sliders, "S1" and "S2" (rename them however you want.
S1 should be the percentage of length of time it takes to accelerate up to full velocity.
S2 should be rate that the acceleration happens (is it really smooth? Is it really abrupt?).
B will be calculated automatically based on S1 and S2.
whoops, I think L should be set to 'thisLayer'; I had this code pasted on a text object for debugging and it was referencing the animated layer.
This one is pretty plug and play. Just need to make your 2 sliders, and 2 keys.
Thank you very much, I think i'll still need some time to figure out how is working.
now it's giving me an "error at line 52 expected: ;., an expression was disabled..." which I can't find.
I'll try to fix it
(About my first parabola approach, it's x it's going up with constant acceleration (y= x*x) til it reach the parabola's focus at 1/4 y, where the tangent is y = x, constant velocity)