  Minimizing the Euclidean distance to a set arises frequently in applications.
When the set is algebraic, a measure of complexity of this optimization problem
is its number of critical points. In this paper we provide a general framework
to compute and count the real smooth critical points of a data matrix on an
orthogonally invariant set of matrices. The technique relies on "transfer
principles" that allow calculations to be done in the space of singular values
of the matrices in the orthogonally invariant set. The calculations often
simplify greatly and yield transparent formulas. We illustrate the method on
several examples, and compare our results to the recently introduced notion of
Euclidean distance degree of an algebraic variety.
