An engine needs two pistons, in theory, to move like this.
But this thing must be applied in experiment, by conversion of the motion of a rotating shaft to a motion like this.
With those sharp turn-arounds the mechanism can't be practically made.
So I need an approximation which is possible to be made using pistons, crankshaft, cam, etc. But this part isn't related to math.
For example the function $\sin x$ is easily made using a rotating wheel and two rods joined to each other, one of them to the wheel, with hinges, and the outer one being constrained only to move in one dimension.
My first try was these functions:
$$2 \left|\cos(\pi t)\right| - \frac12\ ,\ 2 \left|\sin(\pi t)\right| - \frac12$$
Which are like this:
But the sharp turn-around problem isn't still fixed.



