1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Numerical integration of gravity at surface of an object

  1. Feb 2, 2008 #1
    Given any distribution of mass, the gravity at any point outside it can be calculated by dividing the mass into infinitesimal masses, and adding up the gravity due to each.

    Doing that, I faced a problem on the surface of an object: no matter how small you make the integration step, near the point of interest the distance to the infinitesimal mass gets smaller than the integration step so you get very wrong values. So what is the proper way to integrate gravity for a point at the surface of an object?

    Maybe there is a theorem that a hemisphere has this much gravity at its centre, sso you can use the result for infinitesimal masses closer than D from the point of interest on the surface.

    Can anyone solve this integral analytically? Total gravity at centre = ?
    Last edited: Feb 2, 2008
  2. jcsd
  3. Feb 2, 2008 #2
  4. Apr 2, 2008 #3
    I am pretty sure that if you aren't going to do this integration with a computer, the mass distribution will have to exhibit some sort of symmetry, so please be more specific on what your "object" is. For example, Shell Theorem only works if you can approximate your object to be a sphere. I think a hemisphere won't work unless you really look carefully at your indices of integration. With Shell Theorem, you can treat any shell as a point mass located at the shell's center, so the distance from the surface to the shell's center will never be zero.

    If you're analyzing a hemisphere, maybe it would be useful to treat the hemisphere as a stack of increasingly larger disks, and find the gravity contribution from each disk, and then integrate over all the disks. That's how Shell works - take a spherical shell, and divide it into "rings," find the gravity force from each ring, and add them all up by integration.
  5. Apr 2, 2008 #4
    The idea is to use numerical integration for an arbitrary distribution that is defined as an equation (eg an ellipsoid like the earth, or an object defined in terms of cubic surface patches). But this fails at the edges between matter and space.

    So how do we do the edges? We could increase the resolution locally. That works fine when we're close to the edge (which I've done successfully), but when we're exactly on the edge, it fails.

    So we're only stuck when dealing with points on the edge, defined analytically. For these points, we can go like this:

    - if current cubic pixel of integration is further than a small radius r, use Newton's law of gravity,


    - use the analytical formula for a hemisphere of radius r and knowledge of the tangent plane (derived analytically from the equation of the earth ellipsoid or whatever).


    So what is the analytical formula for the gravity at the centre of a hemisphere of radius r, that is the question.
    Last edited: Apr 2, 2008
  6. Apr 2, 2008 #5
    Maybe this could be helpful:


    I tried doing this problem with a double integral and also a surface integral but I couldn't figure out how to relate dm to the variables of integration.

    edit: oh wait, the mass is not uniformly distributed?
  7. Apr 2, 2008 #6
    It is initially.

    In future versions of my program it won't be. But if we make r small enough, this will be ok, assuming density does not vary too much locally.
  8. Apr 3, 2008 #7
    Why don't you try some kind of mollified force function.

    I take it you are numerically integrating something like
    [tex]\mathbf{F}(\mathbf{x}) = \int \Delta \mathbf{F}(\mathbf{y},\mathbf{x}) d\mathbf{y}[/tex]
    Where your "force density" function [tex]\Delta\mathbf{F}[/tex] is something like
    [tex]\Delta \mathbf{F}(\mathbf{y},\mathbf{x})=\frac{Gm(\mathbf{x})\rho(\mathbf{y})}{|\mathbf{y}-\mathbf{x}|^2}[/tex]

    You could try mollifying the force density to prevent self interaction problems, which are essentially the source of your errors. You could try something like

    \Delta \mathbf{F}(\mathbf{y},\mathbf{x})=\begin{cases}\frac{4 \pi}{3} G\rho(\mathbf{x})\rho(\mathbf{y})|\mathbf{y}-\mathbf{x}| & |\mathbf{y}-\mathbf{x}|\le k
    \frac{Gm(\mathbf{x})\rho(\mathbf{y})}{|\mathbf{y}-\mathbf{x}|^2} & |\mathbf{y}-\mathbf{x}|>k. \end{cases}
    [tex]m(\mathbf{x})=\frac{4 \pi k^3}{3} \rho(\mathbf{x})[/tex]
    and k is some characteristic radius which is small, but should be larger than your integration steps.

    Or perhaps more simply
    \Delta \mathbf{F}(\mathbf{y},\mathbf{x})=\begin{cases}0& |\mathbf{y}-\mathbf{x}|\le k
    \frac{Gm(\mathbf{x})\rho(\mathbf{y})}{|\mathbf{y}-\mathbf{x}|^2} & |\mathbf{y}-\mathbf{x}|>k. \end{cases}
    Which would avoid self interaction problems entirely, but leave out close by objects.

    Let us know if you try these.
  9. Apr 3, 2008 #8
    Thanks, I need to think this through when I get some time.

    That's close to what I do at present, I can't increase the resolution forever so I pretend there is no mass nearby, which is correct when you're inside matter, but not when you're exactly on the edge, so I end up with a noisy curve for gravity along the surface of the object.
  10. Apr 3, 2008 #9


    User Avatar
    Science Advisor
    Homework Helper

    If you're just on the surface, not inside the object, you should be able to find the center of mass by integrating over the volume of the object. This would take three triple integrals in your case, or three double integrals if the density is uniform (since the innermost integrand of the triple integral will be 1, so you can simplify one level).

    Once you have that, can't you just calculate gravity as though from a point mass?
  11. Apr 3, 2008 #10


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Nope. The easiest counterexample to see is to compare the gravitational force from a single point mass, and a pair of point masses with that center of gravity, where one of the points is right next to your test particle.
  12. Apr 3, 2008 #11


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I'm assuming you are treating your original mass as a continuous matter distribution?

    You can do some actual analysis and estimate errors. Suppose you are decomposing your mass into little cubes. Then, for each cube, you can compute the smallest and largest densities in that cube. Then, for each component of gravitational force, you should be able to determine the largest and smallest forces that are possible for the cube to exert on your test particle under all possible matter distributions satisfying that density constraint. This way, you have actual hard upper and lower bounds for the value you're calculating.

    Another option is to attempt to subtract off the singularity -- before you attempt to do numerical integration, you analyze the integrand and separate it into a singular and a nonsingular part... hopefully where the singular part is easy to do with symbolic integration.

    For example, if I wanted to integrate

    [tex]\frac{1}{\sqrt{|\sin x|}}[/tex]

    I would recognize that the singluarity at the origin looks like [itex]1 / \sqrt{|x|}[/itex], and I would write the integral as

    \int_{-1}^1 \frac{1}{\sqrt{|\sin x|}} \, dx = \int_{-1}^1 \frac{1}{\sqrt{|x|}} \, dx
    + \int_{-1}^1 \frac{1}{\sqrt{|\sin x|}} - \frac{1}{\sqrt{|x|}} \, dx[/tex]

    The first integral I can do symbolically, and the second integrand is now well-behaved at x=0, and you should have no difficulties numerically integrating it. Of course, you might have some numerical stability issues computing values of the integrand near x=0, so you'll have to do some more work to figure out how to evaluate it with little error.
    Last edited: Apr 3, 2008
  13. Apr 3, 2008 #12

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    Another way to address this problem is to represent the gravitation potential via spherical harmonics. http://www.cdeagle.com/pdf/gravity.pdf" [Broken] (200x200, extensible to 360x360). JPL has developed a 150x150 spherical harmonic model of the Moon's gravity field.
    Last edited by a moderator: May 3, 2017
  14. Apr 3, 2008 #13

    Can't open that article, D H, but can spherical harmonics be generalized for any shape defined in terms of cubic surface patches? This is what I am after eventually.
  15. Apr 3, 2008 #14
    How can I tell the integral is well-behaved?
  16. Apr 3, 2008 #15

    I've done something in that line when I wanted to decide how small to make the integration step given the distance to the point of interest. Ie if the cube is too close, the point mass approximation is no good - increase resolution and repeat with smaller cubes.
  17. Apr 3, 2008 #16

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    I edited the post. Thanks for reporting the problem.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook