Liuye Zhao@ZJU:~$Hi there!

Lecture 7: Group Animation (II)

Computer Animation 第 7 讲

I.Group Behavior Simulation Based on Social Force Model

1.1. The question: What happens when order collapses?

The Problem: When Order Collapses

Real human tragedies—stampedes.

  • The 2010 Duisburg “Paramount de la Love” music festival stampede in Germany.

  • The 1989 Hillsborough disaster in the UK.

  • The 1985 Heysel Stadium disaster in Belgium.

In these incidents, hundreds or even thousands of people huddled in confined spaces. As panic spread, individual rationality was quickly overwhelmed by the irrational behavior of the group, leading to irreversible tragedies.

These disasters raise a serious and urgent question:

  • The herd mentality can be deadly. In a state of panic, people’s behavior becomes clumsy, dangerous, and can even harm others.

  • Obtaining accurate data on panic is extremely difficult. We cannot deliberately create a disaster for research purposes.

  • Public safety is of paramount importance. Stadiums, concert halls, subway stations… these high-density gathering places all pose potential risks.

Therefore, establishing a model that can effectively simulate the behavior of crowds, especially panicked crowds, is crucial for public safety early warning, building design assessment, and emergency evacuation plan development.

1.2. Solution: Social Force Model

To address this challenge, German physicist Dirk Helbing and his collaborators published a landmark paper in the journal Nature in 2000: “Simulating dynamical features of escape panic.” They proposed a highly innovative concept: social force model.

Basic Idea: By abstracting the complex and difficult-to-quantify social psychological influences, analogous to calculable forces in the physical world, and integrating them into the classical Newtonian dynamics framework.

Basic Principles:

  1. Abstract people as self-driven particles. Each person has mass, position, and velocity.

  2. Every person’s motion follows Newton’s second law: .

  3. This resultant force is no longer just a physical force; it consists of three parts:

  • Self-driving force generated by subjective consciousness.

  • Interaction forces from other pedestrians.

  • Environmental forces from obstacles (such as walls).

Now, let’s describe this model precisely in mathematical terms.

1.3. Mathematical Details

A pedestrian ‘s motion equation can be written as:

其中:

  • : Mass of pedestrian .
  • : Actual velocity of pedestrian at time .
  • : Position of pedestrian at time .
  • : Acceleration of pedestrian .

The right-hand side of the equation consists of three forces: self-driving force generated by subjective consciousness, interaction forces from other pedestrians, and environmental forces from obstacles (such as walls).

1.3.1 Self-Driving Force

This force represents the subjective motivation of the pedestrian to reach their destination.

Intuition: Each person has an expected walking speed and direction. If my current speed does not match my expected speed, I will “apply force” to adjust, trying to restore to my expected state within a certain time (called “characteristic time” or “reaction time”).

Formula:

  • : Expected speed of pedestrian (a scalar, such as 1.2m/s).
  • : Expected direction of pedestrian (a unit vector).
  • : This is the expected velocity vector of pedestrian .
  • : The current actual velocity vector of pedestrian .
  • : Characteristic time (or reaction time),This represents the time required for pedestrian to adjust to the desired speed, typically around 0.5 seconds.

How to calculate the expected direction? It is simply the unit vector pointing from the current position to the final destination. If the destination point is , and the current position of pedestrian is , then:

This driving force is the “engine” of the entire model, representing the purposefulness of pedestrian movement.

1.3.2 Forces exerted by one individual on another

This is the most complex and ingenious part of the model, containing both psychological repulsion and physical contact.

  • : The sum of the radii of the two pedestrians.
  • : The distance between the center points of the two pedestrians.
  • : The unit normal vector pointing from pedestrian to pedestrian .
  • : The unit tangent vector perpendicular to .

a) Psychological Repulsion Force

This part is pure psychological action, representing the unconscious behavior of maintaining a “social distance” with others in our daily lives.

  • Its direction is outward along the line connecting the centers of the two individuals.
  • Its core is the exponential function . This means that when the two individuals are far apart (), this force is almost zero; but when they rapidly approach each other, this repulsive force increases exponentially, producing a strong “braking” or “avoidance” effect.
  • and are constants, controlling the strength and distance range of the interaction, respectively.

b) Body Force

