  Let $q$ be a nondegenerate quadratic form on $V$. Let $X\subset V$ be
invariant for the action of a Lie group $G$ contained in $SO(V,q)$. For any
$f\in V$ consider the function $d_f$ from $X$ to $C$ defined by
$d_f(x)=q(f-x)$. We show that the critical points of $d_f$ lie in the subspace
orthogonal to ${\mathfrak g}\cdot f$, that we call critical space. In
particular any closest point to $f$ in $X$ lie in the critical space. This
construction applies to singular t-ples for tensors and to flag varieties and
generalizes a previous result of Draisma, Tocino and the author. As an
application, we compute the Euclidean Distance degree of a complete flag
variety.
