Trying it out
6.10 Trying it out
Now that we have completed our implementation of gravitational forces, it is time to try it out. We can start by using the three ready-made scenarios defined in the Space class.
Exercise 6.24 With your completed gravity code, try out the three initialization methods from the Space object again (sunAndPlanet(), sunAndTwoPlanets(), and sunPlanetMoon()). What do you observe?
96 | Chapter 6 ■ Interacting objects: Newton’s Lab
Exercise 6.25 Experiment with changes in gravity (the GRAVITY constant at the top of the Body class).
Exercise 6.26 Experiment with changes to the mass and/or initial movement of the bodies (defined in the Space class).
Exercise 6.27 Create some new set-ups of stars and planets and see how they interact. Can you come up with a system that is stable?
Pitfall Be careful when using the constructor of class Vector. The constructor is overloaded: one ver-
sion expects an int and a double as parameters, the other expects two doubles. Thus new Vector(32, 12.0) will call one constructor, while new Vector(32.0, 12.0) will call the other constructor, resulting in an entirely different vector.
You will quickly see that it is very hard to configure the parameters so that the system remains stable for a long time. The combination of mass and gravity will often result in objects crashing into each other, or escaping from orbit. (Since we have not implemented a “crashing into each other”, our objects can essentially fly through each other. However, when they get very close, their force becomes very large and they often catapult each other onto strange trajectories.)
Some of these effects are similar to nature, although our simulation is a little inaccurate due to some simplifications we have made. The fact, for example, that all objects act in sequence, rather than simultaneously, will have an effect on the behavior and is not a realistic representation. To make the simulation more accurate, we would have to calculate all forces first (without moving) and then exe- cute all moves according to the previous calculations. Also, our simulation does not model the forces accurately when two bodies get very close to each other, adding more unrealistic effects.
We can also ask the stability question about our own solar system. While the orbits of the planets in our solar system are quite stable, precise details about their movement are hard to predict accu- rately for a long time into the future. We are quite certain that none of the planets will crash into the Sun in the next few billion years, but small variations in orbit may happen. Simulations such as ours (just much more accurate and detailed, but similar in principle) have been used to try to predict the future orbits. We have seen, however, that this is very hard to simulate accurately. Simulations can show that minute differences in the initial conditions can make huge differences
after a few billion years 3 .
3 If you are interested to read more, Wikipedia is a good starting point: http://en.wikipedia.org/wiki/ Stability_of_the_solar_system
6.11 Gravity and music
Seeing how difficult it is to come up with parameters that create a system that is stable even for
a limited time, we might be surprised that our solar system is as stable as it is. But there is an explanation: When the solar system formed, material from a gas cloud surrounding the Sun formed into lumps that slowly grew by colliding with other lumps of matter and combining to form ever-growing objects. Initially, there were countless of the lumps in orbit. Over time, some fell into the Sun, some escaped into deep space. This process ends when the only chunks left are well separated from one another and on generally stable orbits.
It would be possible to create a simulation that models this effect. If we correctly model the growth of planets out of billions of small, random lumps of matter, we would observe the same effect: Some large planets form that are left in fairly stable orbits. For this, however, we would need a much more detailed and complicated simulation and a lot of time: Simulating this effect would take a very, very long time, even on very fast computers.