This part is physical contact.

  • is the key function:
    • When , i.e., the two individuals have not yet touched or are just touching, , the body contact force is zero.
    • When , i.e., the two models overlap (representing body compression), , the body contact force is activated.
  • This force is proportional to the “compression amount” (), simulating the elastic force when the body is compressed. is a very large stiffness constant.

c) Sliding Friction Force

This force also exists only when .

  • It is used to prevent the occurrence of an unrealistic “sliding over” phenomenon between people.
  • is the relative velocity in the tangential direction of the two individuals.
  • When two people are pressed together and have relative tangential motion, a frictional force is generated that resists this sliding. is the coefficient of friction.

1.3.3.Environment Force (Force exerted by obstacles)

The force exerted by obstacles on people can be modeled as a “pedestrian” with an infinite radius. Therefore, its formula is very similar to , just without the exponential term of psychological repulsion (people do not maintain a social distance with walls), mainly composed of physical contact force and friction force.

1.3.4 Surprising Discovery: “Faster-is-slower effect”

  • In a simulation of room evacuation, he let pedestrians escape at different expected speeds .
  • Intuitive belief: The faster the expected speed, the faster the escape.
  • Simulation result: When the expected speed exceeds a critical value, an “arch-shaped” blockage will quickly form at the exit, and the crowd will be like sand in a sandglass, getting stuck. As a result, the total evacuation time actually increases, and the number of injured people also sharply increases.

This result tells us that in emergency evacuation, simply emphasizing “running fast” may be counterproductive. Maintaining order and avoiding过度拥挤 at the exit is key to improving evacuation efficiency.

1.3.5 Herding Effect

In panic, people often blindly follow the crowd, rather than independently thinking about the best path. The social force model simulates this behavior by introducing a “panic parameter” .

The pedestrian’s expected direction of movement is no longer simply pointing towards the exit, but has become a weighted average of the individual goal and the average direction of the neighbors:

  • When , the pedestrian is completely rational and moves only towards their own goal.
  • When , the pedestrian completely loses their individual goal and simply follows the people around them.

Simulation shows that as the panic parameter increases, even if there are multiple exits, the crowd will disproportionately flow to one exit, leaving other exits idle, significantly reducing overall evacuation efficiency.

1.4. Code implementation ideas

Data Structure

#include <vector>

                struct Vector2D { /* ... */ };

                class Pedestrian {
                public:
                    int id;
                    double mass;
                    double radius;
                    Vector2D position;
                    Vector2D velocity;
                    Vector2D desired_direction;
                    double desired_speed;
                    
                    // Social Force Model parameters
                    double tau, A, B, k, kappa;

                    void update(const Vector2D& total_force, double dt) {
                        Vector2D acceleration = total_force / mass;
                        velocity = velocity + acceleration * dt;
                        // Apply speed limit if needed
                        position = position + velocity * dt;
                    }
                };

                class Wall { /* ... defines a line segment ... */ };
                

Main Loop Pseudocode

void simulate_step(double dt) {
                    for (Pedestrian& ped_i : pedestrians) {
                        // 1. Calculate Driving Force
                        Vector2D desired_velocity = ped_i.desired_direction * ped_i.desired_speed;
                        Vector2D driving_force = (desired_velocity - ped_i.velocity) * ped_i.mass / ped_i.tau;
                        
                        Vector2D total_force = driving_force;

                        // 2. Calculate Interaction Forces from other pedestrians
                        for (const Pedestrian& ped_j : pedestrians) {
                            if (ped_i.id == ped_j.id) continue;
                            // ... calculate f_ij based on the full formula ...
                            total_force += calculate_interaction_force(ped_i, ped_j);
                        }

                        // 3. Calculate Interaction Forces from walls
                        for (const Wall& wall : walls) {
                            // ... calculate f_iw ...
                            total_force += calculate_wall_force(ped_i, wall);
                        }

                        // 4. Update pedestrian's state
                        ped_i.update(total_force, dt);
                    }
                }
                

II.Reciprocal Velocity Obstacles (RVO) - Elegant Local Obstacle Avoidance

Social force models are well-suited for simulating high-density, physically-contact crowds. However, for low- to medium-density scenarios requiring smooth, collision-free path planning (such as robot navigation or the daily movement of game characters), we need a method that focuses more on prediction and geometrics.

This is where Velocity Obstacles (VO) and its improved version, Reciprocal Velocity Obstacles (RVO), come in.

2.1. Background and Problem Description

