In order to apply the method of separation of variables to the natural Hamilton-Jacobi equation in Euclidean space, one has to find new curvilinear coordinates in which the transformed equation admits a complete separated solution . For a potential V(q) given in Cartesian coordinates, the main difficulty is to decide if such a transformation x(q) exists and to effectively determine it explicitly. Surprisingly, this nonlinear problem has a complete algorithmic solution, which we present here. It is based on recursive use of the Bertrand-Darboux equations, which are linear second order partial differential equations with undetermined coefficients. The results applies to the Helmholtz (stationary Schrödinger) equation as well.