• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Physics:How accruate?

Old topic!

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.

3 replies to this topic

### #1laeuchli  Members

Posted 22 August 2001 - 07:03 AM

Hey all, I''m in the process of writing a game, where there are a number of planets floating about, with various ships, and other space debris. I''d like to have the ships attrache to the planets, the planets to go around in a realistic way, and be able to calcuate the amount things should move based on the amount of force applied to them. My question is, how accurate should I be? Should I use the full equations from my physics book, and do the calculus for each object, or will this take to long? I guess my question is, where do I use the real equations, and where do I go for the hacks to save cpu time? Thanks, Jesse www.laeuchli.com/jesse/

### #2python_regious  Members

Posted 22 August 2001 - 07:19 AM

Well, for orbits etc, you could just set the planets going around in a circle, and use trig to find the next position it''s supposed to be etc. The correct way would be to use the gravitaional equation with centripetal acceleration, which would also produce spiralling decents into planets/suns etc if the orbiting objects are not going fast enough aswell as orbits ( all though setting up an orbit would be more differcult ). As for gravitational attraction, I can see no other way other than using the gravitational equation. It''s not complicated, so I can''t see it eating up the many CPU cycles either. You could also optimize it by discounting the gravitational force from bodies that are further than a designated distance away etc.

### #3Timkin  Members

Posted 26 August 2001 - 08:09 PM

For your game, you want a stable dynamical system. If you were to simulate each of your celestial objects and the interactions between them all, it would be extremely difficult to produce a system that did not decay or explode (ie all come crashing together or explode off into space). Escpecially given rounding errors in computers!

So, if you want to simulate a bunch of planets, asteroids and objects, then you''re going to have to cheat.

What you can do is this.

1) Simulate the orbits of objects using Keplar''s laws. These state that: 1) The path of an orbit of one object around another is an ellipse, where the central object is located at a focus of the ellipse; 2) That the straight line joining the two objects sweeps out equal areas in equal length timesteps; and, 3) that the square of the period of the orbit is proportional to the cube of the average radius of orbit. The average radius is equal to the length of the semi-major axis of the ellipse (which is just half the length of the major (longest) axis of the elipse).

You can use these facts to simulate objects orbiting one another where the mass of one object is significantly larger than the other. Works for planets and asteroids orbiting stars, space ships orbiting planets, stars or large asteroids, etc,...

Now, when you want to figure out how the motion of a space ship is perturbed by the gravitational effect of a bunch of planets, then you need to compute the force applied on the ship by each planet. Each planet exerts a force inversely proportional to the square of the distance between it and the space ship. The actual equation is:

F = GM1M2/R2

where:
G is the Universal Gravitational Constant
M1 is the mass of object one
M2 is the mass of object two
R the distance between them.

Project all forces as acting radially outward (in 3-D space) from the space ship and sum them to find the resultant force. Add to this the force generated by the space ships engines and you have the resultant force for the direction of motion of the ship. From this compute the acceleration and use a suitable integration routine to compute the new position of the space ship given its current position.

At each time step of the integration you will need to update the ships position and that of all of the planets. The computational cost of this method will be directly proportional to the number of celestial objects you are simulation.

Cheers,

Timkin

### #4TANSTAAFL  Moderators

Posted 29 August 2001 - 06:52 AM

In order to get an object into a stable orbit around another body, you need to balance two forces, the force of gravity and centripetal force.

As stated earlier, the force of gravity obeys the following equation:

F=(G*m1*m2)/(r*r)

Centripetal force is governed by this equation:

F=m*(v*v)/r

If we say that the m in the centripetal equation is the same as m1, then we can se these equal to one another like so:

(G*m1*m2)/(r*r)=m1*(v*v)/r

Cancel out the m1''s

G*m2/(r*r)=(v*v)/r

Cancel out one of the r''s

G*m2/r=(v*v)

And solve for v

v=sqrt(g*m2/r)

This v is a tangential velocity (i.e. it must be perpendicular to the radius between the objects at all times).

Old topic!

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.