How to apply an "easing" to a function with sharp corners?

243 Views Asked by At

What's the common method for “ironing out sharp edges” of a function $g$ defined as follows, for known $a$ and $b$ and $f$ in $\mathbb R$?

$$ g(x) = \max(a, \min(b, f(x)) $$


Quick context: the function determines the position of control points of a Bézier curve as the user drags the mouse around. The control points are calculated based on the start and end point of the curve, but there's a minimum and maximum distance of the control points that's enforced regardless of start/end points.

As the user drags the mouse, these min/max points become obvious as the curve suddenly changes the way it's moving around. It's to be expected, since the graph of how the control point position changes based on the end point has sharp corners because of the min/max restriction.

enter image description here

What's an easy way to make this change more organic (while losing some precision)? In other words, how to transform the function to look more like the following picture?

enter image description here

Any additional formal assumptions that make the problem easier are probably all right. In real life, $f$ itself is nothing crazy with ups and downs and sharps (sorry -- can't put my finger on the exact mathematical term), but it's not necessarily linear.

enter image description here

1

There are 1 best solutions below

1
On

The standard approach is a function called “smooth step”.

The function $f(x) = 3x^2 - 2x^3$ increases smoothly from $0$ to $1$ as $x$ varies between $0$ and $1$, as shown in your pictures. You can scale and translate this function to suit your needs.