WeightedTransition

This class is used for objects that perform smooth transitions between two functions of one variable. Denoting the transition begin and end points by x1x_1 and x2x_2, respectively, and the "left" and "right" functions by f1(x)f_1(x) and f2(x)f_2(x), respectively, the transition function f(x)f(x) is the following: f(x)=w(x)f1(x)+(1w(x))f2(x), f(x) = w(x) f_1(x) + (1 - w(x)) f_2(x) \,, where the weight wx(x)w_x(x) is between 0 and 1 and is computed with a cosine function: w(x)={1xx10xx212(cos(πx2x1(xx1))+1)otherwise. w(x) = \left\{\begin{array}{l l} 1 & x \le x_1\\ 0 & x \ge x_2\\ \frac{1}{2}\left(\cos\left(\frac{\pi}{x_2 - x_1}(x - x_1)\right) + 1\right) & \text{otherwise}\\ \end{array}\right. \,. The transitioned function f(x)f(x) has the following desirable properties:

  • f(x)f(x) is continuous throughout the interval [x1,x2][x_1, x_2] (including at the end points), so long as f1(x)f_1(x) and f2(x)f_2(x) are also continuous on this interval.

  • f(x)f'(x) is continuous throughout the interval [x1,x2][x_1, x_2] (including at the end points), so long as f1(x)f_1'(x) and f2(x)f_2'(x) are also continuous on this interval.

An example of the transition is illustrated in Figure 1, where is transition is created in the region x(1,5)x\in(1,5) at a discontinuity:

Figure 1: Weighted transition at a discontinuity

Note that the transition can exit the bounds of the non-transitioned piecewise function, which can be undesirable. This is illustrated in Figure 2, where compares this weighted approach with the approach of CubicTransition:

Figure 2: Transition at the intersection of two functions

Thus when the transition occurs at the intersection of two functions, it may be advantageous to use CubicTransition instead of WeightedTransition, whereas transitions at a discontinuity may be handled well with WeightedTransition.