Constrained Animation of Flocks - University of Wisconsin...

12
Eurographics/SIGGRAPH Symposium on Computer Animation (2003) D. Breen, M. Lin (Editors) Constrained Animation of Flocks Matt Anderson, Eric McDaniel and Stephen Chenney University of Wisconsin – Madison Abstract Group behaviors are widely used in animation, yet it is difficult to impose hard constraints on their behavior. We describe a new technique for the generation of constrained group animations that improves on existing approaches in two ways: the agents in our simulations meet exact constraints at specific times, and our simulations retain the global properties present in unconstrained motion. Users can position constraints on agents’ positions at any time in the animation, or constrain the entire group to meet center of mass or shape constraints. Animations are generated in a two stage process. The first step finds an initial set of trajectories that exactly meet the constraints, but which may violate the behavior rules. The second stage samples new animations that maintain the constraints while improving the motion with respect to the underlying behavioral model. We present a range of animations created with our system. Keywords: flocking, constraints, sampling, plausible simulation Categories and Subject Descriptors (according to ACM CCS): I.3.7 [Computer Graphics]: Three- Dimensional Graphics and Realism - Animation 1. Introduction Simulated group behaviors are widely used in anima- tion, with many production tools available, such as Weta Digital’s MASSIVE 11 and AI.implant 1 , a plug- in for Maya. Groups typically consist of individual agents, each with a set of parameterized rules govern- ing its behavior (originally described by Reynolds 21 ). The global behavior emerges from the actions of the individuals, producing large-scale effects that are oth- erwise hard to model. However, emergent behavior makes it very difficult to place constraints on the final motion. In this paper we describe a new technique for generating constrained group animations. There are many situations in which constrained group behaviors are necessary. In film, a director might script the path of a particular character within the group (for dramatic effect or as part of a story), while retaining the overall group motion. Advertisers might wish to use the shape or motion of the flock to con- vey a message. We present examples, among others, of email: {manderso,chate,schenney}@cs.wisc.edu an agent constrained to come from behind to win and an entire flock forming letters. In the past such scenes would be hand animated. The simplest method for generating constrained groups is to key-frame the agent of interest then sim- ulate the other agents while the constrained agent fol- lows its path (Figure 1). The key-framed agent in this situation is unable to respond to the actions of the other agents. One of two cases generally results: occa- sionally, the key-framed agent finds itself leading the group, but most often the constrained agent is unable to influence the group enough to avoid breaking off, as in Figure 1. An alternate approach adds a constraint enforce- ment behavior rule to the agents, such as the path following behavior described by Reynolds 22 or the planning-based behaviors of Bayazit et. al. 4 Addi- tional rules can guide the flock in real-time, as in gaming applications, but they must also interact with other behavior rules, such as collision avoidance and flock coherence rules. A significant parameter tuning problem is thus introduced: the constraint behavior must be strong to meet the constraints, yet not so c The Eurographics Association 2003.

Transcript of Constrained Animation of Flocks - University of Wisconsin...

Page 1: Constrained Animation of Flocks - University of Wisconsin ...pages.cs.wisc.edu/~schenney/research/directing/casim/acm-sca200… · Anderson et al / Constrained Animation of Flocks

Eurographics/SIGGRAPH Symposium on Computer Animation (2003)D. Breen, M. Lin (Editors)

Constrained Animation of Flocks

Matt Anderson, Eric McDaniel and Stephen Chenney†

University of Wisconsin – Madison

Abstract

Group behaviors are widely used in animation, yet it is difficult to impose hard constraints on theirbehavior. We describe a new technique for the generation of constrained group animations that improveson existing approaches in two ways: the agents in our simulations meet exact constraints at specifictimes, and our simulations retain the global properties present in unconstrained motion. Users canposition constraints on agents’ positions at any time in the animation, or constrain the entire groupto meet center of mass or shape constraints. Animations are generated in a two stage process. Thefirst step finds an initial set of trajectories that exactly meet the constraints, but which may violate thebehavior rules. The second stage samples new animations that maintain the constraints while improvingthe motion with respect to the underlying behavioral model. We present a range of animations createdwith our system.Keywords: flocking, constraints, sampling, plausible simulation

Categories and Subject Descriptors (according to ACM CCS): I.3.7 [Computer Graphics]: Three-Dimensional Graphics and Realism - Animation

1. Introduction

Simulated group behaviors are widely used in anima-tion, with many production tools available, such asWeta Digital’s MASSIVE11 and AI.implant1, a plug-in for Maya. Groups typically consist of individualagents, each with a set of parameterized rules govern-ing its behavior (originally described by Reynolds21).The global behavior emerges from the actions of theindividuals, producing large-scale effects that are oth-erwise hard to model. However, emergent behaviormakes it very difficult to place constraints on the finalmotion. In this paper we describe a new technique forgenerating constrained group animations.

There are many situations in which constrainedgroup behaviors are necessary. In film, a director mightscript the path of a particular character within thegroup (for dramatic effect or as part of a story), whileretaining the overall group motion. Advertisers mightwish to use the shape or motion of the flock to con-vey a message. We present examples, among others, of

† email: {manderso,chate,schenney}@cs.wisc.edu

an agent constrained to come from behind to win andan entire flock forming letters. In the past such sceneswould be hand animated.

The simplest method for generating constrainedgroups is to key-frame the agent of interest then sim-ulate the other agents while the constrained agent fol-lows its path (Figure 1). The key-framed agent in thissituation is unable to respond to the actions of theother agents. One of two cases generally results: occa-sionally, the key-framed agent finds itself leading thegroup, but most often the constrained agent is unableto influence the group enough to avoid breaking off,as in Figure 1.

An alternate approach adds a constraint enforce-ment behavior rule to the agents, such as the pathfollowing behavior described by Reynolds22 or theplanning-based behaviors of Bayazit et. al.4 Addi-tional rules can guide the flock in real-time, as ingaming applications, but they must also interact withother behavior rules, such as collision avoidance andflock coherence rules. A significant parameter tuningproblem is thus introduced: the constraint behaviormust be strong to meet the constraints, yet not so

c© The Eurographics Association 2003.

Page 2: Constrained Animation of Flocks - University of Wisconsin ...pages.cs.wisc.edu/~schenney/research/directing/casim/acm-sca200… · Anderson et al / Constrained Animation of Flocks

