trapezoid approximation of sine function I want to find a reasonable good periodic trapezoid function approximation for the sine (or cosine) function.
My use case is it to divide the year in 4 epochs: 


*

*visible light length stays roughly the same (around winter solistice), 

*visible light lenghtens by roughly x minutes a day (around spring equinox),

*visible light length stays roughly the same (around summer solistice), 

*visible light length shortens by roughly x minutes a day (around fall equinox). 


I'd be interrested in 3 values: 


*

*length of visible light during quasi-contant epochs

*steepness of change in the transit epoch

*days of transition between the epochs


If I did not make a mistake, this requires estimation or calculation of two parameters of the trapezoid function: amplitude and one of either lenght in high or low phase or steepness of the transition. Additionally of course some weighting function to establish a minimum distance would be required. If sensible/possible I'd go for sum of absolute difference.
I tried to establish a picewise formula for the difference between sinus and a periodic trapezoid function, to then minimize this, but it was over my head. Unfortunately I am not fluent enough in a mathematical program language to state that problem. Before I do a brute force numerical approximation I'd rather have a closed symbolic expression that yields a nice and exact solution.
 A: I assume you want something like this:

This is the line $y = x$ up to some maximum point $c$, which it maintains until it gets to $\pi - c$, where it drops by the line $y = \pi - x$, etc. We can control $c$ to determine the best fit.
The simplest criterion to find the best fit for is the minimum height difference between the two curves. The trapezoidal curve (the usual term of art for this sort of curve is "piecewise linear") is highest above the sine curve at $x = c$, where the distance is $c - \sin c$. The sine curve is highest above the trapezoidal curve at $x = \pi/2$, where the distance is $1 - c$. The distance will be minimized when these two distances are equal, so $c - \sin c = 1 - c$. Wolfram Alpha computes this to be when $c \approx 0.887862$.
If you want to minimize the area, that calculation is a lot more complex. By symmetry, it is sufficient to look only at the portion between $0$ and $\pi/2$, where  the area is given by
$$A = \left(\int_0^c x\,dx + \int_c^{\sin^{-1} c} c\,dx - \int_0^{\sin^{-1} c} \sin x\, dx\right) + \left(\int_{\sin^{-1} c}^{\pi/2} \sin x\, dx - \int_{\sin^{-1} c}^{\pi/2} c\,dx\right)\\=\frac{c^2}2 + c(\sin^{-1}c - c) - (1 - \cos(\sin^{-1}c)) +  \cos(\sin^{-1}c) -c(\frac{\pi}2- \sin^{-1}c)\\=-1 - \frac\pi 2 c - \frac {c^2}2 +2\sqrt{1 - c^2} + 2c\sin^{-1}c$$
To minimize the area, we take the derivative with respect to $c$ and set it to 0:
$$A' = -\frac \pi 2 - c -\frac{2c}{\sqrt{1 - c^2}} + 2\sin^{-1}c + \frac {2c}{\sqrt{1-c^2}}=2\sin^{-1}c-\frac \pi 2 - c = 0 $$
Which Wolfram Alpha says is $c \approx 0.95261$.
Of course, I just used $y = \sin x$, whereas your curve will need to be of the form $$y = A\sin(Bx)$$ but the same solution should work using lines of slope $\pm AB$, and a cutoff value of $C = Ac$ for your choice of the two $c$ values calculated above.
