Computer Animation Algorithms and Techniques Optimization & Constraints Add mention of global techiques Add mention of calculus of variations Rick Parent Computer Animation Enforcing Soft and Hard Constraints Soft constraints - Minimizing energy terms Hard constraints – constrained optimization Example: Space-time constraints Rick Parent Computer Animation Constrained optimization Use whenever the best, shortest, least error, is needed: Fit surface with least curvature to set of points Reach for object with minumu torque Find motion in database whose start pose is closest to end of current motion Rick Parent Computer Animation Minimum (or maximum) of a function f(x) Ballistic motion f’(x) = 0 1 2 f (t ) p0 v0t gt 2 f (t ) v0 gt 0 v0 t g Analytic derivative & solution Rick Parent Computer Animation Minimum (or maximum) of a function Multivariate case f x 1 f f ( x ) x2 0 f x3 ... Gradient / Jacobian Rick Parent Computer Animation Energy function Define energy terms in terms of geometric features =0 for desirable configuration increases for less desirable configurations Useful geometric features– easy to compute Parametric position function P(u,v) Surface normal function, N(u,v) Implicit function I(x) – distance to surface Search parameter space modify parameters to reduce energy Rick Parent Computer Animation Useful Constraints E P (u , v) Q 2 E P (ua , va ) P (ub , vb ) a b 2 2 E P (ua , va ) P (ub , vb ) N a (ua , va ) N b (ub , vb ) 1.0 a b E ( I b ( P a (ua , va ))) 2 Rick Parent Computer Animation Pipe assembly Rick Parent Computer Animation Finding the minimum minimize f (x ) Analytic derivative/gradient f (x ) Analytic solution f ( x ) 0 Rick Parent Numeric approximation to derivative/gradient f ( xi ) f ( xi 1 ) f x Numeric solution by iterative search Newton’s method Steepest Descent Conjugate Gradient Method Computer Animation Newton’s method f ( x ) 0 Rick Parent xi 1 f ' ( xi ) xi f ( xi ) Computer Animation Steepest descent – step in direction of negative of gradient Rick Parent Computer Animation Conjugate gradient method Rick Parent Computer Animation Constrained Optimization minimize f (x ) gi ( x ) 0 Equality constraints hi ( x ) 0 Inequality constraints Rick Parent Computer Animation Lagrange multipliers ( x, y , ) f ( x, y ) g ( x, y ) ( x, y, ) f ( x, y ) g ( x, y ) 0 xy ( x, y, ) xy f ( x, y ) xy g ( x, y ) 0 ( x, y, ) g ( x, y) 0 . Rick Parent Computer Animation Spacetime constraints http://www.cs.cmu.edu/~aw/pdf/spacetime.pdf Constrained optimization problem in time and space Constraints – e.g. locating certain points in time and space Non penetration constraints Objective function – e.g. Minimize the amount of force used over time interval Minimize maximum torque. Rick Parent Computer Animation Spacetime constraint example Particle position is function of time, x(t) Time-varying force function, f(t) Equation of motion mx(t ) f (t ) mg 0 Given f(t), x(t0), Rick Parent x (t0 ) - integrate to get x(t). Computer Animation Spacetime constraint example Need to determine f(t) x(t0) = a x(t1) = b Subject to constraints Objective: to minimize total force Objective function: 2 t1 R f dt t0 Rick Parent Computer Animation Spacetime constraint example Use discrete x(t), f(t), R, constraints Time derivatives approximated by finite differences xi xi 1 xi 1 2 xi xi 1 xi xi h h2 Constraints: xi 1 2 xi xi 1 pi m f i mg 0 2 h ca x1 a 0 cb xn b 0 R – minimize discrete version subject to constraints. 2 R h f i Rick Parent Computer Animation Spacetime constraint canonical form Numerical Solution – canonical form Sj – collection of scalar independent variables x, y, z components of the xi’s and fi’s R(Sj) – objective function to be minimized sum of forces squared used at each time step Ci (Sj) – collection of scalar constraint functions => 0. components of pi’s, ca, and cb . Rick Parent Computer Animation Spacetime constraint - canonical Numerical problem statement Find Sj that minimizes R(Sj) subject to Ci(Sj) = 0 Numerical solution method: - Request values of R and Ci for given Sj - Access to derivatives of R and Ci with respect to Sj - Iteratively provides updated values for solution vector Sj . Rick Parent Computer Animation Spacetime constraint Sequential Quadratic Programming (SQP) Computes second-order Newton-Raphson step in R Computes first-order Newton-Raphson step in the Ci’s Projects the first onto the null space of the second to the hyperplane for which all the Ci’s are constant to the first order. Rick Parent Computer Animation Spacetime constraint using SQP Sequential Quadratic Programming (SQP) Computes first-order Newton-Raphson step in the Ci’s Ci Jacobian: J ij S j Computes second-order Newton-Raphson step in R 2R H ij Hessian S i S j Plus the first derivative vector: Rick Parent R S j Computer Animation Spacetime constraint example xi 1 2 xi xi 1 pi m f i mg 0 2 h Matrices p i 2m / h 2 x j m / h 2 0 pi 1 f j 0 Rick Parent i=j i=j-1, j+1 otherwise i=j Otherwise. Computer Animation Spacetime constraint example Matrices R 2 fi f i 2R 2 f i f j 0 Rick Parent i=j Otherwise. Computer Animation Spacetime constraint example SQP step Solve 2 linear systems in sequence 1 R H ij Sˆ j S i j Yields a step that minimizes a 2nd order approx. to R ~ ˆ 2 Ci J ij (S j S j ) j Yields a step that drives linear approx. to Ci’s to zero And projects optimization step Sj to null space of constraint Jacobian. Rick Parent Computer Animation Spacetime constraint example Final update: ~ ˆ Sj Sj Reaches fixed point: - When Ci’s = 0 - Any further decrease in R violates constraints. Rick Parent Computer Animation Constrained optimization Rick Parent Computer Animation Spacetime constraint example Note about Linear system solving Large matrices often with spacetime problems Inverting is O(n3) Spacetime problems almost always sparse Over and under constrainted systems easily arise Under constrained: pseudo-inverse Pseudo-inverse for sparse matrix sparse conjugate gradient algorithm: O(n2). Rick Parent Computer Animation
© Copyright 2025 Paperzz