Gravitational attraction between two masses

Click For Summary

Discussion Overview

The discussion revolves around the gravitational attraction between two masses, focusing on the calculations involved in determining how far each mass moves in response to their mutual gravitational force. Participants explore the theoretical underpinnings, practical applications in a JavaScript simulation, and the complexities of accurately modeling the motion over time.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • The gravitational constant and the formula for gravitational force are presented, with an example calculation provided by the original poster (OP).
  • One participant corrects the OP's initial calculations regarding the distances moved by each mass, stating that mass 1 travels 5/6 meter and mass 2 travels 1/6 meter.
  • Another participant questions whether the masses would come into contact after 1 second, suggesting that the attraction seems very strong for such small masses.
  • Further calculations are presented to determine the accelerations of each mass based on the gravitational force, with subsequent distances moved after several seconds discussed.
  • One participant notes the complexity of the problem, indicating that as soon as either mass moves, the distance changes, which affects the force and requires calculus for accurate modeling.
  • Suggestions for approximating the simulation using numerical methods are provided, including the use of iterative calculations to update positions and speeds over time.
  • A later post mentions the existence of closed-form solutions for certain aspects of the problem but acknowledges the lack of a closed-form solution for position, velocity, or acceleration versus time.
  • One participant shares a JavaScript method they developed to simulate the motion, detailing the calculations involved in determining forces, accelerations, and positions.

Areas of Agreement / Disagreement

Participants express varying levels of agreement on the calculations and methods for simulating gravitational attraction. While some calculations are accepted, there is no consensus on the best approach to accurately model the motion over time, with differing opinions on the necessity of calculus versus numerical methods.

Contextual Notes

The discussion highlights the limitations of the initial assumptions, particularly regarding the simplifications made in the calculations. The dependence on the definitions of distance and force, as well as the unresolved mathematical steps in modeling the motion, are noted.

Who May Find This Useful

This discussion may be useful for individuals interested in gravitational physics, numerical simulations, or those developing educational software related to physics concepts.

ktoz
Messages
170
Reaction score
12
hi

I'm writing a javascript application to illustrate gravitational attraction between masses, but am getting hung up on some of the details, particularly mow far masses move in response to each other's gravitation.

I've read all available wikipedia articles on gravity and have come up with the following:

Gravitational constant: (6.67408 x 10^-11 meters^3) / (kilos * seconds^2)
Force between masses: G * (mass 1 in kilos * mass 2 in kilos) / (distance in meters ^2)

Now for a concrete example
Mass 1: 1 kilo
Mass 2: 5 kilos
Distance: 1 meter
Seconds: 1

Pluging that into above yeilds
f = (667408 * 1^3 * 1 * 5) / ( 10^11 * 1 * 1 * 1^2)
which reduces to
f = 667408 * 5 / 10^11
f = 3.33704 x 10^6 / 10^11
f = 3.33704 x 10^-5

Simple enough, but here's where I'm getting lost. How far would the 1 kg mass move and how far would the 5 kg mass move in response to this force?

Secondly, so long as all values in f = G x m1 * m2 / d^2 are converted to metric, is "G" just 6.67408 x 10^-11

Thanks for any help
 
  • Like
Likes   Reactions: Delta2
Physics news on Phys.org
CORRECTION: This post overlooked that the OP specified a time of 1 second. The proportions are still correct but the amounts of motion are (probably) wrong.

Their accelerations will be inversely proportional to their masses. The velocities and distances are simple integrals of acceleration and velocity, respectively, so they are also inversely proportional to their masses. They will move toward each other till they collide. The total motion of both is Distance=1 meter. It is simple algebra to find the answers. Mass 1 travels 5/6 meter and mass 2 travels 1/6 meter.
 
Last edited:
FactChecker said:
Mass 1 travels 5/6 meter and mass 2 travels 1/6 meter.

Since the time in the original was specified as 1 second, does that mean they would come into contact after 1 second? For such small masses, that seems like a really powerful attraction. Almost as fast as two strong magnets.
 
OK. Just thinking out loud...

Since F is now known, acceleration for each mass is:
f = m*a
a = f / m
a1 = 3.33704 x 10^-5 / 1 (mass 1)
a2 = 3.33704 x 10^-5 / 5 (mass 2)

a1 = 3.33704 x 10^-5 meters per second ^2
a2 = 6.7408 x 10^-6 meters per second ^2

so after 1 second mass 1 moves 3.33704 x 10^-5
after 2 seconds it moves 6.67408 x 10^-5
after 3 seconds it moves 1.001112 x 10^-4
etc

after 3 seconds total distance moved = 2.002224 x 10^-4

I think I get that part. Just loop the script til total distance for mass 1 and 2 equals 1/6, 5/6 of starting distance. Possible snafu though is since the distance decreases with each iteration, does that mean the force has to be recalculated after each step since it will get progressively smaller each step?
 
ktoz said:
Simple enough, but here's where I'm getting lost.
Actually, this problem not as simple as looks at first glance. The catch is that as soon as either mass moves even slightly, the distance between them changes, and this changes the force, which changes the acceleration, which changes the speed, which changes the amount they move, which changes the distance, and so forth. Doing this problem correctly requires a fair amount of calculus and solving a differential equation... and that's probably not the answer that you were hoping for. (Although you can google for "gravitational two-body problem" and "reduced mass" if you want to go that way).

However, if you're just looking for a javascript application that will illustrate the motion, you can do an approximate simulation. Suppose at time ##t_1## the masses are a distance ##r## apart and they are moving with speeds ##v_1## and ##v_2## respectively. You can calculate the force between them, and that will give you the accelerations ##a_1## and ##a_2## at that time ##t_1##. Now you can approximate the new positions and speeds at time ##t_2=t_1+\Delta{t}##:
The speed of each object changes by the acceleration times ##\Delta{t}##; this is just ##v=at##.
The position of each object changes by the average speed (the sum of the old speed and the new speed divided by two) times ##\Delta{t}##; this just distance equals speed times time.

