piecewiseLinearApproximation: using three auxiliary internal functions