numerical simulation of n-body orbits and interaction€¦ · 2.1 this table shows how the distance...
TRANSCRIPT
Indiana University of PennsylvaniaKnowledge Repository @ IUP
Theses and Dissertations (All)
Summer 8-2016
Numerical Simulation of N-Body Orbits andInteractionAshi Arwa
Follow this and additional works at: http://knowledge.library.iup.edu/etd
This Thesis is brought to you for free and open access by Knowledge Repository @ IUP. It has been accepted for inclusion in Theses and Dissertations(All) by an authorized administrator of Knowledge Repository @ IUP. For more information, please contact [email protected], [email protected].
Recommended CitationArwa, Ashi, "Numerical Simulation of N-Body Orbits and Interaction" (2016). Theses and Dissertations (All). 1370.http://knowledge.library.iup.edu/etd/1370
NUMERICAL SIMULATION OF N -BODY ORBITS AND INTERACTION
A Thesis
Submitted to the School of Graduate Studies and Research
in Partial Fulfillment of the
Requirements for the Degree
Master of Science
Arwa Ashi
Indiana University of Pennsylvania
August 2016
ii
Indiana University of Pennsylvania
School of Graduate Studies and Research
Department of Mathematics
We hereby approve the thesis of
Arwa Ashi
Candidate for the degree of Master of Science
______________________ ____________________________________
John C. Chrispell, Ph.D.
Assistant Professor of Mathematics, Advisor
____________________________________
Frederick A. Adkins, Ph.D.
Professor of Mathematics
____________________________________
Yu-Ju Kuo, Ph.D.
Associate Professor of Mathematics
ACCEPTED
___________________________________ _____________________
Randy L. Martin, Ph.D.
Dean
School of Graduate Studies and Research
Title: Numerical Simulation of N -Body Orbits and Interaction
Author: Arwa Ashi
Thesis Chair: Dr. John C. Chrispell
Thesis Committee Members: Dr. Frederick A. AdkinsDr. Yu-Ju Kuo
This research paper aims to build a mathematical simulation of a n-body prob-
lem in two dimensional space and study its temporal advancement. Moreover, the
paper examines the break-up of a satellite,“Moon” orbiting a larger mass,“Earth”.
It assumes an initial fragmentation of the satellite object. An example would be
break-up of a moon, potentially forming rings about a planet. In order to study this
system, this research builds a gravitational planet solar system simulation using a
fourth order Runge-Kutta method and varying model parameters.
iii
ACKNOWLEDGMENTS
يه أنيب . عليه توكلت وإل بالل وما توفيقي إل
My Guidance Cannot Come Except From Allah, In Him I Trust And Unto Him I Repent, [11:88] Quran.
Firstly, I would like to express my sincere gratitude to my advisor Prof. John C.
Chrispell for the continuous support of my study and related research, for his
patience, motivation, and immense knowledge. His guidance helped me in all the
time of research and writing of this thesis. I could not have imagined having a
better advisor and mentor for my study.
Besides my advisor, I would like to thank the rest of my thesis committee: Prof.
Frederick A. Adkins, and Prof. Yu-Ju Kuo, for their insightful comments and
encouragement, but also for the hard question which incented me to widen my
research from various perspectives.
Last but not the least, I would like to thank my family: my parents and to my
brothers and sister for supporting me spiritually throughout writing this thesis and
my life in general.
TABLE OF CONTENTS
PageChapter
1 INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Universal Planets . . . . . . . . . . . . . . . . . . . . . . 1
Roche Limit . . . . . . . . . . . . . . . . . . . . . . . . . 2
Previous Research . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Experiments . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 THE MATHEMATICAL MODEL . . . . . . . . . . . . . . . . . . . . 10
Newton Law . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Introduction of Fourth order Runge-Kutta Method . . . . . . . . 11
Building a Model of Gravitational Simulation . . . . . . . . . . . 13
Realistic Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Initial Placement of Orbiting Bodies . . . . . . . . . . . . . . . . 17
Building Gravitational Simulation of the Earth’s Moon . . . . . . 18
Ring Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3 RESULTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Table of Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Scope of Coding . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Proof of Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Result of Gravitational Nine Planets Simulation . . . . . . . . . 26
Result of Gravitational Earth’s Moon Simulation . . . . . . . . . 27
Earth’s Rings Simulation Result . . . . . . . . . . . . . . . . . . 28
4 CONCLUSIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5 REFERENCES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
APPENDICES
A. Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
v
LIST OF TABLES
Table Page
1.1 Planetary Fact Sheet - Metric 1: See reference [29] for more detail. . . . 3
2.1 This table shows how the distance from the Sun to each planet andmasses are adjusted to units appropriate for numerical simulation. . . 16
2.2 This table shows the results of adjusting each planets orbital velocitytransforming units of kilometers per second into units of Pixels per day. 17
2.3 Adjusting position of x and y of each planet. . . . . . . . . . . . . . . 18
3.1 Initial parameters of the gravitational simulation of the Nine planet model. 24
3.2 Initial parameters of the gravitational simulation of the Earth-moon sys-tem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.3 A comparison between fragmentation at the Roche limit with (210.054“pixel units”) and the lunar distance (3380.0 “pixel units”) over 2480time steps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
vi
LIST OF FIGURES
Figure Page
1.1 When a massive satellite enters the Roche limit, it is torn a part by themain planet’s tidal force. On the other hand, when small satellites en-ter the Roche limit, their enternal-gravity resists the the main planet’stidal force [12]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Ring systems for Jupiter, Saturn, Uranus, and Neptune, and how theylie within the Roche limit of each planet [4]. . . . . . . . . . . . . . . 5
2.1 This diagram illustrates the conservation of momentum when a singleplanet is fragmented into two parts. . . . . . . . . . . . . . . . . . . . 20
3.1 This figure shows the traced orbits of the nine-planet system. Tracking“Mercury” and ”Plot” in the simulation could not be seen as they aretoo close and far to the “Sun”. . . . . . . . . . . . . . . . . . . . . . 27
3.2 Simulation of an non-fragmented “moon” about a central planet show-casing the ability of our model to track both the moon and planetsposition over time as well as high lighting orbits. . . . . . . . . . . . 28
3.3 Two plots of the partial orbits observed in a fragmented Earth moonsystem at Lunar distance. . . . . . . . . . . . . . . . . . . . . . . . . 29
3.4 Illustrates the potential for formation of a ring system when the moon isfragmented with an initial placement at the Roche limit. Starting fromtop left and warring across and down, the plots show a scattering of thefragments in the fifth panel from the end orbital tracking is initiatedshowing the potential for rings to develop. . . . . . . . . . . . . . . . 32
3.5 Average number of fragments found in the 63 time steps where it is seenthat the number of fragment in the system stabilize after the initialinteractions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.6 More fragmentation is obsearved at the Roche limit as opposed to thelunar distance. As time goes on, more fragments at the Roche limitobserved than that in the lunar distance. . . . . . . . . . . . . . . . . 34
vii
3.7 A growth of the Earth mass after 2480 time steps. Larger growth at theRoche limit shows that initial proximity to the Earth influences thefragments interaction with the Earth. . . . . . . . . . . . . . . . . . . 35
viii
CHAPTER 1
INTRODUCTION
Background
Could the fragmentation of Earth’s Moon cause the Earth to have a system of
rings? The gravity and the interaction of celestial bodies have been a topic of study
for centuries. The interactions of orbiting bodies has sparked the imagination of both
scientists and artists. Recently in the novel Seveneves Neal Stephenson, postulates the
consequences of an agent causing Earth’s Moon to fragment into seven large pieces.
In the novel these larger fragments interact and cause further fragmentation. As the
time progresses these moon fragments revolve around the Earth and cause further
collisions and eventually cause a series of rings to form around the Earth made up of
the former moon. In the novel this creates an interesting backdroop for a story about
the servival of the human race [25]. In this work the fragmentation of an orbiting
satellite around a main celestial body is explored. Similar to Stephenson’s novel, here
a basic model with n-bodies is used in a 2 dimentional settiong to investigate the
fragmentation of the Earth’s moon. What effect would fragmentation of the moon
have, and could it create a system of orbiting rings? There is a study theorized that
Mars may develop a ring system around it due to the break up of one of its moons in
as little as 20 million years [6]. This thesis will explore simulations that model moon
fragmentation and study how the moon’s original distance to its orbiting planet effects
the fragmented system.
Universal Planets
When thinking of rings around planets the first planet that often comes to mind
is Saturn. Saturn’s ring system is the oldest in our Galaxy [10], and its study gives
insights into the infrastructure and formation of ringed systems. When compared to
the Earth, Saturn has approximately 60 moons. Having more than one moon increases
the probability of having collisions that would cause fragmentation and lead to the
creation Saturn’s ring system [23]. Creating a planet’s ring systems take millions of
years. However, using simulation, investigations of what may happen if Earth’s Moon
was to be fragmented can be completed in minutes, hours, or days.
The number of moon fragments in an orbiting system may increase or decrease
for several reasons. A recent study looking at near-earth objects (NEOs) describes
what may be happening to “the missing” NEOs. There are almost 9,000 NEOs within
our solar system. The early theory thought that NEOs disappeared or went missing in
space. However, the recent study shows that they actually break up near the sun [13].
This shows that NEOs do not stay in the orbit near the Earth, which leads to the
idea that if the moon breaks into several parts, some of the moon’s fragments will
be missing in the simulation. This is important because a not all of the fragments
from our simulations will wind up orbiting the Earth and may not become part of
the Earth’s rings system.
Our solar system consists of a Sun orbited by nine celestial bodies: Mercury,
Venus , Earth, Mars, Jupiter, Saturn, Uranus, Neptune and Pluto. To base our study
on a realistic standard Table 1.1 gives detailed information about our solar system.
The Earth has a mass of 5.97 × 1024 kg while its moon has a mass of 0.073 × 1024
kg. Also, the tables identify whether each of the planets has a ring system and how
many moons each planet has.
Roche Limit
The Roche limit defines as a distance away from a main planet that a satal-
ite held together by its own gravity will experience a tidal force large enough from
the main planet to fragment the satellite. The Roche limit is named after French
astronomer Edouard Roche, the first astronomer evaluating the limit in 1848 [26].
Fig 1.1 shows that if a massive satellite enters the Roche limit, it is torn apart by
2
Table 1.1. Planetary Fact Sheet - Metric 1: See reference [29] for more detail.MERCURY VENUS EARTH MOON MARS
Mass(1024kg) 0.33 4.87 5.97 0.073 0.642Diameter(km) 4879 “12,104” “12,756” 3475 6792Density(kg/m3) 5427 5243 5514 3340 3933Gravity(m/s2) 3.7 8.9 9.8 1.6 3.7Distance from Sun(106km) 57.9 108.2 149.6 0.384* 227.9Orbital Period(days) 88 224.7 365.2 27.3 687Orbital Velocity(km/s) 47.4 35 29.8 1 24.1Mean Temperature(C) 167 464 15 -20 -65Surface Pressure(bars) 0 92 1 0 0.01Number of Moons 0 0 1 0 2Ring System? No No No No No
JUPITER SATURN URANUS NEPTUNE PLUTOMass(1024kg) 1898 568 86.8 102 0.0146Diameter(km) “142,984” “120,536” “51,118” “49,528” 2370Density(kg/m3) 1326 687 1271 1638 2095Gravity(m/s2) 23.1 9 8.7 11 0.7Distance from Sun(106km) 778.6 1433.5 2872.5 4495.1 5906.4Orbital Period(days) 4331 10,747 30,589 59,800 90,560Orbital Velocity(km/s) 13.1 9.7 6.8 5.4 4.7Mean Temperature(C) -110 -140 -195 -200 -225Surface Pressure(bars) Unknown* Unknown* Unknown* Unknown* 0Number of Moons 67 62 27 14 5Ring System? Yes Yes Yes Yes No
the main planet’s tidal force. On the other hand, if a small satellite enters the Roche
limit, its self-gravity can resist the the main planet’s tidal force [12].
Saturn’s main rings systems,“rings A, Cassini Division, B, and C”, lie inside
Saturn’s Roche limit for ice (about 140,000 km from Saturn’s center). Additionally,
Saturn’s tidal force effects Saturn’s faint ring systems, E and G, because they are lo-
cated outside the Roche limit for ice [5]. Fig 1.2 shows ring systems for Jupiter,
Saturn, Uranus, and Neptune, and how they lie within the Roche limit of each
planet [4]. Consequently, a planet’s Roche limit and its tidal force cause interest-
ing natural phenomenon and make investigation of a planet’s rings system a worthy
academic endeavor.
3
Figure 1.1. When a massive satellite enters the Roche limit, it is torn a part by themain planet’s tidal force. On the other hand, when small satellites enter the Rochelimit, their enternal-gravity resists the the main planet’s tidal force [12].
Each planet has its own the Roche limit value based on the density, rotation,
and internal material strength of the planet and its satellites [27]. Here the Roche
limit is denoted by Rroche and is approximated by 24/3 of the main planet radius times
the third root of the main planet’s density over its satellite’s density. Thus,
Rroche = 243Rcenter
(ρMρm
) 13
where Rcenter is the radius of a planet and ρM and ρm are internal densities of a planet
and its satellite [24], respectively.
4
Figure 1.2. Ring systems for Jupiter, Saturn, Uranus, and Neptune, and how they liewithin the Roche limit of each planet [4].
In our Earth-Moon system the Roche limit is approximately 2.4 times of the
Earth’s radius (i.e. 18994.6 km from Earth’s center). The Moon lies outside of the
Earth’ Roche limit orbit at a distance of 384400 km. A potential fragmentation at
the Roche limit and smaller orbiting distances will be Examined. Chapter 2 contains
details and simulations regarding the formations of rings in an Earth-Moon system.
Previous Research
The Earth-Moon system and n-body problems have been studied extensively
in the past. The 2-body system has interesting effects on each other even at great
distances. The study of the interaction of celestial orbits and cycles is important when
as it effects geophysical phenomenon, biology, physics, and even social and cultural
aspects of life where calendars are used. Celestial orbits cause seasons, tides, and
circadian rhythms.
5
The Muslim Hijri calendar is based on a lunar cycle. The 13th, 14th and 15th
day of each month coincide with when the moon is fullest. This corresponds to when
the Moon is in the Earth’s magnetotail causing interesting particle charging to occur
on the lunar surface [18]. These particle charges may cause lunar dust storms and
have effects on temperature.
The moon may also have an effect on the Earth’s magnetic field. Specifically
the deep Earth may not be cooling down according to Julien Monteux and Denis
Andrault who postulate that the Moon plays a major role in maintaining Earth’s
magnetic field. The Earth’s mantle deforms elastically due to tidal effects caused by
the Moon. The Monteux and Andrault model illustrates that the Moon’s effect on
the Earth goes well beyond merely causing tides [14].
NASA’s MAVEN (Mars Atmosphere and Volatile Evolution) principal investi-
gator Bruce Jakosky, say that there is evidence that the Earth’s magnetic field has
weakened significantly in the previous 160 years and that neutralization of the mag-
netic field and flipping of magnetic poles could occur in less than 1,000 years – or as
early as the next 100 years [1]. Muslims astronomers through their science and Holy
book say, ”The Hour has come near, and the moon has split ”, [in two] {54 : 1}. This
points out that the moon has been splitted into two parts and that this occurred less
than 1400 years ago.
In August 2010, a team of researchers analyzing high-resolution images obtained
by the Lunar Reconnaissance Orbiter Camera (LROC) that recognized physical signs
of contraction on the lunar surface, in the form of lobe-shaped cliffs identified as lobate
scarps. The scarps are evidence that the moon shrank globally in the geologically
recent past and might still be shrinking today. They saw these scarps extensively
distributed crossways the moon and decided that it was shrinking as its interior
was slowly cooling [3]. The recent splited moon may be the catalyst for the recent
6
weakening of the Earth’s magnetic field. According to NASA scientist, fragmenting
Earth’s moon may cause defect in its magnetic field and allow solar radiation to enter
into the Earth’s atmosphere [14].
There are a lot of investigations about moon fragmentation. These studies
show that a planets’ ring system may be originated from the planet’s satellite system.
In 2015, Ryuki Hyodo and Keiji Ohtsuki showed that Saturn’s current ring system
could have been produced from the planet’s satellite system i.e. Saturn’s moon system
[11]. In 2016, a new study has found that one of Mars’s moons is starting to falling
apart and within 20 million years Mars may develop into a ring system [6]. Nikolai
Brilliantov discovered that solar-ring systems, such as Saturn’s ring system, have a
universally similar particle distribution [15].
Our solar system is a n-body system where 9 satellites orbit the main celestial
body (the Sun). The idea of the gravitational simulation of the solar system is close
to the idea of ring simulation i.e. n-celestial bodies orbit a main object under the
gravitational attraction of each body on all others in the system.
Experiments
Numerical simulations of the interaction of celestial bodies is not a new endeavor.
Rory Barnes, Thomas Quinn, Jack Lissauer and Derek Richardson performed n-
body simulations to model planetary growth via collision of orbiting bodies. Their
simulations required an enormous amount of compute time on supercomputers to
examine systems with a large number of orbiting bodies. Planetesimal growth from
a uniform swarm led to a new more realistic collisional model [2]. This was an
extension of Richardsons earlier work that incorporated a basic model for fractal
aggregation dynamics (fusing a collection of particles together through collision) [21].
In 2001, Stadel wrote a numerical gravity solver in the form of an n-body code
called “pkdgrav” for cosmological modeling using realistic particle distributions and
7
ray-tracing techniques [8]. A local patch model was incorporated by Porco in 2008
into pkdgrav to realistically simulate a patch of colliding, self-gravitating particles in
Saturn’s gravity field [19]. In 2009, Richardson incorporated the model into pkdgrav
[22], on which Randall Perrine studies n-body Cohesion in Dense Planetary Rings
using numerical simulations. Perrine’s model combined a local patch model [19]
and a cohesive aggregated model resulting in a local n-body code that may be used
when simulating a system that involves a large number of colliding and cohesive
bodies, incorporating ring dynamics and planetary system formation. The cohesive
aspects of his n-body model remain quite simple making this work tractable [16].
Later Perrine and Richardson applied parameters into their simulations resulting in
a model of Saturn’s dense A and B rings [16] that incorporates colliding particles or
fragment rigid aggregations to represent van der Waals forces or interlocking surface
frost layers. They found that weak cohesion is consistent with observations of the A
and B rings (e.g., French, R.G., Nicholson, [7]). Their model parameters showcase
observed differences between Saturn’s A and B ring systems [17].
The work of C.J. Voesenek used a fourth order Runge-Kutta Method to quickly
find and calculate reliable orbits in any gravity potential. The benefit of using a
fourth-order Runge-Kutta method are seen when the obtained velocity and position
information is reused to perform computational updates in the next time step. Voe-
senek’s method states that the fourth order Runge-Kutta method is stable at large
time steps, accurate and relatively fast [28]. Peter Reinhardt’s work outlines two
numerically integrated solutions for the Many-Body Gravity Simulation: the Euler
method, and the fourth order Runge-Kutta method. In his simulation, particles (ce-
lestial bodies) are started with zero velocity and randomly and uniformly distributed
throughout a three dimension space “a cubical space”. When objects collied in Rein-
hard’s simulations, one particle absorbs the other and the velocity and mass of the
resulting particle are recomputed in order to conserve momentum [20]. In the work
8
presented here ideas from the aforementioned research are used. Specifically a fourth
order Runge-Kutta method is used to investigate the gravitational attraction of an
n-body celestial system through simulation.
Details of the equations of mathematical model that was used in this paper are
presented in Chapter 2. Chapter 3 has the numerical results from the Gravitational
models including a comparison between the Roche limit and Lunar distance as a
starting point in the simulation. Chapter 4 states the key concepts seen from this
research as conclusions and directions for future work.
9
CHAPTER 2
THE MATHEMATICAL MODEL
In order to build a mathematical model of orbiting celestial bodies, a review of
the governing physical conservation laws is undertaken.
Newton Law
The magnitude of the gravitational force between two massive objects was stud-
ied by Newton in the 1680s. Newton’s second law shows how mass and acceleration
are related to force. Mathematically Newton’s second law is represented by
F = ma (2.1)
where F is force, m is mass, and a is acceleration.
The gravitational force between any two masses m1 and m2 is
F =Gm1m2
r2(2.2)
where G is universal gravitational constant i.e. G = 6.67300× 10−11 m3
kgs2, and r is the
distance between the center of mass for each of the masses m1 and m2.
Using calculus acceleration in (2.1) can be rewritten as a second derivative of
position
a =∂2x
∂t2.
Thus, Newton’s second law is mass times the second derivative of position, giving
F = m∂2x
∂t2(2.3)
where x is the position of an object and t denotes time, giving the driving relationship
for our mathematical model. In order to numerically solve this partial differential
equation a temporal advancement techniques will be needed. A common choice when
solving this type of differential equations is to use a Runge-Kutta method.
Introduction of Fourth order Runge-Kutta Method
Runge-Kutta methods are single-step discrete solvers for differential equations
where derivatives are approximated using finite differences. Time dependent simula-
tions are advanced from time tk to tk+1 based on forces, f evaluated at points between
tk and tk+1. To establish a Runge-Kutta method for a first order system of differen-
tial equations, consider the initial value problem of an ordinary differential equation
(ODE):
y′ = f(t, y(t)) (2.4)
y(t0) = y0 (2.5)
To develop a Runge-Kutta method, we follow the work presented in [9]. Start with
the fundamental theorem of calculus (FTC), integrate y′ = f(t), then,
y(t) = y0 +
∫ t
t0
f(s) ds. (2.6)
By applying (2.6) into (2.4) to evaluate the integral
yk+1 − yk =
∫ tk+1
tk
f(t, y(t))dt.
Using the chain rule on (2.4) gives
y′′ = ft(t, y) + fy(t, y)f(t, y).
Expanding f in a Taylor series in two variables gives
f(t+ h, y + hf) = f + hft + hfyf +O(h2).
11
Thus,
ft + fyf =f(t+ h, y + hf)− f(t, y)
h+O(h). (2.7)
Substitute (2.7) into the second-order method of Taylor series
yk+1 = yk + hky′k +
h2k2y′′k
becomes,
yk+1 = yk + hkf(tk, yk) +h2k2
f(tk + hk, yk + hkf(tk, yk))− f(tk, yk)
hk
= yk +hk2
(f(tk + hk, yk + hkf(tk, yk)) + f(tk, yk)).
This result is known as Heun’s Method and can be implemented in the form
yk+1 = yk +hk2
(k1 + k2)
where k1 = f(tk, yk) and k2 = f(tk + hk, yk + hkf(tk, yk)).
The fourth order Runge-Kutta method is developed the same way and it is
presented as:
yk+1 = yk +hk6
(k1 + 2k2 + 2k3 + k4) (2.8)
where hk is the time steps and the coefficient k1, k2, k3 and k4 are defined as
k1 = f(tk, yk),
k2 = f(tk +hk2, yk + k1
hk2
),
k3 = f(tk +hk2, yk + k2
hk2
),
k4 = f(tk +hk2, yk + k3hk).
Using the fourth order Runge-Kutta method leads to a smaller error term when com-
puting new position and velocity values when compared to Euler methods. Smaller
12
error terms are needed to ensure stability for larger time steps when computing orbits
in our modeling system [28].
Building a Model of Gravitational Simulation
When building a model of orbiting planets, consider the attractive force of some
other planet (indexed by j) acting on a planet indexed by i:
Fi = miai =Gmimj
r2= mi
∂2xi
∂t2=⇒ ai =
Gmj
r2(2.9)
where force Fi is defined by Newton’s second law as mass times the second derivative
of position ’acceleration’. Here mi denotes the mass of planet i, and mj is the mass
of an attracting planet indexed by j and xi is the position of planet i.
To build the gravitational simulation, each planet’s position, x, and velocity, v,
is updated by using the fourth order Runge-Kutta method. For ease of understand-
ing, and to reduce computational complexity, this work is conducted in only two
dimensions, but may be easily extended to three. By defining x, v, and a as a vec-
tors representing position, velocity, and acceleration in two components, sub-scripting
with x and y will be used to denote each component. Thus,
x =
xxxy
,v =
vxvy
and a =
axay
.To use a Runge-Kutta method to solve the n-bodies gravitational model the
governing equations must be written as a first order system. Here the conversion
of the second ordinary differential equations governing the system is done using the
relationship between position, velocity, and acceleration:
x′ = v
v′ = a
13
and the conversion will be written as,
x′ =
vxvy
and v′ =
axay
where the vx and vy are velocities, the ax and ay are accelerations, in equal direction
of space.
The general formula to compute the position and velocity for the next time step
are represented below by the solution of ODEs using the fourth order Runge-Kutta
methods (2.8), and acceleration is found using the representation in (2.9):
w =
xv
and w′ =
va
.In this mathematical model, the updating of position and velocity for the next
time step of the attractive force of some other planet (indexed by j) acting on planet
indexed by i in the system, are presented by the sum of forces:
Fi =n∑
j=1
Fj,where j 6= i
Thus,
wi =
xik+1
vik+1
where Fi is the fourth order Runge-Kutta method approximation solution in kth
time steps.In order to maintain a stationary reference frame the velocity of the main
celestial body (the Sun or Earth) is fixed to zero. xik+1 and vik+1 describe in the
following:
xik+1 = xik +hk6
(k1xik+1+ 2k2xik+1
+ 2k3xik+1+ k4xik+1
) (2.10)
vik+1 = vik +hk6
(k1vik+1+ 2k2vik+1
+ 2k3vik+1+ k4vik+1
) (2.11)
14
where hk is the time steps and the coefficients k1, k2, k3 and k4 are defined
k1xik+1= vik+1(tk,xik)
k2xik+1= vik+1(tk +
hk2,xik + k1xik+1
hk2
)
k3xik+1= vik+1(tk +
hk2,xik + k2xik+1
hk2
)
k4xik+1= vik+1(tk +
hk2,xik + k3xik+1
hk)
and,
k1vik+1= aik+1(tk,vik)
k2vik+1= aik+1(tk +
hk2,vik + k1vik+1
hk2
)
k3vik+1= aik+1(tk +
hk2,vik + k2vik+1
hk2
)
k4vik+1= aik+1(tk +
hk2,vik + k3vik+1
hk).
Realistic Model
As the first pass in modeling a n-body problem we start with a nine-planet
system similar to our own solar system. Success in managing a nine-planet system
will allow for a better understanding of larger systems when fragmentation of an
orbiting body is considered. In order to make the nine planet simulation realistic,
scale should be taken into account. The goal is to convert the universal standard units
to values appropriate for simulation. To make the needed conversions, the Planetary
Fact Sheet - in standard metric units is used [29]. A key aspect is the size of the
window that will be used to observe the system. The size of the output window or
our observing plot should encompass the full orbit of the farthest planet from the
Sun (our system center). When considering our solar system, the farthest orbiting
body or “planet” is Pluto with an average distance of 5906.4× 106km to the Sun. A
transfer to “pixel unit”, that fit the planetary system to out the monitor or screen
is made by setting a base “pixel unit” as 107 km. Thus, in our simulation of a nine
15
Table 2.1. This table shows how the distance from the Sun to each planet and massesare adjusted to units appropriate for numerical simulation.
Distance fromSun km
Distance fromSun (Pixel) mass kg mass Skg
MERCURY 5.79 (107km) 5.79 (Pixel) 0.33 (1024kg) 0.33 (Skg)VENUS 10.82 (107km) 10.82 (Pixel) 4.87 (1024kg) 4.87 (Skg)EARTH 14.96 (107km) 14.96 (Pixel) 5.97 (1024kg) 5.97 (Skg)MARS 22.79 (107km) 22.79 (Pixel) 0.642 (1024kg) 0.642 (Skg)JUPITER 77.86 (107km) 77.86 (Pixel) 1898 (1024kg) 1898 (Skg)SATURN 143.35 (107km) 143.35 (Pixel) 568 (1024kg) 568 (Skg)URANUS 287.25 (107km) 287.25 (Pixel) 86.8 (1024kg) 86.8 (Skg)NEPTUNE 449.51 (107km) 449.51 (Pixel) 102 (1024kg) 102.0 (Skg)PLUTO 590.64 (107km) 590.64 (Pixel) 0.0146 (1024kg) 0.0146 (Skg)
planet system:
1 pixel unit is 107 km.
Table 2.1 shows the adjusted distances in our Pixel framework for our solar system.
In addition the planets’ masses must be changed into appropriate “simulation units”.
Define a simulation kg as Skg where
1Skg = 1024kg.
Table 2.1 also gives details of this conversion. With these choices universal gravity
will have updated units using the following unit conversion
G ≈ 6.74× 10−20km3
kgs2≈
(6.74× 10−20
km3
kgs2
)(1Pixel
1× 107km
)3
≈
(6.74× 10−41
Pixel3
kgs2
)(86400s
1d
)2
≈
(4.98211× 10−31
Pixel3
kgd2
)
≈
(4.98211× 10−31
Pixel3
kgd2
)(1× 1024
1Skg
)≈
(4.98211× 10−7
Pixel3
Skgd2
).
The planets’ velocities must also be adjusted to “pixel units”. The results from
this adjustment are stated in Table 2.2.
16
Table 2.2. This table shows the results of adjusting each planets orbital velocitytransforming units of kilometers per second into units of Pixels per day.
Orbital Velocity km/s Pixel/daySun 0.0 0.0MERCURY 47.4 0.409536VENUS 35 0.3024EARTH 29.8 0.25742MARS 24.1 0.208224JUPITER 13.1 0.113184SATURN 9.7 0.083808URANUS 6.8 0.0587524NEPTUNE 5.4 0.046656PLUTO 4.7 0.40608
Initial Placement of Orbiting Bodies
After the planets’ distances from the Sun are adjusted into “pixel units”, an
initial position that yields a stable planetary orbit needs to be determined. In this
nine-planet model the initial position of each planet is set in a way that spaces the
planets around the Sun. The initial placement of planets in the system is done in
hoping that each planet will have a greater attraction to the Sun than that to the
other planets in the mathematical model.
The Sun is positioned in the middle of the plotted spatial region, a 1200 × 1200
pixel unit box. The Sun’s velocity is fixed to zero to maintain a stationary reference
frame. Table 2.3 shows the initial position and the velocity chosen for each of the
planets in our mathematical model. The assigned values are based on the values
in Table 2.1 and Table 2.2 with minor modifications to ensure the orbiting system
stable. Plots from the numerical simulation using these initial conditions are given in
Chapter 3.
17
Table 2.3. Adjusting position of x and y of each planet.x position y position velocity of x axis velocity of y axis
Sun 600.0 600.0 0.0 0.0MERCURY 600.0 594.21 0.26371969859 0.0362423611009VENUS 600.0 589.18 0.841810004715 0.240343746883EARTH 600.0 749.6 -0.177759577499 -0.0754366450966MARS 600.0 372.0 0.0536458655351 -0.0754366450966JUPITER 600.0 178.6 1.96697778225 -0.485436372127SATURN 833.5 1190.0 0.84539364043 -0.244297836619URANUS 874.13 50.0 0.373091224153 -0.244297836619NEPTUNE 144.45 10.0 0.418646550354 -0.159208435589PLUTO 590.0 -100.0 0.00568501382124 3.47457436434e-05
Building Gravitational Simulation of the Earth’s Moon
In this section a description of the second numerical experiment regarding the
fragmentation of a planet’s satellite or moon is given. Specifically considered is a sys-
tem similar to that of our Earth and Moon. Much as in Stephenson’s book Seveneves
an agent acts and fragments the moon into an unknown number of parts based on
some fragmenting parameters that are set. An exploration of what happens to these
fragments at different orbiting distances is considered.
In order to work in this new Earth-Fragmented Moon system a the base pixel
unit, the universal gravity will be reset and adjusted to reflect the new observation
window encompassing only the Moon’s distance from the Earth. Thus, the new pixel
unit will be based on the Moon’s distance from the Earth.
The universal gravity is adjusted to this Earth-Moon model. Using the Moon’s
distance, or Lunar distance from the Earth at 378, 000 km, defines 103 km as 1 pixel
18
unit. Then
G ≈ 6.74× 10−20km3
kgs2
≈
(6.74× 10−20
km3
kgs2
)(1Pixel
1× 103km
)3
≈
(6.74× 10−29
Pixel3
kgs2
)(1× 1024
1Skg
)
≈
(0.000067
Pixel3
Skgs2
).
The Moon’s mean orbital velocity is converted to the “pixel units”:
Linear Moon Velocity =
(1.022
km
s
)(Pixel
103km
)=
(0.001022
Pixel
s
).
The discrete time step sized used in the model will is per 800 second.
Ring Simulation
To investigate what would happen if Earth’s Moon is fragmented and the po-
tential for ring development, a code that allows for fragmentation of the moon into
n parts is written. The n fragments may orbit the earth, potentially creating a rings
system under the influence of Earth’s gravitational force. The Runge-Kutta method
discretely advances the system in time, and additional collisions between fragmented
orbiting bodies may occur causing additional fragmentation or the joining of the col-
liding bodies. Consequently with every time step, a change in the number of the
fragments may occur. At the first time step, the Earth and the moon (as n frag-
ments) will enter the system. The initial mass and velocity of the moon are used as
starting parameters to the fragmentation. The partitioning of the moon is done in
a while loop, while the mass to be fragmented is larger than a determined stopping
19
size the fragmented mass is split into two parts: the smaller part (between 1/4 and
1/100 of the mass to be fragmented) is added to the system, and the larger is used
as the new mass to be fragmented. Velocities are assigned at each step of the process
in order to conserve momentum. When considering conservation of momentum the
governing equation used is:
P = mv (2.12)
where P is momentum which equals to mass m times velocity v.
Figure 2.1. This diagram illustrates the conservation of momentum when a singleplanet is fragmented into two parts.
For a system of colliding planets, Fiq 2.1 shows conserve momentum in x and
y directions, and it is considered as,
m1v1x = m2v2x +m3v3x
m1v1y = m2v2y +m3v3y
where m1, v1x and v1y are a fixed value of the origin mass, x velocity and y velocity
respectively. m2, v2x, and v2y are a random value of the new small fragment represent
mass, x velocity, and y velocity respectively. The massive mass from the origin m3
20
and its velocities v3x and v3y can be calculated by using the fixed and random value.
Thus,
m3 = m1 −m2
v3x =m1v1x −m2v2x
m3
v3y =m1v1y −m2v2y
m3
.
The n-bodies fragmentation code is developed the same way, and it is presented in
the appendix. The moon is initially broken into n parts using a recursive algorithm
that conserves the original momentum in the system. Taking an initial object with
a known starting mass and velocity. The mass is split into two parts based on the
aforementioned fragmenting parameters. The smaller of the two fragmented part’s
velocity is selected randomly such that it is between (0.0001022, 0.00002044) “pixel
units” and the remaining portions velocity is fixed to conserve momentum. A random
epsilon is added to their initial position within two radius of the fragmented objects
original size. From the second time step to the last, the fragments may merge or the
fragments may collide changing the number of bodies in the system.
Merging of bodies occurs in instances where an orbiting object collides with the
system’s Earth. Additionally orbiting fragments will merge if a smaller massed, and
smaller velocity object occupies the same space as a larger faster moving fragment.
The merging of these fragments occurs when they are close enough to touch using
elastic collisions (conservation of total momentum). Specifically, if two fragments
touch, the distance should be less than the total radius of the two fragments.
distance =√
∆x2 + ∆y2
where ∆x and ∆y represent the difference between the two fragments x position and
y position respectively. If a fragment touches the main body ( the Earth ), a merging
will happen and the fragment’s mass will add to the Earth’s mass.
21
Thus, if any two fragments touch, two scenarios are considered: first, if a small
fragment with a high speed touches another fragment with a larger mass, they will
collide and more fragments will add to the system by using the previous fragmentation
conservation momentum strategy. Second, if a small fragment with a slower speed
touches another fragment with a larger mass, they will merge and the new mass and
velocity will be updated to conserve momentum.
In the research studies mentioned in Chapter 1, it was observed that most of the
ring systems are located inside a planets Roche limit (when using the 2.4 times the
planet’s radius approximation). Here our goal is expand this research to study the
moon’s fragmentation in two studies. First, a study of fragmenting the moon at what
we will call the Lunar distance is analyzed. The Lunar distance for our purposes will
be the original distance from the center of mass of the Earth to the center of mass
of the orbiting moon. In the lunar distance study fragmentation initially happens
at distance from the Earth to its moon and is equal to approximately 378, 000 km
or 3780 “pixel units” (where the estimation of 102 km is 1 “pixel unit”). A second
study is conducted that investigates fragmenting the moon at the what will be called
the “Roche limit” of the original Earth-Moon system. The Roche limit is calculated
using the planetary fact sheet presented in Chapter 1 where:
moon density = 3344 kg/m3, Earth density = 5514 kg/m3 and EarthEquatorial radius = 6378.1 km.
As a result, the Roche limit of the Earth is 189.946 “pixel units”. The equation below
shows the calculation of the Roche limit [24].
22
Rroche = 2×Rcenter
(2ρMρm
) 13
= 2× 6378.1
(2× 5514
3344
) 13
= 18994.6Km
= 189.946 Pixel
It will be shown in Chapter 3 that the results of the simulation depend on the
initial fragmentation placement with respect to distance from the Earth, and the
size of the fragments that the simulation started with. In both sets of simulations the
fragmented systems where seen to have rings that orbit the Earth potentially creating
a system of rings about the Earth.
23
CHAPTER 3
RESULTS
The results from the gravitational simulation of the Nine planet model, and
Earth moon system as described in Chapter 2 are shown and analyzed in this chapter.
Table of Values
Table 3.1 contains the base set of parameters used in the planet model. The time
t and time steps ∆t were chosen so that the simulation was stable. The universal
gravity, G, is set according to the chosen observation window. Table 3.2 contains
the base set of model parameters that were used for the gravitational simulation of
fragmented Earth-moon system. The time t, time steps ∆t, the universal gravity G,
Earth’s mass mE, the moon’s mass mM and the Earth’s and moon’s velocities were
chosen so that the simulation again was stable. “Sun’s velocity” in the nine-planet
model, and the “Earth’s velocity ” in the fragmented Earth-moon system was set to
zero. The reason behind that was to avoid the momentum of the reference window
used to observed the system.
Table 3.1. Initial parameters of the gravitational simulation of the Nine planet model.Parameter Symbol Value
Time t0 0Time Steps ∆t 2 daysThe universal gravity G 4.98211e-7 Pixel3/Skgd
2
In the Earth-moon system, the initial parameter of the moon is done based
on a set of, first, FragmentMoon which is a control parameter. If it is equal to
True then the code will start fragmenting the Moon. If it is set to False, the result
of code gives a two body system. The second parameter is related to adjusting
x position and y position of each celestial. Here we add a random epsilon to the
Table 3.2. Initial parameters of the gravitational simulation of the Earth-moon sys-tem.
Parameter Symbol Value
Time t 0 per secondTime Steps ∆t 800 per secondThe universal gravity G 0.000067 Pixel3/Skgs
2
Earth’s Mass mE 5.97Moon’s Mass mM 0.07342Earth’s velocity vE 0.0Moon’s velocity vM 0.001022 per second
position within 2 radius of the original size to force the fragments’ position starting
from the moon radius. The third parameter is set to adjust the velocity of x and
y which is a random velocity for the smaller mass fragment (last planet added). In
addition, fragmentation parameters for the Earth’s Moon contain adjustments to the
distance of both the moon and its fragments from the main object “Earth”. Since our
model is a two dimensional model, the x-position that the Moon starts from is 400.0
“pixel units”. For the y-position, we study two starting points, the lunar distance
which is 3780 “pixel units” ≈ 3380 ”pixel units” that places the fragment to fit the
resulting plot, and the Roche limit which is 189.946 “pixel units” ≈ 210.054 “pixel
units” that fits the result plotting. The simulation parameters contain adjustments
that affect the amount of moon fragments that the simulation starts with. To control
the size of the moon fragments, we set the size of fragmentation to (1/100, 1/4) of
the original object fragmented by defining parameters as splitIntMin, splitIntMax
and end when the object to be fragmented is smaller than a defined limit.
Scope of Coding
A simple two dimensional model for the computation of the gravitational sim-
ulation was developed by J. Chrispell. The code is written in Python. In order
to conduct our investigation involving gravitational simulation of the solar system,
25
J. Chrispell’s code was extended to use the fourth order Runge-Kutta method, and
the Pygame package for visualization. Additionally, fragmentation and merging of
planets was added. The results of all simulations are shown in the following sections.
Proof of Concept
As a first step a nine-planet solar system is simulated. The showing of the nine-
planets simulation is found using the model parameters in the Table 3.1. The time
steps size is important as it affects orbiting planets. The parameters used are based
on the fact sheet released by NASA [29] in hoping of a simulation result close to the
real solar system.
Result of Gravitational Nine Planets Simulation
The result of the gravitational solar system simulation by using the fourth order
Runge-Kutta method is shown in Fig. 3.1. The figure shows the orbit of the nine
planets around the sun. The time step size used in the simulation is approximately
per 2 days. “Pluto”, which is the furthest object from the Sun in the simulation,
takes the longest time to complete one orbit around the sun. The main factor that
controls the stability of a planet’s orbit is the momentum.
26
Figure 3.1. This figure shows the traced orbits of the nine-planet system. Tracking“Mercury” and ”Plot” in the simulation could not be seen as they are too close andfar to the “Sun”.
Result of Gravitational Earth’s Moon Simulation
The Earth’s moon gravitational simulation is created by using the same strategy
used in the solar system model. Here, the time step count size is shortened to 800
seconds. The same forth order Runge-Kutta method is used but the parameters are
set as in Table 3.2 Fig. 3.2 which shows the result of a non-fragmented Earth-moon
gravitational simulation. Here the moon’s orbit around the Earth’s orbit is tracked.
27
Figure 3.2. Simulation of an non-fragmented “moon” about a central planet show-casing the ability of our model to track both the moon and planets position over timeas well as high lighting orbits.
Earth’s Rings Simulation Result
This section investigates the potential for moon fragmentation to develop into
rings. Fig. 3.3 illustrates a tracking of the fragmented moon mass around the Earth,
and shows orbits of the moon’s fragments. The simulation starts with the moon frag-
mented at the lunar distance which is 3380.0 “pixel units”. Fig. 3.4 presents a tracking
of moon fragmentation around the Earth and shows orbits of the fragmentation. The
point that the simulation starts running is from the Roche limit which is 210.0 “pixel
units”. The gravitational Earth’s moon simulation is used with additional code for
the fragments. All masses are set to be greater than 0.0001 Skg to reduce the flight-
out of the fragments’ orbits. The radius is set to merge the fragments if they touch.
More detail in the following paragraphs will discuss merging.
28
Figure 3.3. Two plots of the partial orbits observed in a fragmented Earth moonsystem at Lunar distance.
To investigate the effect of fragmentation size on the orbits of fragments the
fragmentation parameters are altered. Parameters used allowed the simulations to
start between 1500 to 2500, 400 to 600, and 100 to 200 moon’s fragments. Fig. 3.5
shows the average amount of fragments which break from the moon during the 63
time steps. The high probability of merging and fragmentation was in 1500 to 2500
fragments that the simulation started with. However, in a range of 100 to 200 moon’s
fragments, a collision and join rarely happened in the first 63 time steps and the
simulation runs with stable fragments numbers and orbits. Overall, in the second
time step collisions happened which tended to increase the amount of the fragments.
Later, a merging happens to the fragments which decreases them dramatically with
a stable orbit of each fragment. As a result, a focusing in the fragmentation with a
range of 1500 to 2000 will be discussed in the following.
After studying the effect of applying different fragmentation into the system, the
effect of different starting points on the system is considered by studying the starting
distance of the fragmentation from “ Earth”. Fig. 3.6 shows a comparison between
29
fragmentation at the Roche limit with (210.054 “pixel units”) and the lunar distance
(3380.0 “pixel units”) over 2480 time steps. Table 3.3 presents a brief summary data
resulting from 30 simulation. Some simulations did not finish due to the large number
of the fragment seen in the system and increase computational costs. The average
number of fragments that the simulation started with was 1732.366667. The study
of the fragmentation behavior in the lunar distance and at the Roche limit yields:
1. In the lunar distance after 40th time step, is 1303.4 fragments.
2. In the Roche limit in after 40th time step, is 1871.266667 fragments.
3. In the lunar distance in the 2480 time step, is 2113.2 fragments.
4. In the Roche limit in the 2480 time step, is 2373.8 fragments.
Fig 3.7 illustrates an increase in the Earth’s mass during 2480 time step of the simu-
lation. For Lunar distance the average increasing of Earth mass is 0.002184735 Skg.
For the Roche limit the average increasing of Earth mass is 0.044159635 Skg. A higher
number of fragments merge with the Earth during the simulation in the Roche limit
than that in the Lunar distance. The reason is the Roche limit is closer to the Earth
that allows more fragments to merge than that in the lunar distance.
As a conclusion, the number of fragments has a greater increase in the Roche
limit when compared to the lunar distance. Even though a lot of fragments joined
the Earth mass in the simulation at the Roche limit, collisions keep up the fragmen-
tation and the simulation stop with a higher average number of fragments than those
conducted at the lunar distance. The increase of the fragments in the Roche limit
tend to create a ring system by revolving the fragments around the Earth. Another
conclusion is that the simulation result shows that the fragments at lunar distance
will orbit the Earth outside the Roche limit. This is similar to Saturn’s ring E and
G that are located outside Saturn’s Roche limit for ice. Additionally, the simulation
30
result shows if the moon breaks apart in the lunar distance, a number of the fragments
merge with the Earth.
Table 3.3. A comparison between fragmentation at the Roche limit with (210.054“pixel units”) and the lunar distance (3380.0 “pixel units”) over 2480 time steps.
Fragment numbersDistance At 1st time step At 40 time step At 2480 time step Earth’s Mass at 2480 time step
Lunar 1646 1657 1657 5.97Lunar 1862 5678 5678 5.97Lunar 1841 2960 2960 5.97Lunar 1657 1706 1708 5.97Lunar 1736 1807 2178 5.971715527Lunar 1628 1675 3323 5.978912177Lunar 1486 5988 5988 5.97Lunar 1776 1857 1857 5.97Lunar 1684 1695 1695 5.97Lunar* 1680 3229 11911 5.97Lunar 1764 2869 4313 5.983036636Lunar 1718 1774 1774 5.979106687Lunar 1777 1809 1809 5.97Lunar* 1808 8910 8910 5.97Lunar* 1830 1830 1830 5.97Roche 1789 6284 6284 6.014054341Roche 1679 4538 4538 5.99128178Roche 1664 1762 1762 6.007860225Roche 1823 4368 4368 6.002744768Roche 1744 3505 3515 6.013502991Roche 1768 3149 3149 6.004384902Roche 1706 2667 4867 6.034651863Roche 1765 1832 1832 6.008361871Roche 1688 2616 4798 6.027350316Roche 1555 4009 4009 6.017343298Roche* 1831 1831 1831 5.97Roche 1731 5943 6729 6.01893851Roche 1642 7340 7340 6.021156042Roche 1808 2411 4771 6.073712701Roche 1885 1892 1892 6.007050917
31
Figure 3.4. Illustrates the potential for formation of a ring system when the moonis fragmented with an initial placement at the Roche limit. Starting from top leftand warring across and down, the plots show a scattering of the fragments in thefifth panel from the end orbital tracking is initiated showing the potential for ringsto develop.
32
Figure 3.5. Average number of fragments found in the 63 time steps where it is seenthat the number of fragment in the system stabilize after the initial interactions.
33
Figure 3.6. More fragmentation is obsearved at the Roche limit as opposed to thelunar distance. As time goes on, more fragments at the Roche limit observed thanthat in the lunar distance.
34
Figure 3.7. A growth of the Earth mass after 2480 time steps. Larger growth atthe Roche limit shows that initial proximity to the Earth influences the fragmentsinteraction with the Earth.
35
CHAPTER 4
CONCLUSIONS
Building a solar system to simulate fragmentation of Earth’s moon into a ring
system in real-life is impossible. The creation of a computer model offers a feasible
option when examining the fragmentation of Earth’s moon. Here numerical simula-
tions of celestial bodies and the potential of Earth to form rings was examined using
a Fourth order Runge-Kutta method. This model allowed us to see how:
1. A satellite orbits the Earth and the impact of the satellite’s velocity, mass andinitial position on its orbit.
2. Orbiting objects interact with other objects in space. Specifically an objectstrajectory could be observed in order to see if it will collide with other planetsor burns up in a star.
3. Planets’ rings could be created under fragmentation of their orbiting satellitesystem.
4. Potential fragmentation near Earth objects could effect the Earth.
The Earth and fragmenting moon model presented here explored the potential
of a different number of fragments and the distance from the main object (Earth) at
the start the simulation. It was observed that a high amount of fragments at the start
increased the probability of their collision, which consequently increases the amount
of the fragments that were orbiting the Earth. Throughout the thesis, it seems that
the Roche limit (denoting a critical threshold distance) had an affect on increasing
the total number of objects orbiting a main mass. The research data showed that
if the starting orbital point where fragmentation was initiated was set beyond the
Roche limit less interaction between celestial bodies occurred resulting in fewer total
orbiting bodies.
The code created to undertake this thesis which simulates n-bodies orbital in-
teraction could be extended and potentially used in computational chemistry. The
model could also be expanded to 3-dimensional space, and extended to include a study
of the relationship between the moon and Earth’s magnitude field. Further model
development could address the issue of time scales where information is lost during
a collision (taking fractions of a second) compared to the time needed for a moon or
planet to completely orbit a central body (taking days, weeks, or even years).
37
References
1. J. Austin. Nasa: Earth’s magnetic poles are ‘switching’ with catastrophicconsequences for humanity. 2015.
2. R. Barnes, T. R. Quinn, J. J. Lissauer, and D. C. Richardson. N-body simulationsof growth from 1 km planetesimals at 0.4 au. Icarus, 203:626–643, 2009.
3. D. Brown. Nasa spacecraft reveals recent geological activity on the moon. 2012.
4. E. Chaisson. Astronomy today + masteringastronomy starry night college studentaccess code card. [s.l.] : Benjamin-cummings, 2010.
5. Esposito Larry Krimigis Stamatios (Eds.) Dougherty, Michele. Saturn AfterCassini-Huygens. the scientific results of Cassini-Huygens, 2009.
6. R. Feltman. Mars might get rings just like saturn’s one day. The demise of Phobosand development of aMartian ring system, 2015.
7. R.G. French and P.D. Nicholson. Saturn’s Rings II. Particle Sizes Inferred fromStellar Occultation Data. , 145:502–523, June 2000.
8. F. Governato, S. Ghigna, B. Moore, T. Quinn, J. Stadel, and G. Lake.The descendants of lyman break galaxies in galaxy clusters: Spatialdistribution and orbital properties. The Astrophysical Journal, 547(2):555,2001.
9. M. T. Heath. Scientific Computing An introductory Survey, Second edition. TheMcGraw-Hill Companies, Inc, 2002.
10. J. Henry. The age and fate of saturn’s rings.
11. R. Hyodo and Keiji Ohtsuki. Saturn’s f ring and shepherd satellites a naturaloutcome of satellite system formation. pages 686–689, 2015.
12. K. R. Lang. The roche limit, 2010.
13. R. Jedicke B. Bolin W. F. Bottke E. Beshore D. Vokrouhlicky M. DelboM. Granvik, A. Morbidelli and P. Michel. Super-catastrophic disruptionof asteroids at small perihelion distances. The Journal Nature, 530, 1967.
14. J. Monteux and D. Andrault. The moon thought to play a major role inmaintaining earth’s magnetic field. Earth and Planetary Science Letters,443:195—-203, 2016.
15. Astronomy Now. Scientists solve age-old planetary ring riddle. Proceedings of theNational Academy of Sciences (PNAS), 2015.
16. R. Perrine. N-body simulations with cohesion in dense planetary rings. 2011.
17. R. P. Perrine and D. C. Richardson. N-body simulations of cohesion in denseplanetary rings: A study of cohesion parameters. Icarus, 219:515–533,2011.
18. T. Phillips. Earth’s magnetic field does strange things to the moon. 2008.
19. C. C. Porco, J. W. Weiss, D. C. Richardson, L. Dones, T. Quinn, and H. Throop.Simulations of the dynamical and light-scattering behavior of saturn’srings and the derivation of ring particle and disk properties. TheAstronomical Journal, 136(5):2172, 2008.
20. P. Reinhardt. Many-body gravity simulation using multivariable numericalintegration. 2007.
21. D. C. Richardson. A self-consistent numerical treatment of fractal aggregatedynamics. Icarus, 115:320–335, 1995.
22. D. C. Richardson, T. Quinn, J. Stadel, and G. Lake. Direct large-scale n-bodysimulations of planetesimal dynamics. Icarus, 143:45–59, 2000.
23. D. Roche. What is the roche limit? 2015.
24. F. H. Shu. The Physical Universe: An Introduction to Astronomy, volume 584.University Science Books, 1982.
25. N. Stephenson. Seveneves. William Morrow, 2015.
26. D. Stillman. Ring-a-round the saturn. the NASA Knows! (Grades K-4) series,2015.
27. M. S. Tiscareno, M. M. Hedman, J. A. Burns, and J. Castillo-Rogez.Compositions and origins of outer planet systems: Insights from the rochecritical density. 2013.
28. C.J. Voesenek. Implementing a fourth order runge-kutta method for orbitsimulation. 2008.
29. D. R. Williams. Planetary fact sheet - metric. 2015.
39
Appendix A
Code
Listing 1. The Gravitational simulation of the solar systemimport matp lo t l ib . pyplot as p l timport mathimport osimport pygameimport randomfrom c o l l e c t i o n s import d e f a u l t d i c timport s o l a rCo l o rPa l e t t e
”””John C h r i s p e l l and Arwa Ashi
Code f o r a g r a v i t y s imu l a t i o n o f t h e n−body s o l a r system prob lem us ing PyGame and conve r t .Using a f o u r t h order Runge−Kutta method .
”””
pygame . i n i t ( )
# The window s i z e i s s e t t i n g by how f a r P lu to i s !WIDTH, HEIGHT = 1200 , 1200WIDTHD2, HEIGHTD2 = WIDTH/2 . , HEIGHT/2 .
# Def ine t h e Universe we g e t to p l a y w i th c u r r e n t l y and empty g l o b a l l i s t .#G = 6.674∗10∗∗(−11) # mˆ3 /( kg s ˆ2)#G = 6.674∗10∗∗(−20) # kmˆ3/ ( kg s ˆ2)global PlanetsMadePlanetsMade = 0
# Def ine a s t a t e c l a s s t h a t h o l d s t h e p l a n e t s p o s i t i o n and v e l o c i t y .class PlanetState :
def i n i t ( s e l f , x , y , vx , vy ) :s e l f . x = x # Current p o s i t o n .s e l f . y = ys e l f . vx = vx # Current v e l o c i t ys e l f . vy = vy
def dumpValues ( s e l f ) :print ”Dump Planet State : ”print ” x = ” , s e l f . xprint ” y = ” , s e l f . yprint ” vx = ” , s e l f . vxprint ” vy = ” , s e l f . vy
class Der iva t i v eS ta t e :def i n i t ( s e l f , vx , vy , ax , ay ) :
s e l f . vx , s e l f . vy , s e l f . ax , s e l f . ay = vx , vy , ax , ay ;def dumpValues ( s e l f ) :
print ”Dump Der iva t ive Values : ”print ” vx = ” , s e l f . vx , ” vy = ” , s e l f . vy , ” ax = ” , s e l f . ax , ” ay = ” , s e l f . ay
# Def ine t h e c l a s s s t r u c t u r e f o r our p l a n e t sclass Planet :
def i n i t ( s e l f , mass , x , y , vx , vy , Look , rho = 0 . 00334 ) :global PlanetsMades e l f . index = PlanetsMade ;PlanetsMade += 1 ;print ’ h i i am the t o t a l number ’ , PlanetsMades e l f . Mass = mass # ( kg )s e l f . State = PlanetState (x , y , vx , vy )s e l f . c o l o r = (255 , 255 , 255) #d e f a u l t t o wh i t es e l f . Look = str ( Look ) # The l o o k o f t h e o b j e c t .
# Set t h e r ad i u s o f t h e p l a n e t u s ing i t s mass and a d e n s i t y .# kg /(kmˆ3) (3 . 34 e12 −−> Dens i t y o f Earth ’ s Moon)# kg /(kmˆ3) (5 . 51 e12 −−> Dens i t y o f Earth )# kg /(kmˆ3) (3 . 93 e12 −−> Dens i t y o f Mars )# kg /(kmˆ3) (5 . 24 e12 −−> Dens i t y o f Venus )
s e l f . rho = rhos e l f . r ad ius = 1 .0#((3 . 0∗ s e l f . Mass ) / ( 4 . 0∗ s e l f . rho∗math . p i ) )∗∗ ( 1 . 0 / 3 . 0 ) #s e l f . setRadiusFromMass ( )s e l f . merged = False#pr i n t ” r ad i u s ” , s e l f . r a d i u s
def getColor ( s e l f ) :return s e l f . c o l o r
def s e tCo lo r ( s e l f , inputColor ) :s e l f . c o l o r = inputColor
40
return True
def dumpValues ( s e l f ) :print ” Mass = ” , s e l f . Massprint ” Density = ” , s e l f . rhoprint ” Radius = ” , s e l f . r ad iuss e l f . State . dumpValues ( )print ” look = ” , s e l f . Look
def Acce l e r a t i on ( s e l f , G, SolarSystem , s t a t e ) :# Compute t h e a c c e l e r a t i o n o f o t h e r p l a n e t s on cu r r en t p l a n e t .ax = 0 . 0 ;ay = 0 . 0 ;for p in SolarSystem :
i f p i s s e l f or p . merged :continue
# Loop over t h e o t h e r l o c a l p l a n e t s .# Get t h e d i s t a n c e between s e l f and o t h e r p l a n e t s .dx = p . State . x − s t a t e . xdy = p . State . y − s t a t e . yr s = (dx∗dx + dy∗dy )r = (dx∗dx + dy∗dy )∗∗0 .5f o r c e = G∗p . Mass∗ s e l f . Mass/ r s i f rs>1e−10 else 0 .ax += fo r c e ∗(dx/ r )ay += fo r c e ∗(dy/ r )
return ( ax , ay )
def RKStep1SystemPrime ( s e l f , G, SolarSystem , s t a t e ) :ax , ay = s e l f . Acce l e r a t i on (G, SolarSystem , s e l f . State )return Der iva t i v eS ta t e ( s t a t e . vx , s t a t e . vy , ax , ay )
def RKStep2t4SystemPrime ( s e l f , G, SolarSystem , s tate , d e r i va t i v eS ta t e , dt ) :newState = PlanetState ( 0 . 0 , 0 . 0 , 0 . 0 , 0 . 0 )newState . x = s t a t e . x + de r i v a t i v eS t a t e . vx∗dtnewState . y = s t a t e . y + de r i v a t i v eS t a t e . vy∗dtnewState . vx = s t a t e . vx + de r i v a t i v eS t a t e . ax∗dtnewState . vy = s t a t e . vy + de r i v a t i v eS t a t e . ay∗dtax , ay = s e l f . Acce l e r a t i on ( G, SolarSystem , newState )return Der iva t i v eS ta t e ( newState . vx , newState . vy , ax , ay )
def updatePositionRK4 ( s e l f , G, SolarSystem , dt ) :k1 = s e l f . RKStep1SystemPrime (G, SolarSystem , s e l f . State )k2 = s e l f . RKStep2t4SystemPrime (G, SolarSystem , s e l f . State , k1 , dt ∗0 .5 )k3 = s e l f . RKStep2t4SystemPrime (G, SolarSystem , s e l f . State , k2 , dt ∗0 .5 )k4 = s e l f . RKStep2t4SystemPrime (G, SolarSystem , s e l f . State , k3 , dt )# Use the RK va l u e s .dxdt = ( 1 . 0 / 6 . 0 )∗ ( k1 . vx + 2 .0∗ ( k2 . vx + k3 . vx ) + k4 . vx )dydt = ( 1 . 0 / 6 . 0 )∗ ( k1 . vy + 2 .0∗ ( k2 . vy + k3 . vy ) + k4 . vy )dvxdt = ( 1 . 0 / 6 . 0 )∗ ( k1 . ax + 2 .0∗ ( k2 . ax + k3 . ax ) + k4 . ax )dvydt = ( 1 . 0 / 6 . 0 )∗ ( k1 . ay + 2 .0∗ ( k2 . ay + k3 . ay ) + k4 . ay )# Update t h e p o s i t i o n and v e l o c i t y .s e l f . State . x += dxdt∗dts e l f . State . y += dydt∗dts e l f . State . vx += dvxdt∗dts e l f . State . vy += dvydt∗dt
# Set up the r ad i u s o f each f ragment sdef setRadiusFromMass ( s e l f ) :
””” Rever s ing t h e setMassFromRadius formula , t o c a l c u l a t e r ad i u s frommass ( used a f t e r merging o f two p l a n e t s − mass i s added , and newrad i u s i s c a l c u l a t e d from t h i s ) ”””s e l f . r ad ius = (3 .∗ s e l f . Mass /( s e l f . rho ∗4.∗math . p i ) )∗∗ ( 0 . 3333 )
def updatePos i t i ons (G, SolarSystem , dt ) :#pr i n t ”Update Po s i t i o n ”for i in range ( len ( SolarSystem ) ) :
# Loop through th e p l a n e t s and move t h e i r p o s i t i o n s .i f ( i > 0 ) :
cur rentPlanet = SolarSystem [ i ]cur rentPlanet . updatePositionRK4 (G, SolarSystem , dt )
def d i s tance ( Planet1 , Planet2 ) :# Returns d i s t a n c e between two p l a n e t o b j e c t s .d i s t = ( ( Planet1 . State . x − Planet2 . State . x )∗∗2 .0 + ( Planet1 . State . y − Planet2 . State . y )∗∗ 2 . 0 )∗∗ ( 0 . 5 ) ;return d i s t
def p l o tPo s i t i o n s ( SolarSystem , frame ) :p l t . f i g u r e ( )p l t . ax i s ( [−4 ,4 ,−4 ,4 ] ) ;for i in range ( len ( SolarSystem ) ) :
s c r een=pygame . d i sp l ay . set mode ( (WIDTH, HEIGHT))x = int ( SolarSystem [ i ] . State . x )y = int ( SolarSystem [ i ] . State . y )s c r een . s e t a t ( ( x , y ) , ( 215 , 212 , 207))
FileName = ”System” + str ( frame ) . z f i l l ( 4 ) + ” . png” ;p l t . s a v e f i g ( FileName )p l t . c l o s e ( )
def i n c r ea s e Index ( SolarSystem ) :for i in range ( len ( SolarSystem ) ) :
SolarSystem [ i ] . updateIndex ( ) ;
41
def PrintSolarSystem ( SolarSystem ) :for i in range ( len ( SolarSystem ) ) :
print ”Planet Index = ” , i ;SolarSystem [ i ] . dumpValues ( ) ;
def main ( ) :pygame . i n i t ( )s c r een=pygame . d i sp l ay . set mode ( (WIDTH, HEIGHT))
keysPressed = d e f a u l t d i c t (bool )def planetsTouch (p1 , p2 ) :
dx = p1 . s t a t e . x − p2 . s t a t e . xdy = p1 . s t a t e . y − p2 . s t a t e . ydsq = dx∗dx + dy∗dydr = math . sq r t ( dsq )return dr<=(p1 . r + p2 . r )
def ScanKeyboard ( ) :while True :
# Update t h e k ey sPre s s ed s t a t e :evt = pygame . event . p o l l ( )i f evt . type == pygame .NOEVENT:
breake l i f evt . type in [ pygame .KEYDOWN, pygame .KEYUP] :
keysPressed [ evt . key ] = evt . type == pygame .KEYDOWN
# s e t up th e mass o f each p l a n e t s .G = 4.98211 e−7SolarSystem = [ ] ;SunMass = 1988500MercuryMass = 0.330VenusMass = 4.87EarthMass = 5.97MarsMass = 0.642JupiterMass = 1898SaturnMass = 568UranusMass = 86 .8NeptuneMass = 102PlutoMass = 0.0146
#s e t up th e v e l o c i t y o f each p l a n e t sMercuryVelos ity = 0.409536Venusve loc i ty = 0.3024Ear thve l o c i ty = 0.257472Marsve loc i ty = 0.208224Jup i t e r v e l o c i t y = 0.113184Satu rnve l o c i ty = 0.0838080Uranusve loc i ty = 0.0587520Neptuneve loc i ty = 0.0466560P lu tove l o c i t y = 0.0406080
# Set up the momentum ang l edef Angle ( raduise , mass , speed ) :
ang le = radu i s e ∗ mass ∗ speedi f angle > 360 :
ang le −= 360angleRad = angle ∗ 0.0174532925return angleRad
# Set up the p l a n e t sSun = Planet ( SunMass , 600 .0 , 600 .0 , 0 . 0 , 0 . 0 , ’ co ’ ) ;
Mercury = Planet (MercuryMass , 600 .0 , 594 .21 ,0 .65∗MercuryVelos ity∗math . cos ( Angle ( 57 . 9 , MercuryMass , MercuryVelos ity ) ) ,0 .65∗MercuryVelos ity∗math . s i n ( Angle ( 57 . 9 , MercuryMass , MercuryVelos ity ) ) , ’ ro ’ ) ;
Venus = Planet (VenusMass , 600 .0 , 589 .18 ,2 .895∗ Venusve loc i ty ∗math . cos ( Angle (10 . 82 , VenusMass , Venusve loc i ty ) ) ,2 .895∗ Venusve loc i ty ∗math . s i n ( Angle (10 . 82 , VenusMass , Venusve loc i ty ) ) , ’ ro ’ ) ;
Earth = Planet ( EarthMass , 600 .0 , 749 .6 ,−0.75∗Ear thve l o c i ty ∗math . cos ( Angle (14 . 96 , EarthMass , Ear thve l o c i ty ) ) ,−0.75∗Ear thve l o c i ty ∗math . s i n ( Angle (14 . 96 , EarthMass , Ear thve l o c i ty ) ) , ’ ro ’ ) ;
Mars = Planet (MarsMass , 600 .0 , 372 .1 ,+0.258∗Marsve loc i ty ∗math . cos ( Angle (22 . 79 ,MarsMass , Marsve loc i ty ) ) ,+0.258∗Marsve loc i ty ∗math . s i n ( Angle (22 . 79 ,MarsMass , Marsve loc i ty ) ) , ’ ro ’ ) ;
Jup i t e r = Planet ( JupiterMass , 600 . , 178 .6 ,−17.9∗ Jup i t e r v e l o c i t y ∗math . cos ( Angle (77 . 86 , JupiterMass , J up i t e r v e l o c i t y ) ) ,−17.9∗ Jup i t e r v e l o c i t y ∗math . s i n ( Angle (77 . 86 , JupiterMass , J up i t e r v e l o c i t y ) ) , ’ ro ’ ) ;
Saturn = Planet ( SaturnMass , 833 .5 , 1190 ,10 .5∗ Satu rnve l o c i ty ∗math . cos ( Angle (143 . 35 , SaturnMass , Sa tu rnve l o c i ty ) ) ,10 .5∗ Satu rnve l o c i ty ∗math . s i n ( Angle (143 .35 , SaturnMass , Sa tu rnve l o c i ty ) ) , ’ ro ’ ) ;
Uranus = Planet (UranusMass , 874.13 , 50 . ,7 .0∗ Uranusve loc i ty ∗math . cos ( Angle (287 . 25 , UranusMass , Uranusve loc i ty ) ) ,7 .0∗ Uranusve loc i ty ∗math . s i n ( Angle (287 .25 , UranusMass , Uranusve loc i ty ) ) , ’ ro ’ ) ;
42
Neptune = Planet (NeptuneMass , 144 .45 , 10 . ,9 .6∗ Neptuneve loc i ty ∗math . cos ( Angle (449 . 51 , NeptuneMass , Neptuneve loc i ty ) ) ,9 .6∗ Neptuneve loc i ty ∗math . s i n ( Angle (449 .51 , NeptuneMass , Neptuneve loc i ty ) ) , ’ ro ’ ) ;
Pluto = Planet ( PlutoMass , 590 .0 , −100.0 ,+0.14∗ Plu tove l o c i t y ∗math . cos ( Angle (590 . 64 , PlutoMass , P lu t ove l o c i t y ) ) ,+0.14∗ Plu tove l o c i t y ∗math . s i n ( Angle (590 .64 , PlutoMass , P lu t ove l o c i t y ) ) , ’ ro ’ ) ;
SolarSystem . append (Sun ) ;SolarSystem . append (Mercury )SolarSystem . append (Venus ) ;SolarSystem . append ( Earth ) ;SolarSystem . append (Mars )SolarSystem . append ( Jup i t e r ) ;SolarSystem . append ( Saturn ) ;SolarSystem . append (Uranus ) ;SolarSystem . append (Neptune )SolarSystem . append ( Pluto ) ;
t = 0dt = 2
# Disp l ay t h e i n i n t i a l sys tem .p l o tPo s i t i o n s ( SolarSystem , 0 ) ;Pr intSolarSystem ( SolarSystem ) ;
bClearScreen = Truezoom = 1.0pygame . d i sp l ay . s e t c ap t i on ( ’ Gravity s imula t i on (SPACE: show orb i t s , ’
’ keypad +/− : zoom in /out ) ’ )while True :
t += dtpygame . d i sp l ay . f l i p ( )i f bClearScreen : # Show o r b i t s or not ?
s c r een . f i l l ( ( 0 , 0 , 0 ) )s c r een . l ock ( )for p1 in SolarSystem :
i f p1 i s Sun :pygame . draw . c i r c l e ( screen , (255 , 255 , 0) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (6 . 5∗ zoom) , 0)#in t ( So larSys tem [ i ] . r a d i u s ∗zoom ) , 0)
i f p1 i s Mercury :pygame . draw . c i r c l e ( screen , (222 ,184 ,135) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0)
i f p1 i s Venus :pygame . draw . c i r c l e ( screen , ( 215 , 212 , 207) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0)
i f p1 i s Earth :pygame . draw . c i r c l e ( screen , (165 , 190 , 231) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0)
i f p1 i s Mars :pygame . draw . c i r c l e ( screen , (232 , 193 , 135) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0)
i f p1 i s Mars :pygame . draw . c i r c l e ( screen , (232 , 193 , 135) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0)
i f p1 i s Mars :pygame . draw . c i r c l e ( screen , (232 , 193 , 135) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0)
i f p1 i s Mars :pygame . draw . c i r c l e ( screen , (232 , 193 , 135) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0)
i f p1 i s Jup i t e r :pygame . draw . c i r c l e ( screen , (180 , 164 , 156) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0)
i f p1 i s Saturn :pygame . draw . c i r c l e ( screen , (193 , 184 , 83) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0)
i f p1 i s Uranus :pygame . draw . c i r c l e ( screen , (166 , 193 , 213) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0)
43
i f p1 i s Neptune :pygame . draw . c i r c l e ( screen , (144 , 174 , 224) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0)
i f p1 i s Pluto :pygame . draw . c i r c l e ( screen , (255 , 255 , 255) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( p1 . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( p1 . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0)
s c r een . unlock ( )ScanKeyboard ( )
updatePos i t i ons (G, SolarSystem , dt ) ;
# update zoom f a c t o r ( numeric keypad +/− key s )i f keysPressed [ pygame .K KP PLUS ] :
zoom /= 0.99i f keysPressed [ pygame .K KP MINUS ] :
zoom /= 1.01i f keysPressed [ pygame .K ESCAPE ] :
breaki f keysPressed [ pygame .K SPACE ] :
while keysPressed [ pygame .K SPACE ] :ScanKeyboard ( )
bClearScreen = not bClearScreenverb = ”show” i f bClearScreen else ” hide ”pygame . d i sp l ay . s e t c ap t i on (
’ Gravity s imu la t ion (SPACE: ’’%s o rb i t s , keypad +/− : zoom in /out ) ’ % verb )
i f name == ” main ” :try :
import psycopsyco . p r o f i l e ( )
except :print ’ Psyco not found , i gno r ing i t ’
main ( )
Listing 2. The Gravitational simulation of Earth’s moon and Earth’s ringsimport matp lo t l ib . pyplot as p l timport mathimport osimport pygameimport randomfrom c o l l e c t i o n s import d e f a u l t d i c timport s o l a rCo l o rPa l e t t eimport numpy as npfrom random import randintimport xlwt
”””John C h r i s p e l l and Arwa Ashi
Code f o r a Earth ’ s r i n g prob lem us ing pyGame and conve r t .Using a f o u r t h order Runge−Kutta method .
”””
book = xlwt .Workbook( encoding=”utf−8” )
sheet1 = book . add sheet ( ”Data” )sheet2 = book . add sheet ( ”x , y and mass ” )#she e t 3 = book . a d d s h e e t (” p l a n e t c o l l i d e ”)#sh e e t 4 = book . a d d s h e e t (” Earth math ”)
sheet1 . wr i t e (0 , 0 , ”Data” )sheet2 . wr i t e (0 , 0 , ”Data” )#she e t 3 . w r i t e (0 , 0 , ” P l ane t s c o l l i d e ”)#sh e e t 4 . w r i t e (0 , 0 , ”New Earth mass ”)
pygame . i n i t ( )
# Def ine t h e Universe we g e t to p l a y w i th c u r r e n t l y and empty g l o b a l l i s t .#G = 6.674∗10∗∗(−11) # mˆ3 /( kg s ˆ2)#global PlanetsMadePlanetsMade = 0
# Def ine a s t a t e c l a s s t h a t h o l d s t h e p l a n e t s p o s i t i o n and v e l o c i t y .class PlanetState :
def i n i t ( s e l f , x , y , vx , vy ) :s e l f . x = x # Current p o s i t o n .s e l f . y = ys e l f . vx = vx # Current v e l o c i t ys e l f . vy = vy
def dumpValues ( s e l f ) :print ”Dump Planet State : ”print ” x = ” , s e l f . xprint ” y = ” , s e l f . y
44
print ” vx = ” , s e l f . vxprint ” vy = ” , s e l f . vy
class Der iva t i v eS ta t e :def i n i t ( s e l f , vx , vy , ax , ay ) :
s e l f . vx , s e l f . vy , s e l f . ax , s e l f . ay = vx , vy , ax , ay ;def dumpValues ( s e l f ) :
print ”Dump Der iva t ive Values : ”print ” vx = ” , s e l f . vx , ” vy = ” , s e l f . vy , ” ax = ” , s e l f . ax , ” ay = ” , s e l f . ay
# Def ine t h e c l a s s s t r u c t u r e f o r our p l a n e t sclass Planet :
def i n i t ( s e l f , mass , x , y , vx , vy , Look , rho = 0 . 00334 ) :global PlanetsMades e l f . index = PlanetsMade ;PlanetsMade += 1 ;#pr i n t ’ h i i am the t o t a l number ’ , PlanetsMades e l f . Mass = mass # ( kg )#sh e e t 2 . w r i t e ( PlanetsMade , 4 , s e l f . Mass )s e l f . State = PlanetState (x , y , vx , vy )s e l f . c o l o r = (255 , 255 , 255) #d e f a u l t t o wh i t es e l f . Look = str ( Look ) # The l o o k o f t h e o b j e c t .
# Set t h e r ad i u s o f t h e p l a n e t u s ing i t s mass and a d e n s i t y .# kg /(kmˆ3) (3 . 34 e12 −−> Dens i t y o f Earth ’ s Moon)# kg /(kmˆ3) (5 . 51 e12 −−> Dens i t y o f Earth )# kg /(kmˆ3) (3 . 93 e12 −−> Dens i t y o f Mars )# kg /(kmˆ3) (5 . 24 e12 −−> Dens i t y o f Venus )
s e l f . rho = rhos e l f . r ad ius = 1 .0#((3 . 0∗ s e l f . Mass ) / ( 4 . 0∗ s e l f . rho∗math . p i ) )∗∗ ( 1 . 0 / 3 . 0 ) #s e l f . setRadiusFromMass ( )#she e t 1 . w r i t e ( PlanetsMade , 4 , s e l f . r a d i u s )s e l f . merged = False#pr i n t ” r ad i u s ” , s e l f . r a d i u s
def getColor ( s e l f ) :return s e l f . c o l o r
def s e tCo lo r ( s e l f , inputColor ) :s e l f . c o l o r = inputColorreturn True
def dumpValues ( s e l f ) :print ” Mass = ” , s e l f . Massprint ” Density = ” , s e l f . rhoprint ” Radius = ” , s e l f . r ad iuss e l f . State . dumpValues ( )print ” look = ” , s e l f . Look
def Acce l e r a t i on ( s e l f , G, SolarSystem , s t a t e ) :# Compute t h e a c c e l e r a t i o n o f o t h e r p l a n e t s on cu r r en t p l a n e t .ax = 0 . 0 ;ay = 0 . 0 ;for p in SolarSystem :
i f p i s s e l f or p . merged :continue
# Loop over t h e o t h e r l o c a l p l a n e t s .# Get t h e d i s t a n c e between s e l f and o t h e r p l a n e t s .dx = p . State . x − s t a t e . xdy = p . State . y − s t a t e . yr s = (dx∗dx + dy∗dy )r = (dx∗dx + dy∗dy )∗∗0 .5f o r c e = G∗p . Mass∗ s e l f . Mass/ r s i f rs>1e−10 else 0 .ax += fo r c e ∗(dx/ r )ay += fo r c e ∗(dy/ r )
return ( ax , ay )
def RKStep1SystemPrime ( s e l f , G, SolarSystem , s t a t e ) :ax , ay = s e l f . Acce l e r a t i on (G, SolarSystem , s e l f . State )return Der iva t i v eS ta t e ( s t a t e . vx , s t a t e . vy , ax , ay )
def RKStep2t4SystemPrime ( s e l f , G, SolarSystem , s tate , d e r i va t i v eS ta t e , dt ) :newState = PlanetState ( 0 . 0 , 0 . 0 , 0 . 0 , 0 . 0 )newState . x = s t a t e . x + de r i v a t i v eS t a t e . vx∗dtnewState . y = s t a t e . y + de r i v a t i v eS t a t e . vy∗dtnewState . vx = s t a t e . vx + de r i v a t i v eS t a t e . ax∗dtnewState . vy = s t a t e . vy + de r i v a t i v eS t a t e . ay∗dtax , ay = s e l f . Acce l e r a t i on ( G, SolarSystem , newState )return Der iva t i v eS ta t e ( newState . vx , newState . vy , ax , ay )
def updatePositionRK4 ( s e l f , G, SolarSystem , dt ) :k1 = s e l f . RKStep1SystemPrime (G, SolarSystem , s e l f . State )k2 = s e l f . RKStep2t4SystemPrime (G, SolarSystem , s e l f . State , k1 , dt ∗0 .5 )k3 = s e l f . RKStep2t4SystemPrime (G, SolarSystem , s e l f . State , k2 , dt ∗0 .5 )k4 = s e l f . RKStep2t4SystemPrime (G, SolarSystem , s e l f . State , k3 , dt )# Use the RK va l u e s .dxdt = ( 1 . 0 / 6 . 0 )∗ ( k1 . vx + 2 .0∗ ( k2 . vx + k3 . vx ) + k4 . vx )dydt = ( 1 . 0 / 6 . 0 )∗ ( k1 . vy + 2 .0∗ ( k2 . vy + k3 . vy ) + k4 . vy )dvxdt = ( 1 . 0 / 6 . 0 )∗ ( k1 . ax + 2 .0∗ ( k2 . ax + k3 . ax ) + k4 . ax )
45
dvydt = ( 1 . 0 / 6 . 0 )∗ ( k1 . ay + 2 .0∗ ( k2 . ay + k3 . ay ) + k4 . ay )# Update t h e p o s i t on .s e l f . State . x += dxdt∗dts e l f . State . y += dydt∗dts e l f . State . vx += dvxdt∗dts e l f . State . vy += dvydt∗dt
# Set up the radu iu s o f each f ragment sdef setRadiusFromMass ( s e l f ) :
””” Rever s ing t h e setMassFromRadius formula , t o c a l c u l a t e r ad i u s frommass ( used a f t e r merging o f two p l a n e t s − mass i s added , and newrad i u s i s c a l c u l a t e d from t h i s ) ”””s e l f . r ad ius = abs ( ( 3 .∗ s e l f . Mass /( s e l f . rho ∗4.∗math . p i ) )∗∗ ( 0 . 3 333 ) )
def updatePos i t i ons (G, SolarSystem , dt ) :#pr i n t ”Update Po s i t i o n ”for i in range ( len ( SolarSystem ) ) :
# Loop through th e p l a n e t s and move t h e i r p o s i t i o n s .i f ( i > 0 ) :
cur rentPlanet = SolarSystem [ i ]cur rentPlanet . updatePositionRK4 (G, SolarSystem , dt )
def d i s tance ( Planet1 , Planet2 ) :# Returns d i s t a n c e between two p l a n e t o b j e c t s .d i s t = ( ( Planet1 . State . x − Planet2 . State . x )∗∗2 .0 +
( Planet1 . State . y − Planet2 . State . y )∗∗ 2 . 0 )∗∗ ( 0 . 5 ) ;return d i s t
def p l o tPo s i t i o n s ( SolarSystem , frame ) :p l t . f i g u r e ( )p l t . ax i s ( [−4 ,4 ,−4 ,4 ] ) ;for i in range ( len ( SolarSystem ) ) :
s c r een=pygame . d i sp l ay . set mode ( (WIDTH, HEIGHT))x = int ( SolarSystem [ i ] . State . x )y = int ( SolarSystem [ i ] . State . y )s c r een . s e t a t ( ( x , y ) , ( 215 , 212 , 207))
FileName = ”System” + str ( frame ) . z f i l l ( 4 ) + ” . png” ;p l t . s a v e f i g ( FileName )p l t . c l o s e ( )
def planetsTouch (p1 , p2 ) :dx = p1 . State . x − p2 . State . xdy = p1 . State . y − p2 . State . ydsq = dx∗dx + dy∗dydr = math . sq r t ( dsq )return dr<=(p1 . rad ius + p2 . rad ius )
def i n c r ea s e Index ( SolarSystem ) :for i in range ( len ( SolarSystem ) ) :
SolarSystem [ i ] . updateIndex ( ) ;
def PrintSolarSystem ( SolarSystem ) :for i in range ( len ( SolarSystem ) ) :
print ”Planet Index = ” , i ;SolarSystem [ i ] . dumpValues ( ) ;
# s e t up th e momentum ang l e and momentum v e l o c i t y .def Angle ( raduise , mass , speed ) :
ang le = radu i s e ∗ mass ∗ speedi f angle > 360 :
ang le −= 360angleRad = angle ∗ 0.0174532925return angleRad
def momentum( raduise , mass , v e l o c i t y ) :ang le = Angle ( raduise , mass , v e l o c i t y )Xve loc i ty = v e l o c i t y ∗mass∗math . cos ( ang le )Yve loc i ty = v e l o c i t y ∗mass∗math . s i n ( angle )i f angle > 360 :
ang le −= 360angleRad = angle ∗ 0.0174532925Xve loc i ty = v e l o c i t y ∗mass∗math . cos ( angleRad )Yve loc i ty = v e l o c i t y ∗mass∗math . s i n ( angleRad )return Xveloc ity , Yve loc i ty
def g rav i ty ( e ) : # Time in secondG1 = 6.674∗10∗∗(−20.) # kmˆ3/ ( kg s ˆ2)G2 = G1∗(1/ e )∗∗3 .0 # ( p i x e l / km )ˆ3G = G2∗ (10∗∗24 . ) # kg / Screen kgreturn G
# The window s i z eWIDTH, HEIGHT = 800 ,800WIDTHD2, HEIGHTD2 = WIDTH/2 . , HEIGHT/2 .
def main ( ) :pygame . i n i t ( )s c r een=pygame . d i sp l ay . set mode ( (WIDTH, HEIGHT))
keysPressed = d e f a u l t d i c t (bool )
def ScanKeyboard ( ) :
46
while True :# Update t h e k ey sPre s s ed s t a t e :evt = pygame . event . p o l l ( )i f evt . type == pygame .NOEVENT:
breake l i f evt . type in [ pygame .KEYDOWN, pygame .KEYUP] :
keysPressed [ evt . key ] = evt . type == pygame .KEYDOWN# Moon ’ s Di s tance from Earth = 378 ,000 km# Rocho l i m i t = d = 18994.6 km \ approx 189.946 P i x e lG = grav i ty (10∗∗2 . )print ’ im the g rav i ty ’ ,G #0.000067 #in h 864 .95 #in sec i s 0 .000067SolarSystem = [ ]EarthMass = 5.97MoonMass = 0.07342#Ea r t h v e l o c i t y = i s 0 .0 a c t u l l y 0 .257472Moonvelocity = 0.001022 #in h 3.6792 #in sec i s 0 .001022 #(0.964 ∗ 84600 ∗ 10ˆ(−7))
# Fragmentatnion Parameters f o r MoonFragmentMoon = True # Se t t i n g to Fa l s e g i v e s two body system .
# randomly a d j u s t i n g o f x and y p o s i t i o nMinAdjustx , MinAdjusty = −2000.0 , −2000.0MaxAdjustx , MaxAdjusty = 2000 .0 , 2000.0
# randomly a d j u s t i n g o f v e l o c i t yMinAdjustv = 1000.0MaxAdjustv = 2000.0
# ad j u s t t h e r adu i s o f t h e moon and i t s f ragment sMoonRaduisx = 400.0 # moon s t a r t i n g x−p o s i t i o n# rohco l i m i t 400.0−189.946# moon l i m i t 3780 .0 − 400 .0MoonRaduisy = 400.0−189.946 # # moon s t a r t i n g y−p o s i t i o n
# add j u s t t h e l i m i t o f s p l i t i n gl im i t = 1/300. # Max s i z e o f f i n a l f ragmented f r a c t i o n o f o r i g i n a l moon .sp l i t In tMin = 8 # Si z e o f f r a gmen ta t i on (1/100 , 1/4) o f o r i g i n a l o b j e c t .sp l i t IntMax = 80 #
#================================================================# Do not put f i x e d v a l u e s be low t h i s l i n e !################################################################## a Loop f o r Earth moon system and moon ’ s f ragment s .#################################################################Earth = Planet ( EarthMass , 400 .0 , 400 .0 , 0 .0 , 0 . 0 , ’ ro ’ ) ;SolarSystem . append ( Earth ) ;#add moon .print ”adding moon”Xveloc ity , Yve loc i ty = momentum(378 . ,MoonMass , Moonvelocity )# i f t h e moon ’ s d i s t a n c e from Earth i s 18 .0 w i th G = g r a v i t y (10∗∗3 . )# make the v e l i c i t y \ t imes 3 .0 to g e t a s t a b l e o r b i t e# i f t h e moon ’ s d i s t a n c e from Earth i s 3780 − 400 wi th G = g r a v i t y (10∗∗2 . )# make the v e l i c i t y \ t imes 25 .0 to g e t a s t a b l e o r b i t emoon1 = Planet (MoonMass , MoonRaduisx , MoonRaduisy , 25 .0∗ Xveloc ity , 25 .0∗ Yveloc ity , ’ ro ’ ) ;print ’ Hi i am the o r i g i n a l mass ’ ,MoonMassSolarSystem . append (moon1 ) ;i = 1 # Here ’ i ’ r e p r e s e n t s t h e number o f b o d i e s o r b i t i n g t h e ”Earth ” in our system .
i f (FragmentMoon == True ) :
while ( SolarSystem [ i ] . Mass > l im i t ∗MoonMass ) :# Get l a s t p l a n e t added to sys tem !Plan i tToSp l i t = SolarSystem [ i ]
#Find a f r a c t i o n o f mass to s p l i t o f f .s p l i t F r a c t i o n = 1 .0/ ( randint ( sp l i t IntMin , sp l i t IntMax ) )massSpl i t = Plan i tToSp l i t . Mass∗ s p l i t F r a c t i o n #( a lways t h e minimum)
# Adjus t t h e mass in t h e p l a n e t l i s t .BalanceMomentumMass = Plan i tToSp l i t . Mass − massSpl i tSolarSystem [ i ] . Mass = massSpl i t# Adjus t t h e mass o f new p l a n e t .oldRadius = SolarSystem [ i ] . r ad iusSolarSystem [ i ] . setRadiusFromMass ( )
# Find a Random v e l o c i t y f o r t h e sma l l e r mass f ragment ( l a s t p l a n e t added )w = ( randint (MinAdjustv , MaxAdjustv ))∗10∗∗(−5.0)SolarSystem [ i ] . State . vx = Moonvelocity∗wSolarSystem [ i ] . State . vy = Moonvelocity∗w
# Find fragment v e c o l t i y by momentum ba l ance .Xvelo = ( ( P lan i tToSp l i t . Mass ∗ Plan i tToSp l i t . State . vx ) −
( SolarSystem [ i ] . Mass ∗ SolarSystem [ i ] . State . vx ) ) / BalanceMomentumMassYvelo = ( ( P lan i tToSp l i t . Mass ∗ Plan i tToSp l i t . State . vy ) −
( SolarSystem [ i ] . Mass ∗ SolarSystem [ i ] . State . vy ) ) / BalanceMomentumMass
# add a random e p s i l o n to t h e p o s i t i o n wi th in 2 r ad i u s o f o r i g i n a l s i z e .adjustx = ( randint (MinAdjustx , MaxAdjustx ) ) / 1 0 00 . 0 ;adjusty = ( randint (MinAdjusty , MaxAdjusty ) ) / 1 0 00 . 0 ;
47
#append the fragment to t h e s o l a r sys temmoon2 = Planet (BalanceMomentumMass , SolarSystem [ i ] . State . x + oldRadius∗adjustx ,
SolarSystem [ i ] . State . y +oldRadius∗adjusty , Xvelo , Yvelo , ’ ro ’ )SolarSystem . append (moon2)
i = i +1;
#===============================================================# Plane t s a l l added i n t o our system l i s t !#===============================================================
# S t a r t i n g a t t ime = 0 and d t i s t h e t ime s t e p st = 0dt = 800
# Disp l ay t h e i n i n t i a l sys tem .p l o tPo s i t i o n s ( SolarSystem , 0 ) ;Pr intSolarSystem ( SolarSystem ) ;
bClearScreen = Truezoom = 1.0pygame . d i sp l ay . s e t c ap t i on ( ’ Gravity s imula t i on (SPACE: show orb i t s , ’
’ keypad +/− : zoom in /out ) ’ )
StoppingTime = 800∗dt
#wh i l e t < StoppingTime :while True :
t += dtpygame . d i sp l ay . f l i p ( )i f bClearScreen : # Show o r b i t s or not ?
s c r een . f i l l ( ( 0 , 0 , 0 ) )s c r een . l ock ( )for i in range ( len ( SolarSystem ) ) :
#i f not So larSys tem [ i ] . merged :#sh e e t 1 . w r i t e ( i , ( t /90000) , So larSys tem [ i ] . S t a t e . x )#sh e e t 1 . w r i t e ( i , ( t /90000)+1 , So larSys tem [ i ] . S t a t e . y )#sh e e t 1 . w r i t e ( i , ( t /90000)+2 , So larSys tem [ i ] . Mass )pygame . draw . c i r c l e ( screen , ((225− i )%225 , 255 , (255− i )%255) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( SolarSystem [ i ] . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( SolarSystem [ i ] . State . y−HEIGHTD2)/HEIGHTD2) ) ,int (4 . 5∗ zoom) , 0)#in t ( p1 . r ad i u s ∗zoom ) , 0 ) ;
#i f i == 0 :pygame . draw . c i r c l e ( screen , (165 , 190 , 231) ,
( int (WIDTHD2+zoom∗WIDTHD2∗( SolarSystem [ i ] . State . x−WIDTHD2)/WIDTHD2) ,int (HEIGHTD2+zoom∗HEIGHTD2∗( SolarSystem [ i ] . State . y−HEIGHTD2)/HEIGHTD2) ) ,int ( SolarSystem [ i ] . r ad iu s ∗zoom) , 0)#in t (4 . 5∗ zoom ) , 0)#;
s c r een . unlock ( )ScanKeyboard ( )
updatePos i t i ons (G, SolarSystem , dt ) ;
# merge t h e fragment t h a t are c l o s e enough to touch ,# us ing e l a s t i c c o l l i s i o n s ( c on s e r v a t i on o f t o t a l momentum)for i in range ( len ( SolarSystem ) ) :
i f SolarSystem [ i ] . merged :continue
for j in range ( len ( SolarSystem ) ) :i f SolarSystem [ i ] i s SolarSystem [ j ] or SolarSystem [ j ] . merged :
continuei f planetsTouch ( SolarSystem [ i ] , SolarSystem [ j ] ) :
i f SolarSystem [ j ] i s Earth :SolarSystem [ i ] . merged = TrueEarth . Mass = Earth . Mass + SolarSystem [ i ] . Mass#Earth . S t a t e . vx , Earth . S t a t e . vy= 0 . 0 , 0 . 0#p r i n t ’New Earth Mass ’ , Earth . Mass#sh e e t 1 . w r i t e ( i , 5 , Earth . Mass )break
i f SolarSystem [ i ] . Mass < SolarSystem [ j ] . Mass :
i f SolarSystem [ i ] . State . vx < SolarSystem [ j ] . State . vx :SolarSystem [ i ] , SolarSystem [ j ] = SolarSystem [ j ] , SolarSystem [ i ]# p1 i s t h e b i g g e s t one (mass−wise )SolarSystem [ j ] . merged = Truenewvx = ( SolarSystem [ i ] . State . vx∗SolarSystem [ i ] . Mass+
SolarSystem [ j ] . State . vx∗SolarSystem [ j ] . Mass )/ ( SolarSystem [ i ] . Mass+SolarSystem [ j ] . Mass )
newvy = ( SolarSystem [ i ] . State . vy∗SolarSystem [ i ] . Mass+SolarSystem [ j ] . State . vy∗SolarSystem [ j ] . Mass )/ ( SolarSystem [ i ] . Mass+SolarSystem [ j ] . Mass )
SolarSystem [ i ] . Mass += SolarSystem [ j ] . Mass# mainta in t h e mass ( j u s t add them )SolarSystem [ i ] . setRadiusFromMass ( ) # new mass −−> new rad i u sSolarSystem [ i ] . State . vx , SolarSystem [ i ] . State . vy = newvx , newvy
#pr i n t ” p l a n e t j o i n %d” %i , So larSys tem [ i ] . Mass#sh e e t 1 . w r i t e ( j , 4 , So larSys tem [ i ] . Mass )
i f SolarSystem [ i ] . State . vx > SolarSystem [ j ] . State . vx :w=1while ( SolarSystem [w ] . Mass > SolarSystem [ j ] . Mass ) :
# Get l a s t p l a n e t added to sys tem !
48
Plan i tToSp l i t = SolarSystem [w]
#Find a f r a c t i o n o f mass to s p l i t o f f .s p l i t F r a c t i o n = 1 .0/ ( randint ( sp l i t IntMin , sp l i t IntMax ) )massSpl i t = Plan i tToSp l i t . Mass∗ s p l i t F r a c t i o n #( a lways t h e minimum)
# Adjus t t h e mass in t h e p l a n e t l i s t .BalanceMomentumMass = Plan i tToSp l i t . Mass − massSpl i tSolarSystem [w ] . Mass = massSpl i t
# Adjus t t h e mass o f new p l a n e t .oldRadius = SolarSystem [w ] . rad iusSolarSystem [w ] . setRadiusFromMass ( )
# Find a Random v e l o c i t y f o r t h e sma l l e r mass f ragment ( l a s t p l a n e t added )m = ( randint (MinAdjustv , MaxAdjustv ))∗10∗∗(−5.0)SolarSystem [w ] . State . vx = Moonvelocity∗mSolarSystem [w ] . State . vy = Moonvelocity∗m
# Find fragment v e c o l t i y by momentum ba l ance .Xvelo = ( ( P lan i tToSp l i t . Mass ∗ Plan i tToSp l i t . State . vx ) −
( SolarSystem [w ] . Mass ∗ SolarSystem [w ] . State . vx ) ) / BalanceMomentumMassYvelo = ( ( P lan i tToSp l i t . Mass ∗ Plan i tToSp l i t . State . vy ) −
( SolarSystem [w ] . Mass ∗ SolarSystem [w ] . State . vy ) ) / BalanceMomentumMass
# add a random e p s i l o n to t h e p o s i t i o n wi th in 2 r ad i u s o f o r i g i n a l s i z e .adjustx = ( randint (MinAdjustx , MaxAdjustx ) ) / 1 0 00 . 0 ;adjusty = ( randint (MinAdjusty , MaxAdjusty ) ) / 1 0 00 . 0 ;
#append the fragment to t h e s o l a r sys temmoon2 = Planet (BalanceMomentumMass ,SolarSystem [w ] . State . x + oldRadius∗adjustx ,SolarSystem [w ] . State . y +oldRadius∗adjusty , Xvelo , Yvelo , ’ ro ’ )SolarSystem . append (moon2)
w = w+1#pr i n t ’ p l a n e t c o l l i d ’ ,w#she e t 1 . w r i t e ( i , 6 , ’ p l a n e t c o l l i d ’ )
book . save ( ” python spreadsheet2 . x l s ” )# update zoom f a c t o r ( numeric keypad +/− key s )i f keysPressed [ pygame .K KP PLUS ] :
zoom /= 0.99i f keysPressed [ pygame .K KP MINUS ] :
zoom /= 1.01i f keysPressed [ pygame .K ESCAPE ] :
breaki f keysPressed [ pygame .K SPACE ] :
while keysPressed [ pygame .K SPACE ] :ScanKeyboard ( )
bClearScreen = not bClearScreenverb = ”show” i f bClearScreen else ” hide ”pygame . d i sp l ay . s e t c ap t i on (
’ Gravity s imu la t ion (SPACE: ’’%s o rb i t s , keypad +/− : zoom in /out ) ’ % verb )
i f name == ” main ” :try :
import psycopsyco . p r o f i l e ( )
except :print ’ Psyco not found , i gno r ing i t ’
main ( )
49