Core Problem: In a shared environment, N agents all want to move from their respective starting points to their destinations. How can we ensure that they do not collide with each other during their movement?

  • This is a decoupled approach: each agent makes navigation decisions independently.

  • It focuses on local navigation: I only care about how to adjust my speed in the next instant to avoid colliding with my immediate neighbor.

2.2. Core Idea of ​​Velocity Obstacles (VO)

Imagine I am agent A, and there is agent B directly in front of me.

The question VO needs to answer is: In velocity space, which velocities can I (A) not choose, because choosing them will inevitably lead to a collision with B?

This set of “forbidden zones” is the velocity obstacle constructed by B for A.

Geometric Derivation:

  1. Relative Velocity: Whether a collision occurs depends only on the relative position and relative velocity of the two entities. Let A be the frame of reference; A is stationary, and B moves with a relative velocity .

  2. Collision Region: If the trajectory of B (a ray) passes through a disk centered at A with a radius of , then a collision will occur.

  3. Minkowski Sum: Geometrically, this collision region can be elegantly described as the Minkowski sum of A and B. It’s the region swept by “rolling” the shape of B (a circle) around the boundary of the shape of A (also a circle). For two disks, their Minkowski sum is a large disk with radius .

  4. Velocity Obstacle Cone: In velocity space, all rays extending from the origin (representing A’s current velocity) into this Minkowski sum region constitute a conical region. This cone is .

Conclusion: If the velocity chosen by A lies inside , then A and B will inevitably collide in the future. To avoid the obstacle, A must choose a velocity outside the cone.

2.3. The Fatal Flaw of VO: Oscillation

What happens if and are both intelligent agents, and they both calculate the VO for each other and attempt to avoid each other? Catastrophic oscillation!

Consider this process:

  1. and are traveling in opposite directions.

  2. Time : calculates ‘s VO and decides to turn right. calculates ‘s VO and also decides to turn right (from its own perspective).

  3. Time : ‘s new speed has avoided ‘s old VO. However, because has also moved, ‘s new speed creates a new VO for , and finds itself in the new VO! So adjusts again.

  4. Recurring Cycle: The two agents may swing back and forth like pendulums in front of each other, unable to make effective avoidance, resulting in a very ugly and inefficient path.

Reason: Each agent pushes the entire responsibility for obstacle avoidance onto the other, assuming the other will maintain its current speed without considering that the other is also intelligently avoiding obstacles.

2.4. RVO Solution: Shared Responsibility

The core idea of ​​RVO is: Let’s not shirk responsibility; let’s each share the responsibility for obstacle avoidance.

Implementation: When calculating VO, we no longer assume the other’s velocity remains constant. Instead, we assume that, to avoid the obstacle, we will coordinate our velocity changes in some way. The simplest and fairest way to coordinate is: Let’s work together to adjust the final relative velocity to the boundary of the VO cone.

Geometric Interpretation: This is equivalent to translating the original VO cone with vertex to a new vertex . This new cone is the mutual velocity obstacle .

(The geometric meaning of this formula is to double the velocity and then subtract to see if it lies within the original VO, equivalent to translation.)

Why can RVO solve oscillations? Because it is reciprocal. If chooses a new velocity on its RVO boundary, and also chooses a new velocity on its RVO boundary, then these two choices are compatible. Their new relative velocities will fall exactly on the boundary of the original collision cone, thus achieving a smooth “near miss” avoidance. The oscillation disappears!

Generalized RVO (ORCA - Optimal Reciprocal Collision Avoidance) goes a step further, where obstacle avoidance responsibility isn’t necessarily 50/50. We can introduce a parameter to allocate responsibility. For example, we can decide who should take more avoidance based on social status, quality, or urgency. This is the core idea of ​​ORCA, which provides more flexible control on top of RVO.

Experimental Comparison: In a classic “circle” experiment, N agents are evenly distributed on a circle, and each agent’s goal is to reach the opposite side of the circle.

  • Using VO: Agents huddle together near the center, resulting in chaotic paths filled with jitter and oscillations.

  • Using RVO/ORCA: Agents spontaneously form a beautiful, rotating vortex, smoothly, efficiently, and without collisions reaching their respective goals. This is a truly awe-inspiring emergent phenomenon.

III. Continuum Crowds - Macroscopic Flow

Both social force models and RVO belong to the agent-based approach, simulating each individual. When crowd density is extremely high, and individual free will is dominated by group flow, we can shift our perspective.