Anderson et al / Constrained Animation of Flocks

Figure 1: A comparison between our system (left) anda naively constrained agent (right). The same flock isrendered in gray and black, representing earlier andlater timesteps. In the naive case, the key-framed agentfollows the path while the other agents follow their reg-ular behavior rules. Despite the flock’s ability to see theconstrained agent, the result shown on the right is typ-ical – the unconstrained agents fly off leaving the key-framed agent behind. The standard fix for this problemis a rule that tells the flock to follow the constrainedagent, but that requires the constrained agent to lead.Our system solves for trajectories for all of the agentssuch that the constraints are satisfied and the globalmotion looks plausible, even if the constrained agentis embedded in the flock.

strong that it overrides other, visually important be-haviors. In an off-line production system, the tun-ing may need to be repeated for every constrainedshot, resulting in inconsistency in the flock’s motionacross scenes. Duncan11 describes the extensive be-havior tweaking for flocking scenes in the Lord of theRings, which ultimately required the addition of invis-ible geometry elements to guide agents. Our methodworks with existing, tuned models without modifica-tion to the rule-set or any other parameters.

Timing constraints pose particular difficulties forexisting methods. Rules can guide a character along apath, but the speed at which it moves is governed bythe interplay of many factors, such as the motion offlock-mates. Cuts between shots are typically used toaddress this problem, but they impose potentially un-desirable artistic limitations on a director. For exam-ple, the movie Spirit9, was hand animated to achieveboth good control and a long, continuous shot. Fur-thermore, with existing approaches it remains very dif-ficult to constrain multiple agents at the same time,enforce global constraints on all members of the flock

(such as shape constraints), or enforce constraints ononly part of the motion. Our system handles all ofthese cases.

Our major contribution is a method for imposinghard constraints on the paths of agents at specifictimes while retaining the global characteristics of anunconstrained flock. Our approach has several advan-tages for animators: it works with existing, tuned mod-els; it can enforce timing constraints on long sequenceswithout imposing cuts; and it offers new types of con-straints not previously available (e.g. global shape con-straints). We use a sampling approach to explore thespace of animations that meet the constraints, andoffer one or more to the user. Our algorithms are ap-plicable to an off-line production environment.

2. Related Work

Many techniques have been proposed to generate ani-mations that satisfy constraints and respect some un-derlying procedural model. Witkin and Kass26 workedwith articulated figures, and found joint torques overtime that produced the desired motion while minimiz-ing energy. This work, dubbed Spacetime Constraints,its extensions8, 18, and similar work2, 6, 14, 15, all usesome form of optimization to find the “best” solutionfor the trajectories. They require derivatives of theobjective function with respect to the control parame-ters, which are difficult to extract from flocking mod-els. Specifically, the standard methods for perceptionand inter-agent forces introduce significant disconti-nuities. Ngo and Marks19 used genetic algorithms inthe absence of derivatives, and later extended their ap-proach to collision intensive systems23, while Popovicet. al.20 used derivatives where possible and a randomsearch in other cases. However, these techniques donot scale well as the numbers of agents grows large.

Group behavior models generally don’t have an op-timal behavior. Randomness is frequently used to in-crease the variability in each agent’s behavior, whichimproves the appearance of the motion. Any one ofa large number of potential animations is thus con-sidered acceptable, with no principled way to choosea single best one. Barzel, Hughes and Wood3 notedthat randomness makes many types of simulation ap-pear more plausible, and that randomness can help tosolve constrained problems. Following, Chenney andForsyth7 solved collision intensive constraint problemsby sampling from a distribution describing plausibleoutcomes. We exploit the same ideas in our system.However, unlike previous approaches we explicitly en-force the constraints in a pre-sampling step, and thenmaintain them throughout the process.

c© The Eurographics Association 2003.

Page 3: Constrained Animation of Flocks - University of Wisconsin ...pages.cs.wisc.edu/~schenney/research/directing/casim/acm-sca200… · Anderson et al / Constrained Animation of Flocks

Anderson et al / Constrained Animation of Flocks

3. Constraining Flocks

Our system works on group behavior models that pro-duce agent trajectories and provide a way to evaluatethe plausibility of a given set of trajectories. In ourimplementation we use a variant of Reynolds’ flockingmodel22 (Section 3.1) that produces the positions ofagents over time, which in turn implicitly encodes thevelocities and orientations.

We aim to produce plausible animations that sat-isfy constraints while retaining the realistic proper-ties of the underlying behavior model. The flockingmodel we use incorporates a wander behavior rule22

that adds a random acceleration to each agent oneach discrete simulation timestep. Many group behav-ior models include such a random component to makethe motion appear less mechanical. Random compo-nents provide a natural way to assess the plausibilityof an animation3, 7: a plausible motion is one in whichthe random components used to generate the motionare reasonably distributed. Our technique does not re-quire random components – we could use any measureof plausibility that can be expressed as an objectivefunction.

Our implementation supports three types of con-straints: specific agents constrained to pass through alocation at a given time; the center-of-mass (COM)of the group constrained to a point at a time; andthe members of the flock constrained to lie within agiven shape at a specific time. Constrained anima-tions are produced in a two stage process. The firststage enforces the constraints without explicit regardto the plausibility of the result (Section 3.3). It usesa combination of methods: Forward simulation thatenforces a particular set of initial conditions and gen-erates unconstrained forward motion; Backward simu-lation that generates a simulation that ends at partic-ular positions; Path transformations that take groupmotion along one path and transform it to follow an-other path; and Path blending that interpolates themotion of agents between two paths. The system com-bines these methods to produce a set of trajectoriesthat satisfy the constraints.

The path transformation and blending techniquesdo not take into account the behavior rules – they arepurely geometric operations – and hence the result-ing paths may not be plausible. The second stage ofour solution method samples new animations to en-force plausibility requirements while maintaining theconstraints (Section 3.4). A sampling process is usedwith the output from the first phase as the initial sam-ple. The sampler repeatedly proposes a new anima-tion based on the old one, evaluates its plausibility,and decides to accept it as the new sample or rejectit and stay with the current sample. Animations that

wci-1wc

i-1

^

wii

wci

