Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
 MacRumors Forums Gravity Formulas?
 User Name Remember Me? Password

 Thread Tools Search this Thread Display Modes
 Dec 20, 2009, 11:23 AM #1 Awesomeness macrumors member   Join Date: Feb 2009 Gravity Formulas? Say I have an arbitrary number of bodies with x and y coordinates, each with a unique mass. How would you calculate the change in velocity for each body? How do you calculate inertia? Mainly I just need the formulas, but if anyone is kind enough and has the time to do it, a java example would be awesome. 0
 Dec 20, 2009, 02:15 PM #2 HiRez macrumors 68040     Join Date: Jan 2004 Location: Western US I'm certainly not an expert on physics, but IIRC the mass of an object doesn't factor into how gravity affects them at all, UNLESS you're also accounting for air friction/drag. Acceleration due to gravity is constant, regardless of the object's mass (we are talking Earth gravity here, right?). I think Galileo's famous experiment of dropping 2 balls of different masses proved that. Earth gravity accelerates objects at about 9.8 meters per second squared, so you can use that to calculate downward force (towards the earth's core). d = 1/2at^2. Or, distance traveled = 0.5 * 9.80 * time squared. So for example, after 3 seconds of freefall, d = 0.5 * 9.8 * (3.0)^2 = 44.1 meters added to the y component (the x component would be independent). Like I said, I'm not an expert on this, so please check first, but I think that's right for simple freefalling bodies in gravity, unless you're doing something more complicated (rolling friction, air resistance) or need more accuracy (the acceleration is slightly different depending on elevation, objects accelerate faster at the North Pole than at the equator, for example). __________________ Go outside, the graphics are amazing! 0
Dec 20, 2009, 02:25 PM   #3
mkrishnan
Demi-God (Moderator emeritus)

Join Date: Jan 2004
Location: Grand Rapids, MI, USA
Quote:
 Originally Posted by HiRez I'm certainly not an expert on physics, but IIRC the mass of an object doesn't factor into how gravity affects them at all, UNLESS you're also accounting for air friction/drag.
Mass in essence is a definition of an object's magnitude of gravitational interaction...

