Let $f$ be a mapping $\mathbb{R} \implies \mathbb{R}$
Let $\forall x, r \in \mathbb{R}$ let $T(x, r)$ be the triangle whose three vertices are the following points:
- $(x-r, f(x-r))$
- $(x+0, f(x+0))$
- $(x+r, f(x+r))$
Let $\theta(x, r)$ be the the interior angle at point $(x, f(x))$ on triangle $T(x, r)$.
Let $\Theta(x)$ be the limit of $\theta(x, r)$ as $r$ approaches $0$.
Question: How can we simplify the following formula?
$\begin{align} \Theta(x) &= \lim \limits_{r \to 0} \theta(x, r) \\ &= \lim \limits_{r \to 0} \cos^{-1}\begin{pmatrix} \dfrac{-(r^{2}) + a^{2}(x,r) + b^{2}(x, r)}{2*a(x,r)*b(x,r)} \end{pmatrix} \\ \end{align}$
where
$\qquad \qquad a(x, r) = \sqrt{r^{2}+ \begin{pmatrix}f(x)-f(x-r)\end{pmatrix}^{2}} $
$\qquad \qquad b(x, r) = \sqrt{r^{2}+ \begin{pmatrix}f(x)-f(x+r)\end{pmatrix}^{2}}$
The law of cosines was used here.
A Remark
If $f$ is differentiable then $\forall x \in \mathbb{R}, Θ(x) = 180º$
However, I am interested in calculating the angle when $f$ represents a polygonal-chain


Define $A = \frac{f(x) - f(x - r)}{r}$ and $B = \frac{f(x + r) - f(x)}{r}$. If $f$ is differentiable, then $A$ and $B$ both converge to $f'(x)$ as $r \rightarrow 0$. But this generalization allows for piecewise functions that "turn the corner" at $(x, f(x))$. Anyhow, if we make the substitutions
$$f(x - r) = f(x) - rA$$ $$f(x + r) = f(x) + rB$$
in your definitions of functions $a$ and $b$, then these functions simplify to:
$$a(x, r) = r \sqrt{1 + A^2}$$ $$b(x, r) = r \sqrt{1 + B^2}$$
Plug these into your formula for $\cos(\theta)$.
$$\cos(\theta(x, r)) = \dfrac{-r^{2} + a^{2}(x,r) + b^{2}(x, r)}{2 a(x,r) b(x,r)}$$ $$= \dfrac{-r^{2} + r^2(1 + A^2) + r^2(1 + B^2)}{2 r \sqrt{1 + A^2} r \sqrt{1 + B^2}}$$ $$= \dfrac{r^2 + r^2A^2 + r^2B^2}{2 r^2 \sqrt{(1 + A^2)(1 + B^2)}}$$ $$= \dfrac{1 + A^2 + B^2}{2\sqrt{(1 + A^2)(1 + B^2)}}$$
If $f$ is differentiable at $x$, then $A = B = f'(x)$, and the above expression simplifies to $1 - \frac{1}{2(1+f'(x)^2)}$. Otherwise,
$$\Theta(x) = \cos^{-1}\left(\dfrac{1 + f'_-(x)^2 + f'_+(x)^2}{2\sqrt{(1 + f'_-(x)^2)(1 + f'_+(x)^2)}}\right)$$
Where $f'_-(x)$ and $f'_+(x)$ denote left and right derivatives.