Figure 2: The wander contribution for step i, wci iscomputed based on the contribution for the previousstep and a randomly sampled wander impulse, wii, byadding the impulse to the previous contribution (nor-malized first to prevent it growing too large, as recom-mended by Reynolds). Note that the wander impulse israndomly chosen on each timestep and is uncorrelatedacross steps, while each wander contribution is derivedfrom the previous one and hence is correlated. Givena set of trajectories and the wander contributions, wecan infer wii and use it to evaluate the plausibility ofan animation (Section 3.4.2).

are more plausible than the current one will always beaccepted, while poorer examples will occasionally beused. The process is similar to simulated annealing butwithout the temperature reduction component. Afterrunning the sampler until the average plausibility sta-bilizes, or for a fixed number of steps, the last sam-ple is presented as a solution. Multiple samples couldbe kept to give a user several options, or multiple in-stances of the process could be run.

The remainder of this section discusses each com-ponent of our algorithm in detail. Section 4 presentsseveral animations produced with our system and dis-cusses its limitations. We conclude in Section 5 witha look at potential extensions and improvements.

3.1. Behavior Model

Our underlying behavior model is based onReynolds’22 work. The internal state of eachagent for each timestep consists of three vectors: itsposition, velocity and wander contribution (describedbelow). For subsequent processing we keep only theposition and wander contribution, as the velocity canbe inferred from the sequence of positions.

Each agent has a set of rules that contribute acceler-ation requests on each timestep. The requests are com-bined through a weighted average and the result is ap-plied as an impulse to the agent. The behavior of anyagent at any timestep depends only on the positionsof all the agents and obstacles at that timestep, andthe wander contribution from the previous timestep.We use the following behavior rules:

Separation: Move away from your nearby neighbors.

c© The Eurographics Association 2003.

Page 4: Constrained Animation of Flocks - University of Wisconsin ...pages.cs.wisc.edu/~schenney/research/directing/casim/acm-sca200… · Anderson et al / Constrained Animation of Flocks

Anderson et al / Constrained Animation of Flocks

Cohesion: Move toward the average position of yourneighbors.

Alignment: Align your velocity with that of yourneighbors.

Collision Avoidance: Steer away from impendingcollisions with static objects.

Speed Target: Try to attain a user defined speed.Wander: Add a random wander contribution acceler-

ation based on the previous timestep’s wander con-tribution and a random vector (Figure 2). The wan-der contribution is designed to improve realism byadding random variations to the paths of the agents.

The weights used in the averaging process are de-fined as part of the behavior model and are a sig-nificant factor in determining the appearance of theflock. A user sets these weights in the absence of anyconstraints to get the desired flock appearance, inde-pendent of our algorithm, and our technique does notmanipulate them further.

Behavior models in our system must support threeoperations: Forward simulation: The simulation ofthe behaviors forward from a set of initial conditions;Plausibility Assessment: Given a set of trajectoriesand a timestep, the model must be able to assess theplausibility of the state at the timestep; Backward

Simulation: Simulation of the behaviors backwardin time from a set of end conditions. In practice, wesimulate forward using the regular behavior rules, butwith sense of perception reversed so that agents seethose behind them. The resulting sequence of statesis then reversed. In effect, the agents react to thosebehind them while simulating, but after reversal theyappear to be reacting to those in front, as they nor-mally would. Our technique uses backward simulationin an intermediate step, so it is not essential that itbe high quality motion. In Section 4 we discuss waysto remove the requirement for backward simulation.

Our constraint solution process views an animationas the set of trajectories of all the agents through thetime interval of interest. For all our examples, thesetrajectories are the positions and wander componentsof the agents sampled at 10Hz from the simulator.Velocities are implied by the positions. It is commonpractice to sample behaviors at such frequencies, andit produces good results. The system can readily ac-commodate variations in sampling rate, with compu-tational cost increasingly roughly linearly with thenumber of samples. Agents move in a piecewise lin-ear manner between sample points, and are alwaysaligned with their velocities.

In principle our approach could handle other com-ponents of agent state, such as explicit orientation,but we have not experimented with such cases. Fur-thermore, our approach should work with any group

behavior model that supports the forward, backwardand evaluation operations. We have, however, only ex-perimented with the flocking model.

3.2. Constraints

Our system supports three types of constraints: pointconstraints for which a specific agent must passthrough a given point at a given time; center-of-mass(COM) constraints in which the COM, or averageposition, of a subset of the flock must be at a spe-cific point at a specific time; and shape constraints forwhich a subset of the flock must lie inside a polygonalshape. Constraints can be mixed in any sensible way.For instance, different agents can be constrained at dif-ferent times, or one agent can have a series of pointsto pass through, effectively key-framed with flockingmotion interpolation. The COM constraint mimics thetraditional “fly to point” constraint, but with precisecontrol over timing.

Velocities must be associated with each constraintto aid in the generation of an initial sample. A userexplicitly provides these for shape constraints, whilefor point and COM constraints the velocities are in-ferred by grouping contiguous constraints and fittinga Bspline path. The arc length and time between con-straints gives a velocity. Isolated point or COM con-straints have their velocities provided by the user. Ve-locities are only of temporary use and are not en-forced by the system as currently implemented, al-though they could be enforced with very little modi-fication to our approach.

Point constraints are explicitly enforced when aninitial sample solution is generated, as described inthe next section, and then maintained throughout thesampling process. COM and shape constraints are pre-cisely satisfied by the initial sample process, but in thesubsequent sampling phase they are enforced throughtheir contribution to the plausibility of the animation,as detailed in section 3.4.2.

3.3. Enforcing Constraints with an Initial

Solution

With a set of constraints defined, the system finds a setof trajectories to use as the initial sample for the sub-sequent refinement process. Our aim with this phaseis to create trajectories that exactly meet all the con-straints. We would also like the resulting animationsto be plausible, but that is not an over-riding concern– the sampling phase can fix problems.

We define a window to be an interval between twosequential constraints. Constraints must be satisfiedonly at the start and end of any window (Figure 3),

c© The Eurographics Association 2003.

Page 5: Constrained Animation of Flocks - University of Wisconsin ...pages.cs.wisc.edu/~schenney/research/directing/casim/acm-sca200… · Anderson et al / Constrained Animation of Flocks

Anderson et al / Constrained Animation of Flocks

t=1

t=13

t=10t=7

t=5

t=3

Figure 3: The constrained interval is broken into win-dows for generating initial trajectories. The windowsin this example are the intervals [1, 5], [5, 7], [7, 10] and[10, 13]. Every constrained time defines a new windowboundary, unless the constraint is part of a contiguoussequence of point or COM constraints for a particularset of agents (such as at t = 3). In this figure, thedifferent symbols indicate different agents.

