I have the following problem:
Let $f:\mathbb{R}^n \rightarrow \mathbb{R}$, $f(x)=(\operatorname{dist}(x,D))^2$ where $D$ is a convex, close set in $\mathbb{R}^n$. Prove that $f$ is convex and $f'(x)=2(x-P_D(x))$. Here $P_D(x)$ is the projection of $x$ in $D$.
I prove convexity, but I can't demonstrate that differential (gradient) is this. I think that the way to go is to use the definition, proving that
$$\lim_{x\rightarrow x_0} \frac{|f(x)-f(x_0)-f'(x_0)^{\top}(x-x_0)|}{\|x-x_0\|}=0$$