Variational Principles with Singularities in Geodetics, Optics and Dynamics