Now you have the new positions and speeds, which you can use to calculate the new distance between them and the new forces, and you can just run this in a loop, updating the time by ##\Delta{t}## each time through. The smaller you make ##\Delta{t}##, the more iterations it will take to simulate the same amount of time and the more accurate the simulation will be. With a bit of care (and if you are familiar with vectors) you will be able to make this work even in three dimensions and even if the objects start out moving in arbitrary directions.
 
  • Like
Likes   Reactions: Delta2
Nugatory said:
(Although you can google for "gravitational two-body problem" and "reduced mass" if you want to go that way).

Thanks for the search tip.

Luckily, since the end product is a javascript animation, and I'm limited to screen resolution, it's actually better, for my purposes, to perform each step in a loop rather than resorting to differentials (which is good since I never mastered them). Thanks again and If I get it working, I'll post a link.
 
Sorry. I overlooked the 1 second limitation. That doesn't change the proportions of the motion, but it does change the total.
 
  • Like
Likes   Reactions: Delta2
There is a closed form solution for velocity versus current position, and for time versus current position, but no apparent closed form solution to get position, velocity, or acceleration versus time:

https://www.physicsforums.com/threa...of-two-attracting-masses.849750/#post-5329209

Getting back to a numerical method, you could use something like RK4 to improve the accuracy:

https://en.wikipedia.org/wiki/Runge–Kutta_methods

https://www.physicsforums.com/threa...diff-eq-other-math-stuff.824413/#post-5177469
 
Last edited:
  • Like
Likes   Reactions: PeroK, Nugatory and Delta2
Well, I got it working. Here's the relevant Javascript method

proto.getPVTable = function(inP1, inP2)
{
var t = this;

// get particle centers
var ax = inP1.getCX();
var ay = inP1.getCY();
var bx = inP2.getCX();
var by = inP2.getCY();

// compute triangle sides
var dx = ax - bx;
var dy = ay - by;
var distPixels = Math.sqrt(dx * dx + dy * dy);

// compute sines and cosines
var acos = dx / distPixels;
var asin = dy / distPixels;
var bcos = -acos;
var bsin = -asin;

// mass
var amass = inP1.mass;
var bmass = inP2.mass;

// radiaii
var arad = inP1.getRad();
var brad = inP2.getRad();

// pre compute fmass (G * m1 * m2)
var fmass = (.0000000000667408 * amass * bmass);
var lim = arad + brad;

// declare other vars
var distMeters = distPixels * MetersPerPixel;
var result = [];
var force;

while (distPixels > lim)
{
// compute force
force = fmass / (distMeters * distMeters);

// compute acceleration
aacc = force / amass; // meters per second
bacc = force / bmass; // meters per second

// convert meters to pixels
appm = aacc * PixelsPerMeter;
bppm = bacc * PixelsPerMeter;

// check for overshoot
if ((distPixels - appm - bppm) < lim)
break;

// compute x and y deltas and add to result
// (not sure why, but had to add
// '-' signs to make it work correctly)
result.push({ax: -appm * acos,
ay: -appm * asin,
bx: -bppm * bcos,
by: -bppm * bsin});

// update dist vars
distPixels -= (appm + bppm);
distMeters = distPixels * MetersPerPixel;
}

// handle leftovers
if (distPixels > lim)
{
var tmass = amass + bmass;
var rem = distPixels - lim;

// divide remainder by mass proportion
appm = rem * amass / tmass;
bppm = rem * bmass / tmass;

// compute point deltas and add to result
result.push({ax: -appm * acos,
ay: -appm * asin,
bx: -bppm * bcos,
by: -bppm * bsin});
}

return result;
}

Works pretty well with two particles. Now to add multi particle functionality...
 
  • #10
I don't quite follow the code. It appears it calculates distance moved based on acceleration, as opposed to calculating change in velocity based on acceleration, then calculating distance based on velocity. The RK4 method I mentioned previously would be more accurate, but since this is a 2 body (and perhaps later an n body) problem, you can also use the fact that total energy of the system is constant. Any decrease in gravitational potential energy corresponds to an increase in kinetic energy. This can be used to adjust the results so that total energy remains constant, which further improves the accuracy.

Handling multiple particles will be difficult.

http://en.wikipedia.org/wiki/N-body_problem

In addition to the closed form solution I linked to before, a closed form solution based on Kepler's law produces the same result. From another thread, showing links to the two key posts:

https://www.physicsforums.com/threads/non-constant-accelleration-equation-s.635188/#post-4069467

https://www.physicsforums.com/threads/non-constant-accelleration-equation-s.635188/#post-4069945
 
Last edited:
  • #11
I looked them over, but will have to expend much more effort to understand them. (I never took calculus and all efforts to learn it on my own have failed. Just don't get the whole "make things really really tiny and viola! Magic happens" thing.)

I will try, but for the mean time, here's a link to what I have so far.

http://nowser.net/AppStrings/index.php

It has only been tested in Firefox, so If you take a look, you should use that browser. All you do is click anywhere in the white framed area to deposit the forst "particle" (100,000 kilos) and click somewhrere else to deposit the second particle. Once they collide, you can drag the dots around to other locations. Dragging the big dot doesn't reset the motions, but dragging the small one does.

I'm probably missing something, but to my eye, it looks pretty natural.
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
1K
  • · Replies 61 ·
3
Replies
61
Views
6K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 23 ·
Replies
23
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 21 ·
Replies
21
Views
2K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 7 ·
Replies
7
Views
15K