However, that assumption is fair in the scenario where numerous "small" objects are interacting with a large object at a nearly fixed distance (e.g., people walking on or near the Earth's surface -- where you use the "g" constant of 9.8 m/s^2 as an approximation of the actual gravitational force). It is, of course, incorrect for the scenario when the objects are of loosely comparable size.

For the original question, though, this is going to depend essentially on how detailed you want to get. For games in which a physics engine is not important, you have your objects accelerate down the screen at a fixed rate, specifying some terminal velocity for them if you have an atmosphere. But for games where the physics engine is a really crucial part of the enterprise, you're not going to get someone to post you a java example... this is going to be a lot of work, and you have to decide if you really want to make a physics engine (and understand how to make approximations well enough to do it), or if you would be better served by just using an open source physics engine, like this one.
__________________
Mohan
0
Dec 20, 2009, 03:41 PM   #4
TomM
macrumors newbie

Join Date: Dec 2007
Gravity Formulas

Quote:
 Originally Posted by Awesomeness Say I have an arbitrary number of bodies with x and y coordinates, each with a unique mass. How would you calculate the change in velocity for each body? How do you calculate inertia? Mainly I just need the formulas, but if anyone is kind enough and has the time to do it, a java example would be awesome.
Two days ago I found a link to a very good web site on physics from Georgia State University. They have formulas and good discussions on gravity and other topics.

The site is: http://hyperphysics.phy-astr.gsu.edu/hbase/hframe.html

TomM
0
Dec 20, 2009, 03:59 PM   #5
MrFusion
macrumors 6502a

Join Date: Jun 2005
Location: West-Europe
Quote:
 Originally Posted by Awesomeness Say I have an arbitrary number of bodies with x and y coordinates, each with a unique mass. How would you calculate the change in velocity for each body? How do you calculate inertia? Mainly I just need the formulas, but if anyone is kind enough and has the time to do it, a java example would be awesome.
This brings back a flashback. I once had to calculate the trajectory of an asteroid through the solar system for an astrophysics course. I still have the (crappy) java code. If you are interested, PM me. Unfortunately, the accompanying report is not in English.

There are no analytical solutions for more than 2 bodies. For three bodies, you can approximate it if the mass of the third body can be neglected. For example, the apollo on way to the moon. For a larger number of bodies, you have to compute a numerical solution.
If you are only interested in a bunch of things falling towards the ground, with no or little interaction between them, then you simply use an acceleration of 1 g for each object. This also assumes that you are close enough to the earth surfaces. The value of g also depends where you are on the planet. G, as in Newton's law of gravity, is a universal constant. g as in F=mg is not.

If you really want to get started in numerical computations of the heavens, then maybe this book is of interest to you (it is in English):
http://www.amazon.com/Astronomical-A...1345244&sr=8-1
(Ah, another half-hearted project that fell through the cracks.)

You should be forewarned though. I don't think you are embarking on an easy task. Implementing a few formulas from a book is one thing (setting aside all the numerical approximations issues), trying to build a physics engine is another. If you do not know both physics and mathematics, then I recommend you find a good API. You might get some answer eventually if you do it yourself, but that doesn't mean it will be physically correct.

If you are just doing it for fun, though, then go ahead. Just don't expect too much, too early. You could get disappointed very soon.
__________________
24" iMac, 13" MacBook, iPod Touch. iPod mini and PowerPC Mac Mini gathering dust somewhere.
0
Dec 20, 2009, 04:16 PM   #6
MrFusion
macrumors 6502a

Join Date: Jun 2005
Location: West-Europe
Quote:
 Originally Posted by TomM Two days ago I found a link to a very good web site on physics from Georgia State University. They have formulas and good discussions on gravity and other topics. The site is: http://hyperphysics.phy-astr.gsu.edu/hbase/hframe.html TomM
This is a nice site that explains some basic physics. But if this is all you have to base yourself on to calculate the orbit of N bodies, then in (insert name of whatever deity you believe in)'name don't do it. First you do 10+* pages of hardcore* math to understand the basics of astrophysics, then you do some numerical simulations.

*depending on your prior knowledge of physics and mathematics.
__________________
24" iMac, 13" MacBook, iPod Touch. iPod mini and PowerPC Mac Mini gathering dust somewhere.
0
Dec 20, 2009, 04:35 PM   #7
mkrishnan
Demi-God (Moderator emeritus)

Join Date: Jan 2004
Location: Grand Rapids, MI, USA
Quote:
 Originally Posted by MrFusion *depending on your prior knowledge of physics and mathematics.
Yes, those who went through at least two or three years of undergraduate physics had a fear of explicit solutions to n>2 body problems well drilled into us.
__________________
Mohan
0
Dec 20, 2009, 04:40 PM   #8
MrFusion
macrumors 6502a

Join Date: Jun 2005
Location: West-Europe
Quote:
 Originally Posted by mkrishnan Mass in essence is a definition of an object's magnitude of gravitational interaction...
F = m a = GmM/r^2

Also, don't confuse mass with weight. The mass of an object would still be the same in the absence of gravity. Think of it as an expression of how many atoms something has. An object can gain or lose mass, gain or lose atoms. My mass is the same on earth, as it is on the moon.

However, the weight is not the same. My weight on Earth is much higher than it is on the moon. That is because Earth's gravity is higher than the moon's, and that is because Earth's mass is higher.
The force that the earth applies is much higher because it's mass is higher. This force also depends on the mass of the object (maybe that is what you meant, mkrishnan?). That is why a bag of feathers is easier to carry than a bag of the same volume filled with stones. However, the acceleration is the same for both bags and both bags will hit the ground at the same time. If we neglect friction, that is.
__________________
24" iMac, 13" MacBook, iPod Touch. iPod mini and PowerPC Mac Mini gathering dust somewhere.
0
Dec 20, 2009, 04:49 PM   #9
MrFusion
macrumors 6502a

Join Date: Jun 2005
Location: West-Europe
Quote:
 Originally Posted by mkrishnan Yes, those who went through at least two or three years of undergraduate physics had a fear of explicit solutions to n>2 body problems well drilled into us.
2 or 3 years? You lucky bastard. This is my eleventh year. A few more months until my Ph.D. defense. Argh, the insanity, the horror, the low pay, the long maddening hours in the lab. Incompetent undergrads. Burning labs. (the last two are not necessarily related.) You should read phdcomics.com. Oh, the brutal reality captured in a 3 frame cartoon. And the thrill/terror of publishing.
I am now certain; the mental wings in hospitals are filled with PhD's in physics.

Why yes, I would do it all over again.

----
Edit:
This is my eleventh year. 11... Oh my... For the love of God, put me out of my misery. Please, I am begging you...

Okay, okay, I exaggerate. It is actually a lot of fun to do, with many great opportunities, but at times also stressful.
__________________
24" iMac, 13" MacBook, iPod Touch. iPod mini and PowerPC Mac Mini gathering dust somewhere.

Last edited by MrFusion; Dec 20, 2009 at 04:55 PM. Reason: joking around
0
Dec 20, 2009, 04:58 PM   #10
mkrishnan
Demi-God (Moderator emeritus)

Join Date: Jan 2004
Location: Grand Rapids, MI, USA
I am not a physicist, but it was my understanding that it is not an overly absurd understanding of relativistic theory that energy in the form of rest mass causes an object to distort the metric of spacetime, thereby causing the effect of gravity. Or that in the running quantum theory, that the higgs field gives a particle its mass, which in turn causes other particles to gravitate towards it....

Quote:
 Originally Posted by MrFusion This is my eleventh year. 11... Oh my... For the love of God, put me out of my misery. Please, I am begging you...
I have a PhD already.
__________________
Mohan
0
Dec 20, 2009, 05:10 PM   #11
gnasher729
macrumors G4

Join Date: Nov 2005
Quote:
 Originally Posted by Awesomeness Say I have an arbitrary number of bodies with x and y coordinates, each with a unique mass. How would you calculate the change in velocity for each body? How do you calculate inertia? Mainly I just need the formulas, but if anyone is kind enough and has the time to do it, a java example would be awesome.
Gravity is three-dimensional, so assume x, y and z coordinates.

Assuming that two bodies are both non-intersecting spheres with constant density, the force of gravity is m1 * m2 * G / r^2, where m1 is the mass of the first body, m2 is the mass of the second constant, r is the distance between the centres of both bodies, and G is the gravitational constant

G = 6.67300 × 10^-11 m^3 / (kg s^2)

The acceleration of the first body is m2 * G / r^2 in the direction of the second body, the acceleration of the second body is m1 * G / r^2 in the direction of the first body. For multiple bodies, calculate the acceleration for all pairs of bodies and add the accelerations for each body. Now all you need is a good differential equation solver and you are there

Things are considerably more complicated if the bodies in question, at least the larger ones, are not perfect spheres with constant density.
0
Dec 20, 2009, 05:16 PM   #12
MrFusion
macrumors 6502a

Join Date: Jun 2005
Location: West-Europe
Quote:
 Originally Posted by mkrishnan I am not a physicist, but it was my understanding that it is not an overly absurd understanding of relativistic theory that energy in the form of rest mass causes an object to distort the metric of spacetime, thereby causing the effect of gravity. Or that in the running quantum theory, that the higgs field gives a particle its mass, which in turn causes other particles to gravitate towards it.... I have a PhD already.
Indeed. No need to keep it simple for you.
Now let see if the LHC will detect the Higgs particle. It it does, it would confirm the standard theory. But from what I understand (it is not my field), that would be boring. Far more interesting for the community is apparently that the Higgs particle is not found. That way, they have to come up with a new theory.
__________________
24" iMac, 13" MacBook, iPod Touch. iPod mini and PowerPC Mac Mini gathering dust somewhere.
0

 MacRumors Forums

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules

 Similar Threads thread Thread Starter Forum Replies Last Post jent Mac Applications and Mac App Store 11 Mar 1, 2011 04:42 PM AndoverV Mac Basics and Help 1 Nov 9, 2010 07:20 PM Steradian Current Events 12 Jun 3, 2003 11:31 AM

All times are GMT -5. The time now is 05:14 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps
 Contact Us - MacRumors Forums - Archive - Privacy Statement / DMCA Agent - Top

Mobile Version | Fixed | Fluid | Fluid HD