~ , Volume 21, Number 4, July 1987 ]

Energy Constraints On Parameterized Models

Andrew Witkin~ Kurt Fleischer~ Alan Barr~t ~Schlumberger Palo Alto Research, 3340 Hillview Avenue, Palo Alto, CA 94304 :~California Institute of Technology, Pasadena, CA 91125

Abstract of constraints the properties the model is supposed to have, without the need to manually adjust parameters to give it A simple but general approach to imposing and solving those properties. geometric constraints on parameterized models is intro- In this paper we present a simple but general ap- duced, applicable to animation as well as model construc- proach to expressing and solving constraints on param- tion. Constraints are expressed as energy functions, and eterized model hierarchies. We formulate constraints as the energy gradient followed through the model's parame- "energy" functions on the model's parameter space, non- ter space. Intuitively, energy constraints behave like forces negative functions with zeroes at points satisfying the con- that pull and parametrically deform the parts of the model straints. We then sum the constraints' energy functions to into place. A wide variety of geonmtric constraints are create a single scalar function of the parameters, and move amenable to this formulation, and may be used to influ- through parameter space to minimize the energy. ence arbitrary model parameters. A catalogue of basic We refer to the constraint functions as energy func- constraints is presented, and results are shown. tions not because they always model the energy of ac- tual physical systems, but because they play a role similar Keywords -- Constraints, Modeling, Animation to that of physical energy fimctions during the constraint solving process. For example, an energy constraint attach- I. Introduction ing points on the surfaces of two objects acts much like a A widely-used approach to modeling is to combine geo- spring that pulls the objects together. However, in addi- metric primitives--such as cylinders, blocks, and bicubic tion to translating and rotating, the objects are free to vary patches--with a variety of operators--such as translations, their internal parameters, so, for example, a cylinder may rotations, booleans, and deformatlons--to form a model vary its length or radius to meet the constraint. Although hierarchy. The task of constructing a model within this no fanfiliar physical material deforms in this stylized way framework has two parts: building the hierarchy, and set- in response to applied forces, it is easy enough to imag- ting the internal parameters of the prinfitives and opera- ine an unphysic&l material that does. Since we are using tors. Experience tells us that the second task is usually the energy analogy as a mechanism for building models, by far the more diflqcult and time-consuming, particularly rather than for sinm|ating physical phenomena, this kind when complex operators such as deformations are used. As of non-physical behavior poses no problem. the complexity of the model increases, the number of pa- Our approach provides: rameters becomes large, and they tend to interact in ways • Self.assembling models, whose parts move and deform that make the model difficult to control. parametrically from an ilfitial configuration to one The user knows at the outset what the objects be- that satisfies the specified constraints. ing modeled are supposed to look like--how the pieces are supposed to fit together and move. The difficulty lies in • Animated models that, once assembled, may move in response to time-varying constraints while continuing finding settings of the parameters that achieve the desired effect. The utihty of hierarchic modefing systems would to satisfy static ones. be greatly enhanced if this tedious process could be per- • Oenerality and modularity: we can formulate a wide formed automatically, permitting the user to state in terms range of constraints as energy functions, and use them to influence arbitrary model parameters. To imple- Permission to copy without fee all or part of this material is granted ment a new constraint we need not know the details of provided that the copies are not made or distributed for direct other constraints, nor of the primitives and operators commercial advantage, the ACM copyright notice and the title of the to wtfich they will be applied. Sinfilarly, new parame- publication and its date appear, and notice is given that copying is by terized prinfitives and operators may be implemented permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission. without modifying existing constraints. • Additivity: Energy fimctions compose by addition. The solution to a system of constraints is the so-

© 1987 ACM-O-89791-227-6/87 /O07/0225 $00.75

225 ~'~~ SIGGRAPH '87, Anaheim, July 27-31, 1987

