Let q be a nondegenerate quadratic form on V. Let X ⊂ V be invariant for the action of a Lie group G contained in SO(V,q). For any f ∈ V consider the function df from X to $\mathbb C$
ℂ
defined by df(x) = q(f − x). We show that the critical points of df lie in the subspace orthogonal to ${\mathfrak g}\cdot f$
g
⋅
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.