Core Idea: Instead of viewing the crowd as a discrete collection of “particles,” we consider it as a continuous medium, like flowing water. We don’t calculate the force or velocity of each individual, but rather the “field” throughout the entire space.

3.1. Methodology

  1. Discretization: Divide the scene into a grid.

  2. Field Calculation: Calculate various “fields” on the grid:

  • Density Field : How many people are in each cell.

  • Velocity Field : The average velocity of people in each cell.

  • Cost Field : The “cost” of walking in each cell.

  • Potential Energy Field : The “minimum total cost” to reach the destination from each cell.

  1. Update: Drive the flow of the crowd based on the gradient of the potential energy field.

3.2. Core Mathematics: Optimal Path and Potential Energy Field

a) Defining Cost We want pedestrians to choose an “optimal” path. What is optimal? It could be the shortest distance, the shortest time, or the most comfortable. We can define a total cost , which is the weighted sum of these three factors:

  • is the path length.

  • is the time.

  • is the cumulative “uncomfort” (e.g., is higher in crowded areas).

Because the speed , therefore . Substituting into the above equation, we can unify everything into the integral over the path length: . This is the unit cost field. It represents the total cost incurred to travel a unit length at point .

b) Solving for the potential energy field Now, we define a **potential energy field , whose value is equal to the minimum total cost of reaching the goal from point along the optimal path. This potential energy field satisfies a well-known partial differential equation—the Eikonal equation:

  • Intuitive understanding: The “steepness” of the potential energy field gradient is equal to the “cost” of walking at that location.

  • At the target point, . We can efficiently solve this equation using numerical methods such as the Fast Marching Method to obtain the potential energy field of the entire scene.

c) Driving Crowd Movement With the potential energy field, the optimal direction of movement for pedestrians becomes exceptionally simple: along the direction of the steepest decrease in potential energy, i.e., the negative gradient direction.

Each person is like a small ball placed on a potential energy surface, automatically rolling towards the lowest point (the target).

3.3. Advantages and Disadvantages

  • Advantages:

  • The movement path is very smooth, naturally avoiding the conflicts and jitter in agent-based methods.

  • It can well characterize some macroscopic phenomena, such as the formation of sidewalks and vortices during congestion.

  • High computational efficiency, especially suitable for global path planning for very large groups of people.

  • Disadvantages:

  • Lack of individuality. All people in the same cell behave the same way, making it difficult to represent individual differences.

  • Not suitable for unknown environments. It assumes that the crowd has a predictable global cost field.

  • Lack of inertia. The direction of velocity can change instantaneously, lacking a sense of physical realism.

In practice, continuous crowd models are often used to calculate a macroscopic guiding flow field, and then agent-based models, guided by this flow field, perform localized, personalized behavioral simulations.

Conclusion

This lecture focuses on the modeling and control of complex crowd movements, systematically outlining three core methodologies in crowd animation from different scales and modeling approaches. First, the social force model, by combining psychological factors with physical dynamics, achieves realistic simulations of high-density crowds and panic scenarios, providing an important tool for public safety analysis and emergency evacuation research. Its “faster yet slower” phenomenon also reveals the essential laws governing the nonlinear and emergent characteristics of crowd behavior.

Second, the RVO and ORCA models, from a geometric and predictive perspective, transform obstacle avoidance problems into constrained optimization problems in velocity space. Through a “responsibility-sharing” mechanism, they effectively avoid the oscillation problem in traditional VO methods, making them suitable for real-time navigation and game character control in low-to-medium density environments, reflecting the balance between local decision-making and global coordination.

Finally, the continuous crowd model, based on fluid dynamics and optimal path theory, treats the crowd as a continuous medium, characterizing macroscopic movement trends through potential and cost fields. It exhibits extremely high computational efficiency and stability in large-scale, high-density scenarios, but also sacrifices some individual differences and physical realism.

Overall, social force models emphasize the coupling of physical and psychological factors, Reactive Object Response (RVO) focuses on local geometric cooperation, while continuous models focus on macroscopic flow patterns. Modern crowd animation systems often organically integrate these three: using continuous models to provide global guidance, RVO to achieve local collision avoidance, and then enhancing realism and expressiveness through social force or behavioral models. Future development will further combine learning methods, real-time perception, and multimodal interaction to continuously improve the realism, controllability, and intelligence of crowd simulation.