lution to a single equation, the sum of the energy condition we must satisfy is Pl = P2- A solution is a value terms. This property is particularly valuable in deal- of ~ such that all the imposed conditions are met. ing with overdetermined systems. While conventional Rather than solving the constraint equations alge- algebraic methods return no solution to an overdeter- braically, we formulate constraints as energy fimctions, and nfined system, the energy minimum is a "compronaise" move through parameter space according to the energy that is sometimes acceptable, nearly always informa- gradient. In general, to formulate an energy constraint, tive, and often easily repaired. we must construct a non-negative smooth function E('I') such that E((P) = 0 at all and olrly values of 'I' for which • Interactive control: since we satisfy constraints by the constraint is satisfied. The solutions to a set of n con- moving ttlrough a curve in parameter space, the initial straints are values of • such that constraint solving process can itself be animated, per- nfitting the user to assist the solver in escaping local it energy minima, resolving ambiguities, etc. E(~) y~ E,(~) o, i A significant body of work in constraint-based and dy- uanlics modeling for colnputer graphics is concerned with so to combine constraints, the corresponding energy terms the the specialized problem of animating articulated bod- are simply summed. We are free to express E in terms of ies, particularly hmnan and animal forms. These include position, normal, or implicit functions, or any other quan- Armstrong and Green, [1], Girard and Maciejewski, [6], tities that may be extracted from the model tree. and Wilhehns and Barksy [13]. Nelson's Juno editor em- Intuitively, energy constraints may be viewed as ploys non-linear geometric constraints in the context of a "forces" ttlat pull the parts of the model into the desired 2-D image editor. Dynanffc models of elastic bodies for configuration and hold them there, although they are not computer graphics are treated by Terzopoulos et al. in necessarily intended to be physically realistic forces. For [12]. Closest to ours in approach are Barzel and Barr's dy- instance, a simple attachment constraint nffght be imple- nauric constraints [3], although their current work focuses mented as a spring connecting the points, in which case we on constraining ttle motion of rigid bodies. have E.,,,.;,~,, = ,~ IP~(u~,v~) - ~(~2,w_)l-", II. Energy constraints where ~ is a spring constant, and the "force" vector in parameter space is ~TE.p,.i,,j. A model hierarchy is a tree that defines the model's geom- From an initial condition @0, the energy E is mini- etry through a collection of mathematical functions, three mized by numerically solving the differential equation of wlffch will concern us here. These are a parametric posi- tion function, la(u, v) that returns a 3-space point for each dF(t)/dt- rE, F(0) = ~0, (u,v) pair, a surface normalfunction, N(u,v), that returns a surface normal vector, and an irttplicit or inside-outside for a fixed point of the parameter-space curve F(t), i.e. a point at wtffch VE = 0. The solution is a local mini- function, I(X), that returns a scalar given a 3-space point, mum, Mthough it is not guaranteed to be a zero. Tiffs is such that I = 0 for points on the object's surface, I < 0 for a steepest descent method for solving ~TE - 0. points inside the object, and 1 > 0 for points outside the A variety of standard numerical methods may be used object. One such collection of functions is defined for each to solve the energy equation. The simplest of these, Euler's leaf iu the tree, and represents tile combined effects of the method, has prinfitive at the leaf and of all the operators on the path F(~;~I) - F(t) + h~TE, from that leaf to the root. Defiuitions of these functions are given in Appendix A. with h the step size. More sophisticated methods, such In generM, each primitive or operator possesses some as Gear's method [5] should be used to obtain accurate, real-valued paraineters, for instance the radius of a sphere, reliable results. Any solution method requires evaluation a translation vector, or the bend angle of a parameterized of ~TE. To do so, the suunned energy must be differenti- deformation. The position, normal and implicit functions ated with respect to each model parameter, which may be each depend on these parameters: when they change, ob- done numerically by varying each parameter in turn, re- jects' surfaces move. We refer to the union of all these evaluating E, and taking differences. The structure of the parameters as ~I'. Once the hierarchic structure is fixed, tree may be used to avoid the needless expense of differen- the state of the model is completely determined by the tiating energy terms with respect to parameters on which v.-fiue of ~I'. The notion of parameter spaces, and of mo- they do not depend. tion along curves through parameter space, is fanffliar in A limitation of the method is that it may be trapped computer graphics in the context of keyframe interpolation at spurious (i.e. non-zero) local minima of E. Our solution (see, e.g. [111.) to this problem is user interaction. Such minima are usu- We will express geometric constraints in terms of the ally easy to interpret geometrically, e.g. a single part has functions P, N, and I. For instance, if we wish to attach become stuck or been turned backwards. Presented with two surface points P~(ui,v~) and P2(u2,v2), at least one a bad answer, the user can often correct the situation by

226 (~ ~)' Computer Graphics, Volume 21, Number 4, July 1987

manually repositioning a part. In fact, with fast enough attachment, in which both points float on their re- rendering to view the evolving solution dynamically, the spective surfaces. user can literally push or pull on parts of the model with • Slider constraint: Constrain a specified point on a pointing device, introducing a time-varying energy term, an object to a line in space: E~ .... into the equation, to bump it out of local minima. This style of user interaction has been used to good effect E = PLD(Pa(u,,,v,,),P1,P.,) 2, in interactive image interpretation [7]. A different form of user control is obtained by selectively freezing and un- where PLD is the polnt-to-llne distance function, and freezing model parameters, to decompose a larg~ problem P1 and P2 are points on the line. Useful variations into a sequence of smaller ones. constrain the point to a line segment, or constrain two line segments to be colinear and to overlap (like seg- III. A catalogue of useful ments of a telescope.) constraints • Collision using the implicit function: For ob- jects possessing inside-outside functions, interference A wide range of geometric constraints may be cast in the or collision constraints may be imposed without cal- form of energy functions. Here we list a few basic con- culating surface intersections. The implicit function is straints, most of which are used in the examples to follow. zero everywhere on the object's surface, and, by our Many are subject to alternative formulations. Each energy convention, negative inside and positive outside the function is multiplied by a weighting factor; these factors object. To impose an anti-interference constraint, we are not shown below. transform the implicit function into a thin repulsive • Attachment to a fixed point in space: The "force field" surrounding the object. At a single point, energy term P'~(u,,,v,,) on object a, a suitable energy function is

E = IP"(u~,v,~) - ql 2 .~ = c--~ib(P'(u.,va))

attaches a specific point on the surface of object a, where ~ is a positive scale factor. This makes the defined by parameter point (u,, v,~), to a specific point energy high inside object b, tending to zero far from in space, Q. object b. Thus a point inside the object is repelled, the repulsion approaching zero off the object's surface. • Surface-to-surface attachment: Place specified points on two surfaces in contact. To acheive contact, To implement a general interference constraint, this the points must coincide. In addition, their tangent function must be integrated over u and v. An efficient planes at those points must coincide, and the surfaces implementation must make use of intelligent sampling, should not (locally) interpenetrate. These conditions hierarchic bounding boxes, etc., which are beyond the can be encoded by scope of this paper. • Direct constraints on parameters: It is some- E = IP"(u,~,v,,)- Pb(u~,v~)[ 2 + times useful to impose constraints directly on model N"(u~,v,). Nb(ub,vb) + 1, parameters, for instance to establish default values, or to constrain relations among parameters. If a is where pa and pb are the positions at the two attach- some model parameter, then a defaulting constraint ment points, and N" and N b are the unit surface nor- m~ty be written as E = (or - a0) 2, where a0 is the' reals at those points. This function is zero when the default value. If a and/3 are two model parameters, points coincide and the dot product of the normals is then a linear relational constraint may be written as --]., E = (a - kl/3 - k,_)2, which says that the linear rela- • Floating attachment: Attach a specified point tion a = klfl + k2 should hold between a and/3. For on an object to some point on a second object, allow- instance, if we want one rod to be twice as long as ing the point of contact to slide freely on the second another, we have E = (l] - 212) ~', where 11 and 12 are object. Our implementation of this constraint is sim- the lengths of the rods. ilar to that for simple surface-to-surface attachment, but uses the second object's implicit function instead IV. Examples of its parametric position function: This section presents three examples of the use of energy E = Ib(P"(u,,,v,,)) ~" + constraints to build and animate models. The first, a rela- tively simple one, is described in detail as a concrete illus- VI ~ tration of the method. The second and third are described N"(u,,,v,,). lWib I + 1, more briefly. noting that KrIt'/]VII is a unit normal to surface b Pipefitting: A simple example illustrating self- where I b = 0. A useful variation is double floating assembly and adjustment of a variety of model parameters

227 ~ SIGGRAPH '87, Anaheim, July 27-31, 1987 la~®~e~l

is shown in figure 1. A cylindrical pipe, subjected to a and TTans(Rot(Bcnd(P2))), respectively, so their posi- translation, a rotation, and a parameterized bend is to be tions in model space depend on all the model parame- fitted to other pipes at either end. All other parts of the ters except radius and thickness. Using the fact that sur- model have already been assembled, and their parameters face normals transform under deformations by multiplica- frozen. tion with the inverse transpose of the deformation's ja- The model hierarchy for the adjustable tube is de- cobian ([2]), the transformed normals are Rot(J[~,tN, ) scribed schematically by Trans(Rot(Bend(Tube))): and ttot(j~!TtN,),,.,,. where d -tTn,.~,,,,l is the inverse transpose of the bend operator's jacobian, evaluated at P1 and P~. • A tube is a primitive, whose axis is coincides with respectively (see [2] for the formula.) the x-axis in model space, and whose dimensions are To solve the constraints, we solve the equation controlled by three parameters --length, radius, and ,~@(t) = VE from a starting point @(t0), until we reach a thickness. point at which VE < ~, where e is a small tolerance value. • A bend (after [2]) is a parameterized deformation that At any point • in parameter space, we can evaluate P1, maps the ~-axis into a circular arc in the x, z plane. Pz, N1, and N2, and hence the energy function defined Its effect on shape is controlled by three parameters-- in terms of them. To compute VE munerically, we first start, stop, and amount. Start and stop determine evaluate E at the current ~, then add a small A to each the "tightness" of the bend, and amount is the angle parameter (i.e. each component of ~) in turn, re-evaluate between the ends of the curved axis. E and subtract the central value of E, obtaining the cor- responding component of VE. Using Euler's method the • A quaternion rotation is specified by a 4-vector. Al- though any rotation may be specified by three Euler new value of ~ is given by ~'t+a = q2, + hVE, where h is angles, we use quaternions to avoid gimb~ lock. a step size. Figure 1 shows the model at the initial condition, at • A translation is specified by a 3-vector of x, y, and z several steps toward the solution, and at the solution. Fi- displacements. nally, we show a new solution obtained when one of the The union of these parameters, ~, is a 13-dimensional fixed pipes is moved. vector. Motion along a curve through q'-space corresponds Oldham linkage: An oldham finkage is used to trans- to some combination of bending, translating, rotating, and fer rotation between shafts that are offset in a plane per- changing the tube's dimensions. Despite the simplicity of pendicular to their axes, by means of a system of tongues the example, this means that we have to come up with 13 and grooves. Figure 2 shows several frames from the independent numbers to pin down the model in the desired self-assembly sequence for an oldham linkage, and several configuration. Doing this manually, or writing a special frames from an animation sequence. The specification of purpose program to do it, would have been unpleasant. this mechanism involved a variety of constraints, including For our purposes, two pipes are attached if their axes sliders, surface-to-surface contact, and position and ori- join smoothly and they have the same radius and thickness. entation constraints. This example illustrates the use of An "attach-pipes" (AP) energy constraint may be built by energy constraints both for assembly and for animation of combining a surface-to-surface attachment constraint, as the assembled model. defined in the previous section, with relational constraints Cam and rocker arm: This example (figure 3) shows that make the radii and thicknesses agree. Let P1 and Pz an already-assembled cam and rocker arm at several points be the endpoints of the two pipes' axes, i.e. the points to be in its cycle. This is a working model: the pressure of the joined, and let Nt and N_~ be two unit vectors extending spring on the valve head pushes the follower against the outward from the axis endpoints in a direction tangent cam via the fulcrum. The follower "feels" the cam using to the axes. Then we want P1 = P~_ and N, .N~ = 0. an implicit-function interference constraint, so that if the Additionally, we want el = v2 and tl - t2 for the radii cam were reshaped, the motion of the arm would change and thicknesses. In energy form, this gives us accordingly. EAp = ]Pl -- P.~l"~ + Na • Nz + 1 + (r~ - re) 2 + (ta - 1_,)-9. V. Conclusion To attach both ends of the moving pipe, we have as the total energy the sum of two terms of this form. Energy constraints were shown to provide an effective Prior to bending, rotation, and translation, the end- means of building and controlling parameterized models. points of the moving tube's axis are situated at the points A principle advantage of the energy method is its gener- Pa = (length/2,0,O), and P9 = (-length/2,0, O), with ality: it does not depend on the details of the constraints unit normals N~ = (1,0,0) and N2 = (-1,0,0) point- used or the models to which they are applied. It is tolerant ing outward from the ends. The two fixed pipes to of over- and under-determined systems, and amenable to which the moving one is to be attached each have a sinfi- user interaction. Among its disadvantages, it can be nu- larly defined endpoint and normal, which are constants. merically intensive--particularly when the equations be- The transformed endpoints are Trans(Rot(Bend(P,))) come stiff--and it can be trapped in local minima. The

228 (~ ~ Computer Graphics, Volume 21, Number 4, July 1987

second difficulty is largely overcome by effective user in- References teraction. [1] William W. Armstrong and Mark W. Green, The dy- namics of articulated rigid bodies .for purposes of an- Appendix A imation, in Visual Computer, Springer-Verlag, 1985, In this appendix we define the position, normal and im- pp. 231-240. plicit fnnctions in terms of the structure of the model tree. [2] Alan H. Barr, Global and Local Deformations of Solid Our definition describes the SPAR modeling testbed [4], Primitives, Proe. SIGGRAPH, 1984, pp. 21-29, but is typical of hierarchic modelers in most relevant re- [3] Ronen Barzel and Alan It. Barr, Dynamic Con- spects. Each leaf in the tree represents a primitive. The straints, to appear. root is a camera, and the intermediate nodes represent op- [4] Kurt Fleischer and Andrew Witkin, The SPAR mod- erators. We denote the leaves by L i, and the n nodes on the eling testbed, to appear. ascending path from leaf L i to the camera as 0 Lj, where [5] William C. Gear, Numerical Initial Value Problems 0 i'l is L i, 0 i'~- is the first operator above L i, and Oi,n Prentice-ttall, En- is the camera. (When we refer to the objects comprising in Ordinary Differential Equations, glewood Cliffs, N J, 1971 the tree without regard to the paths they lie on, we index them as 0;.) For the purpose of sampling and rendering, [6] Michael Girard and Anthony a Maciejewski, Corn- each such path defines a distinct object, characterized by putataional Modeling for the Computer Animation of a coordinated bundle of mathematical functions. These Legged Figures, Proc. SIGGRAPH, 1985, pp. 263 include: 270 [7] , Andrew Witkin, and Demetri Ter- • A parametric position fnnction, P;(u,v), ~-~ ~ ~3 zopoulos, Proc. In- defined recursively by Snakes: Active Contour Models, ternational Conference on Computer Vision, 1987. Pi(tL, v) = pi"'(u,v), [8] V. C. Lin, D. C. Gossard, and R. A. Light, Vari- Pi'J(u,v) = Ti'J(Pi'J-a(u,v)),j # l, ational Geometry in Computer-Aided Design, Proc. S[GGRAPH, 1981, pp. 171-178 pi'l(u,v) = pL'(u,v), [9] Greg Nelson, Juno, a constrait~t-based graphics ~y~tent where T i'5, ~.3 ~ ~3 is associated with operator 0 i'j, Computer Graplffcs, Vol. 19 No. 3, July 1985, pp. 235- defining the transformation it performs, and pL' is 243. the prinfitive position function associated with L ~. By [10] Thomas W. Sederberg and Scott R. Parry, Free-Form convention, the domain of P is the unit square 0 < u < Deformation of Solid Geometric Models, Proc. SIG- 1, 0 < v < 1. In words, the primitive L* generates 3- GRAPH, 1986, pp. 151-160. space positions on the object's surface as a function of [11] Scott N. Steketee and Norman I. Badler, Parametric u and v, and each operator transforms those positions. Keyfvame Interpolation Incorporating Kinetic Adjust- • A parametric normal function, Ni(u,v), similar to ment and Phrasing Control, Proc. SIGGRAPII, 1985, the position function but generating surface normals. pp. 255-262. Tiffs is defined by [12] , John Platt, Alan Barr, and Kurt Fleischer, Elastically Deformable Models, Proc. N'(~,v) = N~"~(~,v), SICGRAPH, 1987. Ni'J(u,v) = Ni'J-I(u,v)J-1T(Ti'j),j # 1, [131 Jane Wilhehns and Brian Barsky, Using Dynamic oPLI(u,v) oPL'(u,v) Analysis To Animate Articulated Bodies Such As Hu- NZA(U,V) -- × Ou Ov ' mans and Robots, Graphics Interface, 1985. where 3 -IT is the inverse transpose of the Jacobian Acknowledgements nmtrix [2]. All images were rendered by Kurt Fleischer using his modeling testbed system (M-BLORB) on a Symbolics • An implicit (inside-outside) function, I~(X), ~3 LISP Machine. Michael Kass helped design some of the ~, such that the solution to Is(X) = 0 is the same constraints, and provided helpful comments on early veri- surface defined by pi. The implicit function is defined recursively by ons of tiffs paper. We thank Demetri Terzopoulos, Jotm Platt, and Michael Kass for valuable discussions and goop. ~(x) = I~"(x), Ii'/(X) = I i'j 1((Ti'J)-I(X),j # 1, /i'l(x ) ~- /'L' (X),

where T -1 is the inverse of T, and I/; is the pritfiitive implicit function associated with L i.

229 ~ SIGGRAPH '87, Anaheim, July 27-31, 1987

Figure 1: Pipefitting. A pipe subjected to a p,'trametric bend is irttached to other pipes at either end using surf~rce- to-surface attachments. Starting with the upper left we see the ilritial contiguration, three steps in tile assembly process, and the final solution. At the lower right is shown a new solution obtained by tnovit~g one of the fixed pipes.

230 (~) ~ Computer Graphics, Volume 21, Number 4, July 1987

Figure 2: An Oldham's linkage being assembled and moved using a variety of energy constraints including sliders. The system of tongues and grooves serves to transfer rotation through the floating disc while allowing translations of either shaft in the plane of the disc.

231 ~ SIGGRAPH'87, Anaheim,July 27-31, 1987

Figure 3: A working model of a cam and rocker arm, specified using energy constraints, shown at several points in its cycle. The spring creates a torque around the fulcrunl, pushing the follower against the cam. The follower "feels" the cam using all implicil,-function interference constraint.

232