I need to round the profile of a trapezoidal wave function.
In case of no rounding, the function $f\left(x\right)$ is defined as: $$ f\left(x\right)= \begin{cases} \frac{A}{l_x}\cdot x & 0\leq x<l_x \\ A & l_x\leq x<T_{high}\\ -\frac{A}{l_x}\cdot \left(x-T_{high}-l_x\right) & T_{high}\leq x<T_{high}+l_x\\ 0 & T_{high}+l_x\leq x<T \end{cases} $$
It is defined using these four parametes:
- $T$ is the period of such wave.
- $D=\frac{T_{high}}{T}$ is the duty-cycle, where $T_{high}$ is the $x$-length of the $50\%$ highest part.
- $A$ is the amplitude.
- $S=\frac{l_x}{T_{high}}$ the slope factor ($0<S\leq1$), where $l_x=S\cdot \min\left(D,1-D\right)\cdot T$ is the $x$-length of the rising/falling segment. Therefore for $s=1$ the top (or bottom) horizonal segment is zero in the case of $DC\leq0.5$ (or $DC\geq0.5$).
A schematic of such wave is shown in the following image. An example of such function is reported in the following plot for $T=8$, $D=0.25$, $A=5$, $S=0.5$.
I need to expand this function by adding a roundness factor $0\leq R\leq 1$, which makes the rounding of such function using the following rules:
- The rounding is defined with circular arcs having the same radius.
- For $R=0$ the corners are sharp with no roundness, i.e. the function is exactly as defined before.
- For $R=1$ there is no straight rising/falling segment.
- The tangent at the edge of a rounded part is the same of the adjacent straight segment or rounded part (i.e. there are no abrupt variations in the slope).
- The tangent of a rising (or falling) part is always $\geq0$ (or $\leq 0$).
- The horizontal segments at top and bottom are also shrunk as we increase R. If the horizontal segments are shorter than the rising/falling segments, then the amplitude $A$ is decreased during the rounding operation.
A sketch of such rounding operation is reported in the following image.