except that a new window is not defined for pointor COM constraints that are part of a contiguous set(our techniques meet these constraints when trajecto-ries are found within a window). We then roll forwardthrough the sequence of windows, generate an initialand final configuration for each window, and join themwith plausible trajectories that are cheap to compute.

3.3.1. Generating Constrained Configurations

The initial flock configuration for the first windowmust satisfy all the constraints at that time and bea reasonable snapshot of the flock’s motion. Likewise,the end configuration of the first window must alsosatisfy all the constraints and be plausible. For subse-quent windows, the final configuration from the pre-vious window provides a set of initial conditions thatsatisfy the constraints, while a satisfactory end con-figuration must still be created.

The process of finding a constrained configurationalways begins with a snapshot of simulated motion,either the final configuration of a short unconstrainedsimulation or the outcome of a forward simulationfrom the start of a window. To ensure that all theconstraints are satisfied, we then modify this snapshotaccording to the following rules:

• For each point constrained agent, the system appliesa translation and rotation to move it to its targetposition and align its velocity with that implied bythe constraint sequence. The transformations thatwere used are stored.

• If a subset of agents is COM constrained, the groupis rigidly translated and rotated from the snapshotto make the COM meet the constraint and its veloc-ity. We are also free to re-assign agents among thesnapshot positions, because that will not change the

COM. If we are finding a configuration for the endof a window, we sample a matching10 that reducesthe sum of squared distances between the locationof each agent at the start of the window and its po-sition at the end. This reduces the degree to whichthe agents must mix in getting from one constraintto another, which results in more plausible motion.

• If a subset of agents is shape constrained, we sam-ple one point inside the shape for each agent. Thesamples are initially chosen uniformly at randomwithin the shape, and then a few relaxation stepsare performed on the point set to push very closepoints apart. We then do a re-assignment of agentsto points as described for COM constraints.

• If the agent is unconstrained, the closest constrainedagent in the snapshot is found, and that agent’stransformation is applied. Alternately, we couldchoose a constrained agent at random; which optionis better depends on the users preferences. Choosingthe closest point produces smoother, but sometimesless interesting, results.

The result is a flock that tends to look plausible butis not assured to be so. If there is only one con-strained agent, or a COM constraint, the result is gen-erally reasonable because it represents a rigidly trans-formed version of an unconstrained forward simulatedflock. Otherwise, the results depend on the number ofconstrained agents and the plausibility of their con-strained positions, which presumably arise from au-thoring considerations and are out of the system’s con-trol.

3.3.2. Finding Initial Trajectories

The initial constraint enforcement process must find aset of trajectories within each window that meet theinitial and final constraints for that interval. Depend-ing on the constraints to be met, some or all of thefollowing operations are performed:

Operation 1: Simulate forward to meet initial

conditions. An unconstrained forward simulation isalways run, starting with the initial conditions for thewindow, for the duration of the window.

Operation 2: Transform the forward simu-

lated trajectories to meet point constraints. Ifthe window is part of a sequence of point constraintson one or more agents, we fit a Bspline curve throughthe sequence and transform the result of Operation1 such that the constrained agents follow the Bsplinepaths. The forward simulated path is time parame-terized, as are the constrained agents’ Bsplines. Ateach timestep the translation required to move eachconstrained agent from its forward simulated positiononto its Bspline path position is computed and ap-plied. Similarly, if the window is part of a sequence

c© The Eurographics Association 2003.

Page 6: Constrained Animation of Flocks - University of Wisconsin ...pages.cs.wisc.edu/~schenney/research/directing/casim/acm-sca200… · Anderson et al / Constrained Animation of Flocks

Anderson et al / Constrained Animation of Flocks

of COM constraints, we perform a path translationto move the COM of the flock onto the interpolatedpath. Unconstrained agents (with no point, COM orshape constraints) receive the translation for the agentto whom they were closest at the start of the window,or the COM translation. At the end of this step, allthe agents with contiguous constraints that span thewindow are on their required trajectory, and the win-dow is done if there are no additional constraints atthe end of the window.

Operation 3: Simulate backward to meet end

constraints. End constraints will not be satisfied byOperation 2 for agents that are shape constrained, orpoint or COM constrained only at the end of the win-dow. The configuration generation technique of Sec-tion 3.3.1 is used to generate a final configuration forthe window, but agents already in the correct posi-tion are left unchanged. A backward simulation is runfrom the resulting set of end conditions. The back-ward trajectory is path transformed as in Operation2 to enforce any contiguous point and COM con-straints. Finally, the positions of agents from the for-ward and backward simulations are blended to gen-erate the final set of trajectories. The blend func-tion we use is x = (1− u)xforward + uxbackward withu = −

(

2t3 − 3t2)

for scaled time t running from 0 to1 within the window. This blending function17 retainsthe velocities from the forward trajectories at the startof the interval, and the velocities from the backwardsimulation at the end of the interval.

Cases occur in which no agent is part of a sequenceof point constraints within the window, and hencethere is no Bspline path to use as a reference pathfor path transformations. In this case we construct aHermite curve that joins the center of masses for theinitial and final conditions and has tangents alignedwith the agents’ average velocities. This curve, andthe center of mass for the flock throughout the win-dow are used to compute a translation that moves thecenter of mass of the flock along the Hermite curvejoining the initial and final conditions.

After applying these operations in every window,the system has a set of constraint satisfying trajec-tories for all the agents throughout the entire con-strained interval. The trajectories are joined to formone continuous set. They may not, however, be plau-sible: our methods for building them, including set-ting constrained configurations, translating agents andblending positions may result in collisions, tight loopsor other implausible motions. The sampling phase, de-scribed next, refines the initial result to generate aplausible final animation.

3.4. Sampling Plausible Solutions

The trajectory generation process provides initial tra-jectories for all of the agents through the constrainedinterval. A sampling process, akin to Markov chainMonte Carlo or simulated annealing, is used to re-fine these paths to produce more plausible results. Thehigh-level algorithm is:

generate initial trajectories, A0

while not donepropose candidate trajectories, Ac, based on Ai

u← random(0, 1)if u < Paccept

Ai+1 ← Ac

else

Ai+1 ← Ai

