Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 18 October 2012 - 08:50 PM
Posted 18 October 2012 - 10:56 PM
This m is the sun's mass, right? Not the planet's.But when I apply the force of gravity 'G = m/d^2'
What is your timestep? If it's too big errors will quickly creep in the simulation and ruin it. This could also be due to floating-point inaccuracy, losing a bit of precision every tick.If everything is set the way it's supposed to be, mercury gets it's correct orbit, venus is a little off, earth is a little more off and etc.
“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”
Posted 18 October 2012 - 11:34 PM
// time step is based off the time between frames float dt; const double G_Constant; Vec3 gravityAccel = (G_Constant*objMass/distSqu) * direction ; velocity -= gravityAccel * dt;
Edited by Muzzy A, 18 October 2012 - 11:39 PM.
Posted 18 October 2012 - 11:42 PM
Woh woh woh, what? Do you mean you sum up the gravitational accelerations from each object, right? You can't just take the sum of the mass of everything like that.'m' is the mass of everything, including the sun. Gravity from all objects affect all objects.
For objects in orbit, you can define a new coordinate system based on the tangent of the object with respect to the orbit. By definition, objects in orbit have velocity only in the tangential direction. Direction matters. If you don't set the velocity in the right direction the orbit will obviously be different (although in any case it will still form an orbit if the velocity is less than escape velocity).I have no tangential velocity, i just have normal velocity being affected by gravity.
What is objMass?? Is it the mass of the object exerting the force, or is it the mass of the object being affected?Vec3 gravityAccel = (G_Constant*objMass/distSqu) * direction ;
“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”
Posted 18 October 2012 - 11:53 PM
Posted 19 October 2012 - 12:12 AM
Edited by h4tt3n, 19 October 2012 - 12:12 AM.
Posted 19 October 2012 - 12:16 AM
No. F = ma. a = F/m, and the force is defined as F = G m1m2/r^2, so a = F/m = G m/r^2. This is correct. Gravitational acceleration is independent of the "receiving" object's mass.The value of gravityAccel is actually a force, not acceleration. You need to multiply it with mass to get the proper acceleration. Also, you need to include the masses of both objects in your gravity equation.
Edited by Bacterius, 19 October 2012 - 12:17 AM.
“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”
Posted 19 October 2012 - 08:04 AM
Posted 19 October 2012 - 08:28 AM
No. F = ma. a = F/m, and the force is defined as F = G m1m2/r^2, so a = F/m = G m/r^2. This is correct. Gravitational acceleration is independent of the "receiving" object's mass.
Posted 19 October 2012 - 11:06 AM
I may have to look up tangential velocity then
Edited by taby, 19 October 2012 - 11:15 AM.
Posted 19 October 2012 - 03:23 PM
You could experiment a little. Take two masses and draw them traveling at some random velocity (this implies direction too). Have a toggle button that either skips the gravitational force calculations or turns it on. When the button is toggled off all objects should continue in a straight line from their last computed velocity. This is an example of one of Newton's laws, an object at rest tends to stay at rest, an object in motion tends to stay in motion unless they are acted upon by an outside force. In particular this motion is linear. Then, click the toggle button to start computing gravitational force on each of the objects and soon they should be moving on a curved trajectory, assuming their velocity has some tangential component relative to the other.
Bacterius is correct. You have to supply the correct tangential velocity.
you're going into orbital elements, which was what i was trying to avoid lol. But i see your logic.I may have to look up tangential velocity then
Calculating the tangential velocity based on orbit parameters like distance/eccentricity:
http://www.gamedev.n...58#entry3961958
Periapsis velocity:
v = sqrt((G*M/a)*(1 + e)/(1 - e)).
The planet Mercury's semi-major axis a = 57909176e3 metres, and has an orbit eccentricity e = 0.20563069:
v = sqrt((6.6742e-11 * 1.988435e30 / 57909176e3) * (1 + 0.20563069) / (1 - 0.20563069)),
v = 58976.3015.
That's very close to the maximum orbit speed of Mercury, as 58980 m/s on wikipedia.org.
(Note, 1.988435e30 == Sun's mass)
Oppositely, for the apoapsis velocity:
v = sqrt((G*M/a)*(1 - e)/(1 + e)),
v = 38858.47.
For a circular orbit, the eccentricity is 0.
These calculations help you find the length of the tangential velocity vector. As for finding the direction of the tangential velocity vector, the cross product operation will help you (if your orbit plane is nice and aligned with the coordinate system, it's very straightforward).
Edited by Muzzy A, 19 October 2012 - 03:24 PM.
Posted 21 October 2012 - 07:14 AM
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.