TITLE: Why does the plot of $f(x)=|\cos x|-|\sin x|$ look almost piecewise linear?
QUESTION [10 upvotes]: I recently stumbled upon an interesting plot that I - even until today - could not quite explain: 
It's the plot of $f(x) = \lvert \cos(x) \rvert - \lvert \sin(x) \rvert$. I mean this is almost piecewise linear...
I tried to derive this shape from the Taylor series but I could not quite see it. Does anyone have some mathematical intuition for me concerning the shape of this plot?

REPLY [3 votes]: I Quadrant$\rightarrow x\in\left(0,\frac{\pi}2\right], f(x) = \lvert \cos x \rvert - \lvert \sin x \rvert=\cos x-\sin x=-\sqrt2\sin\left(x-\frac{\pi}4\right)$
II Quadrant$\rightarrow x\in\left(\frac{\pi}2,\pi\right], f(x) = \lvert \cos x \rvert - \lvert \sin x \rvert=-\cos x-\sin x=-\sqrt2\sin\left(x+\frac{\pi}4\right)$
IV Quadrant$\rightarrow x\in\left(-\frac{\pi}2,0\right], f(x) = \lvert \cos x \rvert - \lvert \sin x \rvert=\cos x+\sin x=\sqrt2\sin\left(x+\frac{\pi}4\right)$
III Quadrant$\rightarrow x\in\left(-\pi,-\frac{\pi}2\right], f(x) = \lvert \cos x \rvert - \lvert \sin x \rvert=-\cos x+\sin x=\sqrt2\sin\left(x-\frac{\pi}4\right)$

Draw individual graphs in individual domains and you should get the desired graph. Also, it looks linear just because of the scale you have chosen. Actually, it is as sinusoidal as sine is in the intervals of $\frac{\pi}2$.