Formulas are derived for the calculation of the potential of bodies, which surface is a sphere or an ellipsoid, and the distribution function has a special form: a piecewise continuous one-dimensional function and a three-dimensional mass distribution. For each of these cases, formulas to calculate both external and internal potentials are derived. With their help, further the expressions are given for calculation of the potential (gravitational) energy of the masses of such bodies and their corresponding distributions. For spherical bodies, the exact and approximate relations for determining the energy are provided, which makes it possible to compare the iterative process and the possibility of its application to an ellipsoid. The described technique has been tested by a specific numerical example.

- Aleksandrova A. A. Plasma inhomogeneities in the magnetohydrodynamic interpretation. Information processing systems.
**9**, 122–127 (2007). - Chandrasekhar S. Ellipsoidal balance figures. Moscow, Mir (1973), (in Russian).
- Kuznetsov V. V. The principle of minimizing the gravitational energy of the Earth and the mechanisms of its implementation. Bulletin of the Earth Sciences Division of the Russian Academy of Sciences. Electronic scientific information magazine.
**1**(23), 1–27 (2005). - Newton I. Mathematical principles of natural philosophy. In the book A. N. Krylova. Publishing House of the Academy of Sciences of the USSR.
**7**(1936). - Fys M. M, Brydun А. M., Yurkiv М. I. Researching the influence of the mass distribution inhomogeneity of the ellipsoidal planet’s interior on its stokes constants. Geodynamics.
**26**(1), 17–27 (2019). - Moritz G. Earth figure: Theoretical geodesy and the internal structure of the Earth. Kiev (1994), (in Russian).
- Kondratiev B. P. The theory of potential. New methods and tasks with solutions. Moscow, Mir (2007), (in Russian).
- Meshcheryakov G. A. Problems of the theory of potential and generalized Earth. Moscow, Nauka (1991), (in Russian).
- Fis M. M. On average convergence of biorthogonal series inside an ellipsoid. Differential equations and their applications.
**172**, 131–132 (1983). - Fys M. M. The use of biorthogonal decompositions to calculate the potential of an ellipsoid. Geodesy, cartography, and aerial photography.
**40**, 114–116 (1984). - Tikhonov A. N., Samarskii A. A. Equations of mathematical physics. Moscow, Nauka (1972), (in Russian).
- Muratov R. Z. Potentials of an ellipsoid. Moscow, Atomizdat (1976), (in Russian).
- Fys M., Zayats O., Fot R., Volos V. About one method of recognizing the potential of a heterogeneous planet. Successfully reaching geodesic science and technology.
**10**(1), 236–239 (2005). - Fys M. The distribution of the gravitational field of the trivial and planetary planet from the orthogonal to one class of non-harmonious functions. Geodesy, Cartography, and Aerophotognism.
**74**, 34–37 (2011). - Fys M. M., Nikulishin V. I., Ozimblovsky R. M. Victoria polynomials Legendre for approximation of the same rozpodіlіv gustini mas planets and doslizhennya їх zbіzhnostі. Geodesy, Cartography and Aerophotognism.
**73**, 3–6 (2010). - Sege G. Orthogonal polynomials. Moscow, Fizmatgiz (1962), (in Russian).
- Marchenko A. N. Zayats A. S. Estimation of the potential gravitational energy of the Earth based on reference density models. Geodynamics.
**7**(1), 5–24 (2008). - Dzewonski A., Anderson D. Preliminary reference Earth model. Physics of the Earth and Planet Inter.
**25**, 297–356 (1981). - Fys M., Nikulishin V. Analysis of the energy efficiency of land on the internal structure of the applied model of PREM. Geodynamics.
**10**(1), 17–21 (2011).