The sampling chain is run for either a fixed num-ber of iterations or until the plausibility of the ani-mations stabilizes. Two components are essential tothe operation of the sampling process: the proposalmechanism that generates a candidate animation, Ac,based on the current one, Ai; and the acceptance cri-teria, Paccept, used to determine if the candidate isaccepted.

We use an acceptance criteria motivated by theMarkov chain Monte Carlo (MCMC) algorithm13:

Paccept =g(Ac)

g(Ai)

where g(A) is an objective function evaluated on theanimation, A. The criteria differs from that of MCMCin two ways: we do not require that the objective func-tion g be a valid probability distribution, and we ig-nore the transition probability between states. Theresult is a sampling strategy that balances switch-ing between different samples and favoring plausibleanimations, without getting stuck in local minima oraccepting too many poor results. In the next sectionwe discuss the methods for proposing new animations,while in Section 3.4.2 we describe the objective func-tion g(A).

3.4.1. Proposal Strategies

The system randomly chooses one of three strate-gies to propose candidate animations. Each has accessto the current animation (the trajectories for everyagent), the constraints, and the windows used to pro-pose the initial sample.

Propose completely new trajectories: Thisstrategy re-runs the process in Section 3.3 to generateentirely new trajectories within a subset of the con-strained period. With 50% probability this proposalregenerates all of the trajectories using the procedure

c© The Eurographics Association 2003.

Page 7: Constrained Animation of Flocks - University of Wisconsin ...pages.cs.wisc.edu/~schenney/research/directing/casim/acm-sca200… · Anderson et al / Constrained Animation of Flocks

Anderson et al / Constrained Animation of Flocks

in Section 3.3. Otherwise, 1, 2 or 3 contiguous win-dows are chosen to be replaced, with uniform prob-ability of generating any subset. When regeneratingwithin a subset of the windows, additional, temporaryconstraints are placed at the ends of the subset to en-force continuity with neighboring windows (which areunchanged by the process). This proposal strategy isuseful throughout the refinement process to encouragegood mixing – the creation of significantly different an-imations – because it tends to propose animations thatare locally different but not so bad as to be rejected.This strategy is chosen with probability 0.1.

Propose bumps: This strategy adds 1 to 3 ran-domly positioned and shaped bumps to the currenttrajectories. The bumps can be any length up to twicethe length of the trajectory, although the randomchoice of bump size is biased toward those that cover1 to 10 steps. The bumps are allowed to be longerthan the trajectory, in which case the unused portionis thrown away. In that case, however, the endpointsof the trajectory will be changed. The center of thebump is placed at a timestep chosen at random, withthe probability of choosing any point inversely pro-portional to its plausibility. Particularly poor sectionsof animation are therefore more likely to be modified.A specific agent’s trajectory is chosen uniformly atrandom from among the agents, but agents for whomthe bump would break constraints are excluded. Thisensures that the point constraints are maintained.

The bump is added to the trajectory in a multi-resolution manner in order to have the bump “follow”the trajectory as it is added. We first define the bumpin 3D in a plane that contains the x-axis, but is oth-erwise randomly oriented. The bump is parameterizedby the distance along the x-axis, from its start at x = 0to its end at x = 1. The distance from the axis is givenby d = 16s(x2 − 2x3 + x4), which results in a curvewith zero derivative at the points x = 0 and x = 1, asshown in Figure 4. The parameter s defines the sizeof the bump; it is samples from a normal distributionwith mean 0 and standard deviation 0.05.

In our system the trajectory is sampled at discreteintervals, and the bump is sampled to give the samenumber of samples as the trajectory has over the re-quired length of the bump. A multi-resolution decom-position is performed on both the bump and the pieceof trajectory to be modified. The decomposition re-cursively down-samples a curve by a factor of two,replacing every second point with its offset from themidpoint of its neighbors (Figure 4). The offset co-ordinates, oi, for point i, pi, at level l is computedas follows (level 0 is the curve consisting only of the

pi

pi+n/2l

pi-n/2l

m

d

t n

0.8

1

0

0.2

0.4

0.6

0.2 0.4 0.6 0.8 1

Figure 4: One proposal strategy adds bumps to seg-ments of an agent’s trajectory. Top left: The bumpis a quartic curve with zero value and derivative atits ends. We scale the vertical size of the bump bya normally distributed random amount with mean 0and standard deviation 0.05. Top right: bumps areadded in a multi-resolution manner. The position of apoint is encoded according to its offset from its neigh-bors’ midpoint, expressed in a coordinate frame deter-mined by the neighbors’ locations. See the text for de-tails. Bottom: The result (dashed) of adding a bump ofheight 0.05 to a segment of curve (solid). Our multi-resolution strategy automatically accounts for the ori-entation off the curve segment and the scaling of thebump.

endpoints of the original curve):

m =pi+n/2l + pi−n/2l

2d = pi −m

n = pi+n/2l − pi−n/2l

t = r× n

s = n× t

oi =

(

1

‖n‖ (d · n) ,1

‖n‖ (d · s) ,1

‖n‖ (d · t))

The midpoint, m, of the neighbors at level l is com-puted first, and then pi’s offset from it. A coordinateframe, (n, s, t) is computed using the unit vector alongthe line joining pi’s neighbors, n, and a global unitvector r. The multi-resolution coordinates stored forpi are the projections of its offset onto this coordinateframe, divided by the distance between the neighbors.

Our method is a modified version of a standard tech-nique for multi-resolution decomposition of a curve,

c© The Eurographics Association 2003.

Page 8: Constrained Animation of Flocks - University of Wisconsin ...pages.cs.wisc.edu/~schenney/research/directing/casim/acm-sca200… · Anderson et al / Constrained Animation of Flocks

Anderson et al / Constrained Animation of Flocks

(producing results similar to those of Finkelstein andSalesin12 and similar to the “standard” method men-tioned in Guskov et. al.16) except that we work with3D curves and have a scaling factor derived from thespacing of the samples. The move to 3D necessitatedthe use of the global vector r, which orients the refer-ence frame about the line joining the neighbors. With2D curves the orientation is implicit. There remains apotential degeneracy, if the line joining the neighborsis aligned with r, but we detect this case and use a dif-ferent r. We have not found this to be a problem. Thescaling of the coefficients by the distance between theneighbors automatically accounts for varying samplespacing in world coordinates, and also automaticallyscales the bump according to the length of the seg-ment.

