home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 10
/
aminetcdnumber101996.iso
/
Aminet
/
misc
/
sci
/
StarCollapse.lha
/
analysis
next >
Wrap
Text File
|
1995-08-07
|
7KB
|
243 lines
ANIMATED 3-D GRAVITY SIMULATOR
------------------------------
(c) August 1995 Laurence Vanhelsuwé
1. REQUIREMENTS
2. ANALYSIS
3. DESIGN
3.1 DATA STRUCTURES
3.2 LOGIC FLOW
3.2.1 Calculation of Cloud mass and center of gravity
3.2.2 Calculation of gravitational pull on individual mass
3.2.3 Calculation of force x,y,z components
3.2.4 Calculation of 3-D mass movement from acting force
3.2.4.1 Calculation of the velocity V from the force F
3.2.4.2 Calculation of the velocity vector Vx,Vy,Vz
3.2.4.3 Calculation of the new velocity
3.2.4.4 Calculation of the new position
1. REQUIREMENTS
------------
We wish to animate the gravitational interaction of a LARGE ( >100 ) number
of masses in 3 dimensions.
The idea for this program comes from a desire to animate a galaxy (!) which,
by definition, contains a huge number of point-like masses.
Therefore, 2 main requirements exist:
1) physical accuracy
2) very high performance
The 3-D viewing aspects will not be discussed further as this will be handled
by an already existing sub-system. This viewer will project and allow the
rotation and scaling of any database of (x,y,z) triplets, in real-time.
2. ANALYSIS
--------
Since this program is simple, no object-oriented analysis or design will be
undertaken.
The main structure of the program is a straight-forward infinte loop:
1) calculate new positions of masses
2) refresh display using new positions
The data structures of the program are equally trivial.
The main structure will be the collection of masses.
Masses themselves will be structures holding their physical properties being
modelled (3-D coordinates, mass, velocity).
3. DESIGN
------
3.1 DATA STRUCTURES
---------------
The Mass objects are structured as follows:
Mass is {
numeric mass;
numeric x,y,z;
numeric vx,vy,vz;
}
The modelled "cloud" of Masses is simply an array of Mass objects plus a
counter telling us howmany array elements there are:
Cloud Mass[MAX_POINTS];
numeric NumMasses;
3.2 LOGIC FLOW
----------
Each simulation iteration consists of the following steps:
- calculate mass (M) and center of mass (Mx,My,Mz) for the modelled cloud.
- foreach individual mass:
- calculate magnitude of gravitational pull by cloud (F) and associated
orthogonal force components (Fx,Fy,Fz)
- calculate 3-D mass movement from acting force
- move mass
- output a database of (x,y,z) triplets for viewer pipeline
Each step of this outline will now be designed in more detail.
3.2.1 Calculation of Cloud mass and center of gravity
-----------------------------------------------
The cloud mass is simply the sum of all its component masses.
The cloud center of gravity (Mx,My,Mz) can be calculated as follows:
m1.x1 + m2.x2 + ... mn.xn
(1) Mx = -------------------------
m1+m2+...+mn
m1.y1 + m2.y2 + ... mn.yn
(2) My = -------------------------
m1+m2+...+mn
m1.z1 + m2.z2 + ... mn.zn
(3) Mz = -------------------------
m1+m2+...+mn
3.2.2 Calculation of gravitational pull on individual mass
----------------------------------------------------
The formula for the Law of Gravity is as follows:
m1.m2
(4) F = G . -------
2
R
Where:
F is the magnitude of the gravitational force
G is the gravity constant (6.33 x 10-11)
m1 is mass 1
m2 is mass 2
R is the distance between m1 and m2
Observation: since this simulation is explicitly designed for LARGE sets of
masses, the effect of any single mass on the placement and magnitude of the
cloud's center will be negligable.
Therefore we can simplify calculations to calculate the force of attraction
between any individual mass and the cloud's center of gravity by considering
those two points instead of having to adjust the center of gravity due to the
inclusion of the mass under consideration.
The algorithm simply becomes the application of formula (4), with
m1 = the mass of the current body
m2 = the mass of the cloud (minus the current body's mass to improve the
accuracy cheaply)
2
R = (Mx-mx)^2 + (My-my)^2 + (Mz-mz)^2
3.2.3 Calculation of force x,y,z components
-------------------------------------
The magnitude of the force F has to be available as a vector Fx,Fy,Fz too.
This is so that later we can calculate the associated velocity components
Vx,Vy,Vz.
The force vector can be calculated as follows:
dx
(5) Fx = F * ----
R
dy
(6) Fy = F * ----
R
dz
(7) Fz = F * ----
R
3.2.4 Calculation of 3-D mass movement from acting force
--------------------------------------------------
This sub-problem can be sub-divided further:
- calculate the velocity V generated by the attraction force F
- calculate the velocity vector (Vx,Vy,Vz) from V
- calculate the new velocity of the body
- calculate the new position of the body by adding velocity to current position
3.2.4.1 Calculation of the velocity V from the force F
----------------------------------------------
The formula for the Law of Impulse is as follows:
(8) F.dt = m.dV
Since we use time increments of one ('1') we can write that:
F
(9) V = ---
m
3.2.4.2 Calculation of the velocity vector Vx,Vy,Vz
-------------------------------------------
In a similar vein to the calculation of the force vector in (5),(6) and (7)
we can write:
Fx
(10) Vx = V * ----
F
Fy
(11) Vy = V * ----
F
Fz
(12) Vz = V * ----
F
3.2.4.3 Calculation of the new velocity
-------------------------------
The current object's new velocity is obtained by adding the new velocity vector
to the current velocity:
(13) Vx = Vx + Vx
new old
(14),(15) analogous to (13).
3.2.4.4 Calculation of the new position
-------------------------------
The object's new position is obtained by adding the new current velocity to
its current position.
(16) x = x + Vx
new old
(17),(18) analogous to (16).