of time since a particle has been created. In the simulation, the maximum life of each particle is randomized upon initialization and the current life begins at this value. In each iteration of
the simulation loop, the timestep is subtracted from the life value, multiplied by somedecay
rate. Thus the life value is actually an indicator of the timeremainingbefore the particle is
destroyed. Thedecay rateis also randomized upon initialization, and as such certain particles
will lose life faster than others. When the particle’s life count reaches zero or below, it is destroyed and no further calculations can be performed on it until the following loop iteration where it will be recreated with new random values.
Because of the simplicity of the non-interacting particle models, they are fairly easy to im- plement and run extremely fast. An implementation of this particle model will be demonstrated in Chapter 6. However, these types of particle models suffer in trying to simulate highly com- plex behaviour, and often have to resort to high usage of randomization to give the appearance of chaotic motion. Other, more physics-oriented approaches are more suited to these types of problems.
4.2
Spring-Mass Model
Spring-mass models are most often used in modelling cloth-related simulations [108] [32] [7], but these models are suited to many other applications as well, including surface modelling [124] and crowd simulation [111].
As mentioned previously, for particle systems where soft-body dynamics are observed a spring-mass model is applicable. The interactions between particles can change depending on the types of springs used, as well as the distances they are compressed or extended.
In a spring-mass particle model particles are modeled as points connected by conceptual springs, which are weightless and serve simply as a vector between any two particles along
which anelastic force is calculated. Springs obey the laws of physics according toHooke’s
Law[113], which states that the force required to compress or extend a spring is dependent on
the compression or extension distance, and thestiffnessof the spring itself. The most general
form of the law is shown in Equation 4.1.
F =−ksX (4.1)
Here the forceFis directly proportional to the compression or extension distanceX, multi-
plied by the spring stiffness constantks. Additionally, the reaction force of the spring should be
equal to the applied force, following Newton’s third law, soF is therefore directly proportional
to the compression or extension distance in magnitude, but acting in the opposite direction
−X. For example while being compressed together, at any instance of time there should be
an equal and opposite force extending the spring. Figure 4.2 shows this general idea. Notice that in this example, the spring mass system is in relation to a cloth simulation rather than a
Figure 4.2: An example of spring-mass particle motion. Depending on the compression or ex- tension distance of the springs connecting pairs of particles, a force is exerted on each particle. If the spring is compressed, the pair pushes each other apart, while if the spring is extended, the pair are drawn together.
water simulation. A water simulation-specific approach to the spring-mass model is discussed in Chapter 6.
When applying Hooke’s law to the particle system, the spring rest distancer should be
determined. Particles with a scalar distance equal to the rest distance are situated at the equilib- rium point where the conceptual spring is neither being compressed nor extended. A distance larger than the rest distance implies the spring is being extended, while a distance shorter than the rest distance implies the spring is being compressed. This application is shown in Equation 4.2, where|Xa−Xb|is the scalar distance between the two particlesaandb, whileXabis the relative position of the two particles (the spring vector).
F =−(ks(|Xab| −r) Xab
|Xab| (4.2)
In its simplest form, this equation gives the value of thespring force of the spring-mass
system, but this is just one part of the total force exerted by one particle on another. Particles
experiencefrictionordrag forceswhen moving, depending on the velocity of the particle as
well as adrag constantas shown in Equation 4.3. Friction or drag forces are approximated by
damping.
Fd=−kdv (4.3)
SECTION 4.2: SPRING-MASS MODEL 51
be in an environment without friction if the drag constant is zero.
Particles also experienceshear forces, forces which occur when two parts of a body move
in different directions. Basically, the shear force is the equivalent of a spring force which does not align with the spring vector. Shear forces apply to the tangential component of the relative velocity of the two particles, also having a shear coefficient property of the system determining the magnitude of the shear force. This is shown in Equation 4.4.
Fsh =ksh(V t a−V t b) (4.4)
where V t is the relative tangential velocity between the two particles, and ksh is the shear
constant.
Finally, particles may exert attraction forces on each other. The type of attraction force
depends on the type of system that is intending to be simulated. In ann-bodysimulation [105],
the attraction force of one particle on another refers to the gravitational pull of the particle based on its mass. This gravitational force is shown in Equation 4.5.
Fg =
GmambXab
|Xab|3 (4.5)
wheremaandmb are the masses of the two particles,Xabthe relative position of the two par-
ticles,|Xab|the scalar distance between the two particles andGis thegravitational constant, approximately6.674×10−11N m2kg−2.
The superposition of all these forces make up the total internal force of the spring-mass
particle system. When applying these forces to the particle system, the total forceFT acting on
any particleaby any other particlebis shown by in Equation 4.6.
FT =Fs+Fd+Fsh+Fg (4.6)
Perhaps the most important aspect of the spring-mass force calculation is setting the spring
rest distancer. For a cloth simulation or n-body simulation, the rest distance might be large
in comparison to the size of the particle. However, for soft-body collision dynamics this need not be the case. Setting the rest distance to the sum of the radii of the two particles means the spring becomes compressed only when the two particles touch each other and thus produce a repulsive force keeping particles at least the sum of their radii away from each other (a soft- body collision).
Additionally, spring forces need not always be applied for both extension and compression.
Specifying the spring forceonlyto act when particle distances are less thanr and not greater
Algorithm 3Application of the spring-mass model in parallel
Given array X ofnparticle positions
Given array V ofnparticle velocities
Given particle thread indexi
Local environment cell size 2r //Set up local environment Calculate neighbouring cells C
//Loop through the local environment, calculate the internal force foreach particle P at X[i]do
Calculate local environment based on P for all27 (max) neighbouring cells Cdo
Calculate firstfand lastlordered particles within cell //Avoid case where particle interacts with itself forj=f;j≤l;j++do
ifi=jthen
Perform collision detection for P and particle at X[j] Calculate internal force F, based on X and V
end if end for end for
Add external force E where applicable end for
each other - this is the approach used later in Chapter 6 for simulating a crude fluid simulation using this model.
Algorithm 3 shows the approach used to apply the model in parallel to a particle system. Since each particle only interacts with other particles within its local environment, the algo- rithm assumes the setup of this local environment before the forces are calculated for each particle. This local environment typically consists of a grid of cells surrounding the particle,
with dimensions3×3×3to make 27 cells altogether. Setting up this grid of cells is covered
in more detail in Chapter 5. It is assumed that particles within each cell in the grid are sorted such that they are accessible efficiently in a parallel manner. The size of the local environment cells is typically dependent on the rest distancer.