After decomposing both the bump and the segmentof the trajectory, their multi-resolution coefficients areadded. The new segment of trajectory is recomposedand put in place of the original segment. This pro-posal strategy is chosen with probability 0.6. It is sig-nificantly cheaper than the complete regeneration oftrajectories, and is very effective at cleaning up lo-cal problems with a solution or mutating an alreadyplausible solution.

Propose velocity changes: This proposal adjuststhe speed with which some agents move along theirtrajectory. Qualitatively, the proposal increases thespeed of an agent through one portion of its trajec-tory, then decreases it in a subsequent section, so thatthe agent travels the same overall distance and con-tinuity of the trajectories is maintained. A procedureidentical to that above is used for selecting trajectorysegments to modify. The system computes the cumu-lative distance traveled by the agent at each samplepoint over the segment of interest, then adds an offset,o, to each distance given by o = 16s(u2 − 2u3 + u4),where u varies from 0 to 1 along the segment, and s isa scaling value chosen from a normal distribution withmean 0 and standard deviation of 0.025 × r, where ris the length of the segment to modify. The trajectoryis re-sampled to give points spaced according to themodified distances. This strategy is chosen with prob-ability 0.3, and its effects are like those of a bumpaddition: it is good for resolving local problems andmutating plausible solutions.

3.4.2. Evaluating Animations

The evaluation function takes the product over alltimesteps in the constrained regions. Each timestephas terms for the plausibility of the wander impulsesused, gw, terms for any COM, gc, or shape constraints,gs, that may be active at that time, and a term that

biases toward a single flock, gf . Overall,

g(A) =∏

t∈[0,T ]

gw(A, t) · gc(A, t) · gs(A, t) · gf (A, t)

where the various component functions are defined inthe following sections. Note that terms for the pointconstraints are not required because they are enforcedin the initial trajectory generation step and the pro-posal mechanism maintains them.

The plausibility of a step in the flocking model isevaluated based on the wander contribution impliedby the trajectories on that step. In a regular forwardsimulation, the wander contribution for step i, wci iscomputed based on the previous wander vector anda randomly sampled wander impulse, wii (Figure 2).This contribution is included in a weighted sum of allthe behavior contributions to compute the instanta-neous change in velocity of the agent at that timestep.The other behaviors depend only on all the agents’ po-sitions and velocities at the timestep in question.

The sampling of wander impulses in a forward sim-ulation produces plausible results. If the wander im-pulses implied by a set of constrained trajectories looklike they were sampled from the same distributionas those sampled in the forward case, we can saythat the trajectories represent a plausible animation.When given a set of trajectories and timestep to evalu-ate, the system computes the total impulse applied atthe timestep (the difference in velocities from beforeand after the step). Treating the trajectories as theoutcome of a forward simulation, this impulse is theweighted average of the wander contribution and theother behaviors. From the agents’ positions we com-pute the contribution due to the other behaviors. Thediscrepancy between that and the total observed im-pulse is the wander contribution that would be usedby a forward simulation to generate the trajectories.If these wanders look like they were sampled correctly,the animation is plausible.

To evaluate the function gw, we compute the wan-der contribution from both the current and previousstep, and hence the wander impulse for the currentstep wii (see Figure 2). We define gw to be the prob-ability of seeing the complete set of wiis for an entiresimulation. In the flocking model we use, the wanderimpulses are vectors in a uniformly random directionwith a normally distributed length with mean 0 andstandard deviation set by the user, typically to a valueof σw = 0.125. Hence,

gw(A, t) =∏

i

1

σw

√2π

e−‖wii(A,t)‖/2σ2

w

where i ranges over the agents in the system.

The COM constraints are enforced with the follow-

c© The Eurographics Association 2003.

Page 9: Constrained Animation of Flocks - University of Wisconsin ...pages.cs.wisc.edu/~schenney/research/directing/casim/acm-sca200… · Anderson et al / Constrained Animation of Flocks

Anderson et al / Constrained Animation of Flocks

Figure 5: Three frames from an example in which an agent (larger and brighter) is constrained to come frombehind to win a race. Constraints are placed at the start and end time of the race. At the start time, the winningagent is point constrained to be behind the rest of the flock, which is COM constrained. At the end time, the agentis point constrained in front of the other COM constrained agents.

ing term:

gc(A, t) =∏

C∈COM(t)

1

σcom

√2π

e−‖COM(A,t)−Cx‖/2σ2

com

where C is a constraint requiring the COM to be atCx, COM(t) is the set of COM constraints active atthe timestep, COM(A, t) is the COM of the group attime t, and σcom is a user defined parameter (set to0.1 for all our examples).

Shape constraints contribute a term that dependson the sum of squared distances of each agent from itsnearest point in the shape.

gs(A, t) =∏

S∈SHAPES(t)

e−cSd(S,A,t)

where S is a shape, SHAPES(t) is the set of shapeconstraints active at the timestep, and cS is a userdefined constant, set to 10 in all our examples. Ourimplementation currently only supports 2D shapes de-fined as a set of triangles. This makes it simple to finddistances to the shape. For 3D we could constrain theagents to fill a volume (with no change to our algo-rithm) or to form a shape when projected onto theimage plane.

Under our plausibility model, a group of completelyisolated agents are every bit as valid as a single flock,provided their wander impulses are reasonable. Tokeep the flock together, we employ a term that fa-vors a particular number of flocks, where a flock is aset of agents with the property that every agent cansee some other agent in the same flock, but all of theagents in one flock are unable to see any agent in an-other flock. The term is:

gf (A, t) = e−cF |F−Fc|

where F is the number of flocks at time t, Fc is thepreferred number as defined by a user, and cF is a con-

stant, set to 1000 for our examples. In all our exampleswe requested a single flock.

The system is relatively insensitive to the values ofthe constants cS , cF and σcom. Values that range overan order of magnitude appear to perform equally well.

4. Examples

The simplest example for our system is a single con-strained agent (Figure 1). The process for proposinginitial samples does well in this case, and the samplingproduces a range of variations. It is difficult to deter-mine which agent is constrained unless the constraintis explicitly visualized. Figure 5 is an example of mix-ing position and COM constraints, in which an agentis constrained to be behind the flock at the begin-ning and in front by the end. This example highlightssome of the problems with using rules to achieve con-straints. The “winning” agent could be started at theback and given a higher target speed, but the parame-ters of the speed rule need to be balanced against theother flocking rules (particularly the alignment rulethat attempts to match velocities within the flock).The rule balancing process is typically very time con-suming and would need to be repeated if the con-straint was changed, whereas our method meets thegoals without any modification to the behaviors. Mostof our examples are in 2D for easier visualization, butthe system works equally well in 3D (Figure 6).

Constraints in the presence of static obstacles pro-pose particular challenges for our system, because wecompletely ignore them in the initial trajectory gen-eration procedure and correct them in the samplingphase. Experiments indicated that, when used to gen-erate initial trajectories, obstacles introduced devia-tions that were inappropriately shifted to new loca-tions by the path translation operation. If obstaclesare ignored, the initial trajectories frequently contain

c© The Eurographics Association 2003.

Page 10: Constrained Animation of Flocks - University of Wisconsin ...pages.cs.wisc.edu/~schenney/research/directing/casim/acm-sca200… · Anderson et al / Constrained Animation of Flocks

Anderson et al / Constrained Animation of Flocks

Figure 6: Our system also operates in 3D, as illus-trated by this frame from an animation in which theflock follows a looping path.

Figure 7: An example in which the flock is forced, viacenter of mass constraints, to fly very close to a staticobstacle. The left frame shows the initial paths gener-ated by the system. The obstacles are ignored becausewe found they introduced artifacts in the motion. Thesubsequent sampling process removes the penetrationsresulting in a plausible animation (right).

agents that pass through obstacles, and the samplingprocess must make more iterations to correct the prob-lems. The example in Figure 7 demonstrates staticobstacles combined with COM constraints. This se-quence is 5 seconds long and required 200 samplingiterations to generate the solution shown. This tookabout 10 seconds on a current generation PC.

The examples in Figure 8 demonstrate the effect ofusing our system with different flocking parameters,and hence different measures of plausibility. The flockon the left uses our standard parameters. The one onthe right places a heavier weight on the cohesion be-havior, causing the agents to flock much more tightlyand circulate within the flock more rapidly. Resultsfrom identical constraint sets, with two constrainedagents, are also shown. Note the constrained resultsresembles the unconstrained flocks. Each constrained

example from Figure 8 took a few minutes to compute,and the sampling process stabilized around a plausibleanimation after about 800 iterations.

Cases containing multiple agents with point con-straints are more difficult than single constrained casesbecause our initial trajectory generation process trans-lates unconstrained agents according to only one ofthe constrained agents. This produces motion that ini-tially is not very plausible. The sampling process gen-erally manages to find solutions despite the limitationsof the initial step, as Figure 8 illustrates.

The greatest limitation of our system is the processfor generating initial trajectories. It could be improvedby including more behavioral information into the pro-cess. The current system only reflects behavioral ef-fects if they survive the path translation and blendingoperations, which they frequently do not. One promis-ing approach is to set the trajectories of agents one ata time, using information obtained from the behav-ior rules to place each agent relative to those alreadypositioned. Alternatively, additional behavioral rulescould be used in the initial constraint generation pro-cess and then removed for the sampling phase. Thiswould also remove the requirement for backward sim-ulation and path blending.

It is possible for a user to specify constraints that aflock cannot reasonably meet. Our system will still en-force them, but the motion may not appear plausible.The spacing of constraints causes the most difficul-ties, either because agents may be forced to move toofast or slow, or because the flock may have insufficienttime to re-arrange itself between constraints. Our in-terface for setting constraints provides hints for thespacing of constraints based on speed requirements.Otherwise we have found the cause of problematic mo-tion to be visually obvious, and a user could adjust theconstraints if that were a concern.

Our system produces solutions in seconds for smallexamples, up to hours for long samples that need torun for many sampling iterations. The running time ofany one iteration is dominated by the time to simulateand evaluate the flock, which in turn is dominated bynearest neighbors computations. In our current imple-mentation this scales quadratically, and we found thatfor the flock sizes we used (up to 100 agents) the use ofspatial data structures did not improve the situationbecause most agents can see each other. Otherwise, therunning time scales roughly linearly with the length ofthe constrained sequence, but it is hard to estimate upfront the run time required for a particular constraintset. Our experience indicates that scenarios with mul-tiple constrained agents and static obstacles are themost difficult to solve. Multiple instances of our sys-tem will produce different results, making it a good

c© The Eurographics Association 2003.

Page 11: Constrained Animation of Flocks - University of Wisconsin ...pages.cs.wisc.edu/~schenney/research/directing/casim/acm-sca200… · Anderson et al / Constrained Animation of Flocks

Anderson et al / Constrained Animation of Flocks

Figure 8: Our approach retains the overall properties of the original behavior model. The two left images areof our standard flock, with the leftmost unconstrained and the center-left one required to satisfy simultaneouspoint constraints on two agents. On the right are corresponding snapshots of an insect-like flock, in which agentscirculate more rapidly and fly closer together. The far-right flock was required to satisfy the same constraints asthe center-left flock, but notice that it retains the insect-like properties.

Figure 9: An example of shape constraints solved with our system, in which 50 agents in a flock form each arrowin turn. The initial trajectory generation procedure is very effective for shape constraints. This example was runfor only 1000 sampling iterations (taking two hours).

candidate for cluster computing. Several jobs can besent out and the results perused for the best solutions.

5. Conclusion

Our system succeeds at producing constrained flockingmotion for a wide variety of examples. Unlike previ-ous systems, we enforce hard position constraints, wespecify the times at which constraints must be met,and we generate solutions that respect the underlyingbehavioral model. While it sometimes produces poorresults, one or two additional constraints were suffi-cient to improve the performance of our system whenneeded, and it was always clear how to place them.Furthermore, the system can produce many candidatesolutions, from which a user can select the most ap-propriate. Overall we explored a problem of significantpractical importance not comprehensively addressedpreviously in the literature.

We would like to make stronger claims that the an-imations produced by our system are representativeof the underlying model. We could do this if we guar-anteed that our sampling phase produced animationsdistributed identically to those of the unconstrainedcase. Markov chain Monte Carlo sampling would en-able us to make such claims, but our current proposalstrategies preclude this. In particular, the addition of

multi-resolution bumps is not an easy operation toinvert, and hence it is hard to compute the reversetransition probabilities required for MCMC13. Alter-nate proposal schemes could be designed, but thosethat we considered (adding bumps in world coordi-nates, for instance) would not produce proposals asgood as our current choices.

While we have demonstrated our system for a flock-ing model, we are interested in testing its performanceon other behavioral models. In principle, we require asimulator that implements only a few functions (Sec-tion 3.1), of which the ability to simulate backwardis probably the most limiting. Of particular interestare the dynamically accurate models of Brogan andHodgins5 or Tu and Terzopoulos25, or behavioral mod-els based on particle system, such as those used forStar Wars: Episode 1 24.

Acknowledgments

This work was funded in part by NSF grant CCR-0204372. We appreciated the comments and sugges-tions of those who reviewed this paper.

References

1. AI.implant, 2003. http://www.ai-implant.com.

c© The Eurographics Association 2003.

Page 12: Constrained Animation of Flocks - University of Wisconsin ...pages.cs.wisc.edu/~schenney/research/directing/casim/acm-sca200… · Anderson et al / Constrained Animation of Flocks

Anderson et al / Constrained Animation of Flocks

2. Ronan Barzel and Alan H. Barr. A ModelingSystem Based on Dynamic Constraints. In Com-puter Graphics (SIGGRAPH 88 Conf. Proc.), vol-ume 22, pages 179–188, August 1988.

3. Ronan Barzel, John F. Hughes, and Daniel N.Wood. Plausible motion simulation for computergraphics animation. In Computer Animation andSimulation ’96, pages 184–197, 1996. Proceedingsof the Eurographics Workshop in Poitiers, France,August 31-September 1, 1996.

4. O. Burchan Bayazit, Jyh-Ming Lien, andNancy M. Amato. Better flocking behaviorsin complex environments using global roadmaps.In Proceedings of the Workshop on AlgorithmicFoundations of Robotics (WAFR’02), 2002.

5. David Brogan and Jessica Hodgins. Group be-haviors for systems with significant dynamics. InProceedings of the 1995 IEEE/RSJ InternationalConference on Intelligent Robots and Systems,volume 3, pages 528–534, 1995.

6. Lynne Shapiro Brotman and Arun N. Netravali.Motion interpolation by optimal control. Com-puter Graphics (SIGGRAPH 88 Conference Pro-ceedings), 22(4):309–315, August 1988.

7. Stephen Chenney and D.A. Forsyth. Samplingplausible solutions to multi-body constraint prob-lems. In SIGGRAPH 2000 Conference Proceed-ings, pages 219–228. ACM SIGGRAPH, July2000.

8. Michael F. Cohen. Interactive spacetime controlfor animation. In Computer Graphics: Proceed-ings of SIGGRAPH 92, volume 26(2), pages 293–302, 1992.

9. Doug Cooper. Challenges of the homeland panin “Spirit”, 2002. SIGGRAPH 2002 ConferenceAbstracts and Applications, page 156.

10. Frank Dellaert. Monte Carol EM for Data-Association and its Applications in Computer Vi-sion. PhD thesis, Carnegie Mellon University,2001.

11. Jody Duncan. Ring masters. Cinefex, (89):64–131, April 2002.

12. Adam Finkelstein and David H. Salesin. Multires-olution curves. In Computer Graphics: Proceed-ings of SIGGRAPH 94, pages 261–268, 1994.

13. Walter R Gilks, Sylvia Richardson, and David JSpiegelhalter. Markov chain Monte Carlo inPractice. Chapman & Hall, 1996.

14. Michael Gleicher. Motion editing with space-time constraints. In Proceedings 1997 Symposium

on Interactive 3D Graphics, pages 139–148, April1997. Providence, RI, April 27-30.

15. Radek Grzeszczuk, Demetri Terzopoulos, and Ge-offrey Hinton. Neuroanimator: Fast neural net-work emulation and control of physics-based mod-els. In Computer Graphics, Proceedings of SIG-GRAPH 98, pages 9–20. ACM SIGGRAPH, 1998.

16. Igor Guskov, Kiril Vidimce, Wim Sweldens, andPeter Schrder. Normal meshes. In SIGGRAPH2000 Conference Proceedings, pages 95–102, 2000.

17. Lucas Kovar, Michael Gleicher, and FredericPighin. Motion graphs. In Proceedings of the 29thannual conference on Computer graphics and in-teractive techniques, pages 473–482, 2002.

18. Zicheng Liu, Steven J. Gortler, and Michael F.Cohen. Hierarchical spacetime control. In Com-puter Graphics: Proceedings of SIGGRAPH 94,pages 35–42, 1994.

19. J. Thomas Ngo and Joe Marks. Spacetime con-straints revisited. In Computer Graphics: Pro-ceedings of SIGGRAPH 93, pages 343–350, 1993.

20. Jovan Popovic, Steven Seitz, Michael Erdmann,Zoran Popovic, and Andrew Witkin. InteractiveManipulation of Rigid Body Simulations. In SIG-GRAPH 2000 Conference Proceedings. ACM SIG-GRAPH, July 2000. 209–218.

21. Craig W. Reynolds. Flocks, herds, and schools: Adistributed behavior model. In Computer Graph-ics: SIGGRAPH ’87 Conference Proceedings, vol-ume 21(4), pages 25–34. ACM SIGGRAPH, 1987.

22. Craig W. Reynolds. Steering behaviors for au-tonomous characters. In 1999 Game DevelopersConference, pages 763–782, 1999.

23. Diane Tang, J. Thomas Ngo, and Joe Marks. N-body spacetime constraints. The Journal of Vi-sualization and Computer Animation, 6:143–154,1995.

24. Marjolaine Tremblay and Hiromi Ono. Multiplecreatures choreograhy on Star Wars: Episode I“The Phantom Menace”. SIGGRAPH 99 Ani-mation Sketch. In Conference Abstracts and Ap-plications, page 205, August 1999.

25. Xiaoyuan Tu and Demetri Terzopoulos. Artifi-cial fishes: Physics, locomotion, perception, be-havior. In Computer Graphics: Proceedings ofSIGGRAPH 94, pages 43–50. ACM SIGGRAPH,1994.

26. Andrew Witkin and Michael Kass. Spacetimeconstraints. In Computer Graphics: Proceedingsof SIGGRAPH 88, pages 159–168, 1988. Atlanta,Georgia, August 1-5.

c© The Eurographics Association 2003.