4  Contact Simulation

When simulating any kinds of physical systems in graphics we often have to deal with contact. Contact is the interaction between two objects that are in close proximity. The forces between these objects are called contact forces and they are there to prevent the objects from interpenetrating. There are 3 rough types of contact simulations: 1. constraint based methods, 2. penalty based methods, and 3. impulse based methods. We will focus on the first two.

4.1 Basics of Contact Simulation

Newton-Euler equations of motions that govern dynamics of physical systems as a 2nd order ODE is written as:

M(t)u˙(t)=f(q(t),u(t),t),

where M(t) is the mass matrix over time, u(t) is the velocity of the system, q(t) is the generalized position of the system, and f is the external forces acting on the system. The contact forces are a subset of these external forces. We can abbreviate the above equation as:

Mu˙=f,

and we evaluate it using numerical integrators that take discrete steps in time. In this section we denote explicit quantities with superscript and implicit quantities with +. In the implict setting the 1st order Taylor approximation gives:

u+u+hu˙, which when placed into the Newton-Euler equation gives gives the following Euler update:

Mu+=Mu+hf.

Here Mu can be seen as the momentum term and u+ is the velocity determined at the end of the timestep. The form of M will depend on the type of representation we use for our body.

Now we can similiarly update the generalized positions:

q+=q+hHu+,

where H is the kinematic matrix that maps velocities to positions.

Since most contant models are based on Coulomb model, we get limited performance boost from higher order methods, so we just we assume planar surface at the contact points.

4.1.1 Basics of Constraints

To restrict movement of bodies to some desired state we introduce kinematic constraints, specifically with m constraints functions we define the desired state as a manifold ϕ(q)Rm embeeded in Rn.

Assuming constraints are initially satisfied, we can formulate constraints in terms of how fast they change with respect to q:

J=ϕqRm×n. We call J the constraint Jacobian / gradient. It encodes the direction in which bodies may be pushed or pulled without exerting any forces on the system while staying on the manifold. With this the bilateral and unilateral constraints can be written as:

Ju˙=0, and Ju˙0, respectively. More generally the constraint forces are written as:

fc=JTλ,

where λ is the vector of Lagrange multipliers. The multipliers relate to the magnitudes of fc when the gradients / directions are normalized. So J tells the force direction and λ tells the magnitude. The constraint forces can be thought of as the forces that keep the system on the manifold.

To actually enforce that our system stays on the manifold we need to add the constraint forces to the external forces acting on the system in the form of an impulse:

Mu+=Mu+hf+hJTλ+, where the constraint forces are evaluated explicity. If we just consider bilateral constraint and write this as a linear system, then we can use Shur complement to reduce the system:

JM1JJ(hλ+)+JM1(Mu+hf)=0

which is a linear system of the form Ahλ++b=0.

4.1.1.1 Non-interpenetration Contact

Unilateral constraints are only active when the bodies are in contact. We model the distnace between two bodies with a gap function ϕ—i.e. a constraint function that ϕ=0 when the bodies are in contact, ϕ>0 when bodes are separated, and ϕ<0 when bodies are interpenetrating.

If we make the gross assumption that surfaces are smooth, then we can imagine a plane at the contact point and its normal vectors is parallel to surface normal. If the bodies are in contact, then an impulse λn^ is applied at the contact location in the direction of n^ (i.e. perpendicular to the contact plane).

As such we have 2 cases:

  1. No contact, No force. ϕ>0 and λn^=0.

  2. Contact, Force applied. ϕ0 and λn^>0.

Since they are independent we can write them as one “position level non-penetration complementary condition”:

ϕ0λn^0.

Since the contact is only when ϕ=0 we can again think about it in terms of velocities of bodies. In the implict setting, if bodies A,B are in contact at time t, then if ϕ˙>0—that is the normal component of relative velocity is positive—they will not be in contact at time t+h (note ϕ+ϕ+hϕ˙=hϕ˙), so λn^=0. If ϕ˙0—that is they have negative or 0 relative velocity—then they will be in contact at time t+h, so λn^>0. Combined we have the condition:

ϕ˙0λn^0.

We replace ϕ˙=vn^, since it is the relative velocity of the contact points in the normal direction. If we want to anticipate the collision and avoid tunneling effects we can replace ϕ˙ with ϕ+hvn^.

Non-interpretation Jacobian. The question now is how do we compute ϕ˙? We can use the chain rule to get:

ϕ˙=ϕqq˙=Jq˙=JH˙u=Ju,

where J body-space Jacobian of the gap function.

How do we construct J? Let’s consider collision of two bodies A,B at contact point p and centes of mass mA,mB respectively. Defining n^ to point AB, then by taking rA=pxA and rB=pxB we can write: vn^=n^δv vn^=n^((vB+ωB×rB)(vA+ωA×rA)),

where vA,vB are linear velocities of A,B and ωA,ωB are angular velocities of A,B respectively. Finally we see how to compute J:

vn^=[n^n^rA×n^n^rB×][vAωAvBωB]=Ju.

To extend J to multiple contacts, we would just place a new row for each contact point.

Soft-Bodies Non-interpenetration Constraints. This is very similar to the rigid body case we were considering. We usually use a mesh with nodes to represent a deforamble model.

Considering colliding tetrahedral elements of a mesh between A,B we can formulate the contact point using Barycentric coordinates:

p=wixi,B+wjxj,B+wkxk,B+wmxm,B=xl,A.

The relative contact point velocity in the normal direction is then:

vn^=n^(i=14wi,Bvi,Bi=14wi,Avi,A)

vn^=[n^win^wjn^wkn^wmn^][vl,Avi,Bvj,Bvk,Bvm,B]=Ju.

4.1.2 Coulumnb Friction Model

So far we assume that tangential movement between contacts was allowed and not opposed. In graphics we often want to simulate friction as well. We can model friction as a force that opposes the relative tangential velocity of the contact points. We can model this as a force that is proportional to the normal force and the relative tangential velocity.

To describe this friction we think about a local contact frame for each contact point. The local frame is defined by the normal vector n^ and two tangent vectors t^,b^ that are orthogonal to n^ and each other; b^,t^ define the shared contact plane between the smooth surfaces.

n^ can be defined from ϕ. Since we are discussing this in the local frame, we need to have relative velocity of the two surfaces

v=[n^,t^,b^,]Δv,

where Δv is the world-space relative velocity. We rewrite the context frame basis with C=[n^,t^,b^]. Now recalling the equation for the relative world velocity we can write:

v=C[I3×3,rA×I3×3,rB×][vAωAvBωB]=Ju,

so Jf=C[I3×3,rA×I3×3,rB×].

To refelct we recall that in the non-friction case we actually had J=n^[I3×3,rA×I3×3,rB×] so we indeed got the friction Jacobian by just changing the normal vector to the contact frame basis!

We defined how we can compute the contact frame relative velocity, but to determine the impulses that separate objects and the friction forces between the objects, we need to separate v into normal vn^ and tangential vt^ components.

Theory of Friction. Since Column force couples the normal and tangential impulses, we restrict the tangential friction with a cone constraint. The cone constraint is defined by the friction coefficient μ and the normal force λn^R:

λt^μλn^,

where λt^R2. Each μλn^ corresponds to some slice of the cone and that slice tells us all the possible tangential forces that can be applied given the normal force. The equation is quadratic so the cone is a quadratic cone.

We separate friction into 2 types: 1. slipping and 2. sticking. If the relative tangential velocity is less than the threshold, then the contact is sticking and the tangential friction force can have any direction. If the relative tangential velocity is greater than the threshold, then the contact is slipping and the tangential friction force is is opposing the movement and has magnitude μλn^. We can write this as:

μλn^λt^0, vt^(μλn^λt^)=0, vt^λt^=vt^λt^.

The first condition is always active and tells us that the tangental impulse has to be in the quadratic cone. If vt^>0 then the other two conditions activate: first tells us that μλn^=λt^, i.e. the impulse must be maximized in the cone, the last condition says that the tangential friction impulse should oppose the relative tangential velocity. We call this a (non-linear) complementary problem.

To give more intuition on these conditions, we can think about the friciton force as maximally decreasing energy of a system. If we define F to be the set of possible friction forces, then the principle of maximum dissipiation gives:

λt^=argminfFvt^f. Following this setup we can arrive to the variational inequality (VI) and you can read more about it in [the notes].

4.1.2.1 LCP - Linear Complementary Problem

We saw that our friction model is non-linear and can be hard to solve efficiently. We can linearize the problem by creating a linear approximation of our friction cone. We call it a polyhedral cone and it is given by the span of k+1 unit vectors {n^,t^1,,t^k}. Each tangent vector has a twin in the opposite direction, so we can write all friction forces with non-negative coefficients. This allows us to re-write the quadratic constraint above as:

0μλn^iλt^i.

To form the stick-slip conditions we only need to know whether we are slipping or not. For this we can measure the maximum slipping velocity along all of the tangential directions. Then for β0:

0βe+vt^

where e is the vector of all ones and vt^ is the relative tangential velocity along all directions. β is the maximum slipping velocity and can be 0 iff vt^=0, i.e. we are sticking. Otherwise β=maxvvt^v. We also sometimes call β the slack variable.

Again by principle of maximum dissipation we know that:

β>0iλt^i=μλn^. To get the right direction of the friction force we let βe=vt^. Finally this gives a complete linear model for 1 contact point:

0<vn^λn0

0βe+vt^andλt^0

0μλn^iλt^iβ0.

p contact points. To generalize our system to multiple contact points we need to assemble a global Jacobian containing non-penetration and tangential friction constraints for all p contact points. For the non-penetration conditions each contact point we have a separate row:

Jn^,i=[n^in^iri,A×n^in^iri,B×], Jn^=[Jn^,1Jn^,p].

For the friction Jacobian (tangential friction) we have a similar setup for all tangential directions:

Jt^=[Jt^,1,,Jt^,p], Jt^,i=[t^it^iri,A×t^it^iri,B×]

where Jt^,i is the Jacobian for the i-th contact point. The global Jacobian is then: [MJn^TJt^T0Jn^000Jt^00E0μ¯ET0][u+λn^+λt^+β]+[Muhf000]=[0snsβsλ]

subject to: 0snλn^+0 0sβλt^+0 0sλβ0

With rearamnging we can get the LCP form:

Ax+b0x0.

After all this gargol we see that it really boils down to a nice and simple linear system!

4.1.2.2 Boxed LCP

Another way to discretize the friction cone is by using only 2 orthogonal tangent directions and have them limited:

μλn^λt^iμλn^ for i{1,2}.

Note that to solve these discretizations we need more general algorithms than LCP solvers. One nice benefit we get from writing our system this way is that we can run away from the whole mess of having different constraints for friction and non-penetration and just use the same algebraic expression (with different bounds) for both! Concretely, we can write:

vi>0λi=μλn^ vi=0λi[μλn^,μλn^] vi<0λi=μλn^

We can further decompose the residual velocity as vi=vi,+vi, and write BLCP as 3 separate LCPs:

0vi,+λi+μλn^0 0vi,λiμλn^0 0vi,vi,+0.

To assmble the global Jacobian we recall the Jacobian for a single contact as:

Ji=C[I3×3,rA×I3×3,rB×]

where we now replace C with [n^,t^1,t^2]. Then the global Jacobian becomes: J=[J1,,Jp] and the global BLCP for the constrainted equations of motion becomes:

[MJTJ0]A[u+λ+]+[Muhf0]b=[0v],

0+vλ+λlo0, 0vλhiλ+0, 0v+v0

where λ=[λn^1,λt^1,1,λt^1,2,]. We could again use Shur complement to reduce the system to a smaller one and you can see that in [the notes].

Numerical stabilization. Add springs, because we have numerical drift in linear approximation.

4.1.2.3 Deformable Contact

While most of the friction contact formulations above were derived from a rigid-body setting, we can extend them to deformable bodies too. The main differneces are that there are more variables and we use implicit discretization approaches in deformable objects.

If we first consider the kth contact between 2 rigid bodies, we can write the relative contact point velocity as:

[vn^kvi^kvb^kvr^k]=[CkT(rki×Ck)TCkT(rkj×Ck)T0Tn^kT0Tn^kT][viωivjωj].

Most often we pick t^k to be the direction of sliding and b^k to be orthogonal to n^k,t^k. We can combine all K contacts and N bodes into one big system of the familiar form:

v=Ju. Finally we write the block M matrix, the external forces f, and the generalized coordinates qi=[xiQi]. Since we incorporate quaternions we have to change q˙=u using a kinematic matrix H (refer to the notes for the exact form). Then q+=q+hHu+ and Mu+=Mu+hf, as we have seen before.

To change this to a deformable body we need to add elastic forces. Recall that applying FEM on a deformable body results in a second order differential equation:

Mq¨+Bq˙+Ku=f+Jλ

where q is all the nodes in the mesh, K is the stiffnes matrix, B is the damping matrix, and Jλ is the contact forces. Observe that we do not have any quaternions or angualr spin present anymore. Using Euler integration and finite differences we get:

u˙+u+hu˙

where u+=ut+h,u=ut. Integrating genearlized poisitions we get:

q+=q+hu+. Note: no H, because we are not dealing with quaternion rotations anymore. Now we can write a velocity level dynamic equation for this system:

M(u+uh)+K(q+q0)+Bu+=f+Jλ or equivalently in the impulse form:

Mu++hBu++h2Ku+=Mu+hfhKq++hKq0+Jhλ, Au+=b+Jhλ.

Here A is sparse, block-symmetric, and positive definite. That’s every numerical analysit wet dream. We can now easily solve the system using Conjugate Gradients or any other iterative solver to get u+, then q+, and repeat.

Note: Deformable objects make numerics easier compared to rigid bodies.

4.2 Contact Generation

We talked about how to simulate contact, but we did not talk about how to generate it, based on the representation of the objects. We will focus on the most common representation: tetrahedral meshes. First we define some terms: the contact position / point will be denoted as p w.r.t points pA,pB on the surfaces of objects A,B. At the exact time of contact they obey p=pA=pB, but since we are doing discreitzation in time, this is not guaranteed to happen. That said, we will still apply forces at pA,pB. We will define for simplicty the contact normal n^ to be the normal of the surface at pA. Again, note that nA^ might not be equal to nB^ if the surfaces are non-smooth. We also introduce a measure of penetration ϕ (same convention as the gap function); it tells how much we have to move along n^ to get to p=pA=pB.

When dealing with mesh-based collisions, we recognize 2 types of collisions: 1. vertex-face (V,E) and 2. edge-edge (E,E). Since we are timestepping, we should expect to the detect the collision when the objects are interpenetrating.

Continuous Collisoin Detection (CCD). Rather then trying to reason about when a collision will happen in our descretized setting, we can think about it in a continuous setting. CCD processes all the possible collisions that might occur from tnow to tlater (e.g. t to t+h). To do so we can either look forward in time and look for the time when a collision will happen or look backward in time and find a time just before the collision happend. We can pefrorm CCD with a course-to-fine approach to speed it up.

To prevent collisions we can either set a large enough time-step based on CCD or we can warp points to the start of the timestep based on the computed normal.

To compute a t and p at the contact we will make the assumption that when h0, then motion between time-steps can be considered linear, while the error increases with O(h). We can “sweep” a triangle over the time-step to get the “swept-volume.” We can then compute the time of collision by finding the intersection of the swept-volume with the other object. Using the forward prediction approach we get candidate positions at the next timestep for one of the triangles as:

xi=x0+hui for i{0,1,2}. For the backward formulatoin we get:

xi=xihui. In fact for the backward formulation we already have the exact candidates for the previous timestep. We can instaed compute linear velocity as ui=xixih. Using bounding boxes around previous and next timestpe we can see whether there might exist a collision or not.

CCD for (V,F) contact. The idea is to use 3 nodes {x1,x2,x3} from one triangle to get the surface normal p^n and another node to check whether it is in the plane of p^n. First we get p^n=(x2x1)×(x3x1). Distance to the origina is p^nx1.

For a new point x4 to lie in the triangle we need:

p^nx4d=0, ((x2x1)×(x3x1))(x4x1)=0. Now introducing time-dependence and linear motion equations from beofre into the test we get:

(((x2x1)+(u2u1)t)×((x3x1)+(u3u1)t))((x4x1)+(u4u1)t)=0

and we want to determine the minmial non-negative such t<h s.t. the above is true. This is a P3 polynomial so we can find these values using a root-finding algorithms. This gives the point of contact p=x4+u4t.

CCD for (E,E) contact. We can use the same approach as above, but we need to consider the edges as well. We must check if the edges are parallel:

(x2x1) times(x4x3)ε. If this is a case we can project vertices on the line through the other edge and check for intersection.

When the two edges are not parallel—possibly touching at only 1 point—then we can reparametrize the edges as line equations:

E1:x1+α(x2x1), E2:x3+β(x4x3).

Then the contact point must also be the closest point between these two lines:

a,b,argmina,b[0,1]x1+α(x2x1)(x3+β(x4x3))2.

From preschool we know that we can solve this in the normal equations form:

[(x2x1)(x2x1)(x2x1)(x4x3)(x2x1)(x4x3)(x4x3)(x4x3)][αβ]=[(x2x1)(x3x1)(x4x3)(x3x1)].

The (α,β) solutions give the candidate closest point. If α,β[0,1] we can simply write the point as:

p=(x1x3)+α(x2x1)β(x4x3).

If we really want to get sweaty, we can write this using Barycentric coordinates:

((1iv)x1(t)+ux2(t)+vx3(t))x4(t)))=0 where t[0,1] and u,v are Barycentric coordinates for the traingle.

4.3 Deformable Bodies / Soft Body Contact

While we did discuss how to frame contact simulation for deformable bodies briefly, we will now give a more nuanced discussion of the topic.

First, reacall the DiffEq that govers dynamics of a deformable body:

Mq¨=fext+fd(u)+fe(q)fc(q,u)

where fd is the damping force, fe is the (internal) elastic force, and fc is the contact force. The first conceptual shift we will do is to consider a system of deformables as one global tetrahedral mesh, so e.g. q,u,fext,R3|V| where |V| is the number of vertices in the “mesh soup” of our system. From a numerical standpoint this view is no differnet from before, but it will give us some benefits when computing contact forces.

With this in mind let us turn to computing contact forces, specifically how rewrite the constraint Jacobian J for constrain-based approaches:

fc(q,u)=J(q)λ(u)

where λ containts the Lagrange multipliers of all the contact forces. Consider two tetrahedral elements A,B defined by {x}{i,j,k,m},{x}{n,o,p,r}, respectively. Then the point of contact is

pA=wixi+wjxj+wkxk+wmxm=pB=wnxn+woxo+wpxp+wrxr,

again through our favourite Barycentric coordinates. At the time of contact we have pA=pB and n^ is the normal to the surface at pA. As we did many times before, we now need to compute the relative velocity of the contact point:

Δv=(tpBtpA),

which is expressed in world space. To convert it into contact space:

v=CΔv,

where C is the contact space coordinate system from before. This expression projects relative velocity onto C. But since wi are not time-dependent we can rewrite:

v=C[w{i,j,k,m}I3×3,w{o,p,q,r}I3×3][v{i,j,k,m}vo,p,q,r]=Ju,

and please bear with me as I use v{i,j,k,m} to denote a vector of velocities vi,vj,vk,vm. To construct the global Jacobian we can combine these local Jacobians for all the contact points to get JR3K×3|V|.

Global J assembly

4.3.1 Time Discretization for Deformables

Instead of using semi-implicit integrators we usually gravitate towards implicit schemes, because stiff elasticity limits time-step sizes.

The first way to solve implicit formulations is using root-finding which gives time-updated state vectors. The second popular way is by minimizing an energy potential using a first-order optimizer. The minimization approaches can be broken into position and velocity-level methods and we will very briefyl discuss them after we introduct root-finding methods.

Root-finding. Rewrite 2nd order ODE as a system of coupled 1st order ODEs:

Mu˙=fext+fd(u)+fe(q)+fc(q,u), q˙=u.

For why we do this, refer to [notes]. We can now formulate root finding using the following (rough) steps:

  1. Write primary or dual form of the system of equations.
  2. Use finite differences to compute time-derivatives.
  3. Derive Newton’s method equation by plugging in 1st order Taylor approximations. This should give us a linear system which can be solved using different methods (Schur complement, etc.).
  4. Iterate until convergence.

We derive the Primary form of the system. Assume for the moment that contact forces are fc(q,u)=qEc(q,u) where Ec is a contact potential function. Then the descretized equations of motion in Euler method are:

M(ut+hut)/h=fext+fd(ut+h)+fe(qt+h)qEc(qt+h,ut+h),

which can be rewritten in matrix form as a homogeneous system:

Fprimary=0. This gives a rootfinding problem:

compute qt+h,ut+h s.t. Fprimary(ut+h,ut+h)=0, which can be solved using Newton’s method. Assuming qt,ut are known we want the updates:

qk+1=qk+Δq,uk+1=uk+Δu,

where Δq,Δu are the updates. We can incorporate line-search into the Newton’s method to ensure convergence by ading a step-length parameter. Next step is to compute 1st order Taylor approximations of Fprimary elements. First we note that Bk=ufd(uk), Kk=qfe(qk), Hqk=q2Ec(qk,uk), Huk=quEc(qk,uk), where B,K are the dambing and stifness matrices. Particularly we have:

Muk+1Muk+MΔu

hfd(uk+1)hfd(uk)+hBkΔu

hfe(qk+1)hfd(qk)+hKkΔq

hfc(qk+1,uk+1)hfc(qk,uk)hHqkΔqhHukΔu

which by noting Δq=hΔu we can write as:

[MhBkh2Kk+hHuk+h2Hqk00h][ΔuΔq]=[M(utuk)+h(fdk+fek+fck+fext)qtqk+huk]

A solution can be obtained by solving 1st row for Δu, then 2nd row to solve for Δq. We can then update qk+1=qk+Δq and uk+1=uk+Δu and repeat until convergence.

Dual.

Position-level Minimization. We rewrite the time-integration as a minimizatoin problem:

qt+h=f(q,u)=argminq,ϕ(q)012(qq^)M(qq^)+h2Ee(q)qh2fd(u)

is a solution to implicit Euler formulation. The first part is the momentum potential where q^=q+hu+h2M1fext, the second term minimizes the energy potential of elastic strain Ee, and the third minimizes work done by fd.

To actually solve it we need to form the optimality conditions, i.e. a Lagrangian function:

L(q,u)=f(q,u)γϕ(q),

where γ0 are Lagrange multipliers for constraints ϕ(q)0. We can then compute the gradient of the Lagrangian and set it to zero to get the (1st order) optimality conditions:

qL(qh+t,ut+h)=qf(qh+t,ut+h)qϕ(qh+t)topγ=0, γ0, ϕ(qt+h)0, γϕ(qt+h)=0.

With expanding f and using some tricks (refer to the [notes] ) we get the minimization problem equivalent to the primal form:

qt+h=argminq12(qq^)M(qq^)+h2Ee(q)+h2Ec(q,u)qh2fd(u)

where Ec is the contact potential.

Velocity-level Minimization. Before we talk about this, note that velocity-level minimization is not that popular for deformable somulations. That said, it is very similar to the position-level minimization, we get the optimization problem:

ut+h=argminu,Ju012(uu^)M(uu^)+hEe(q),

where u^=u+hM1fext, ignoring the damping forces and ϕ(q) constraint is approximated to first order as ϕ(qt)+hJuJu0. Looking at q as function of u:

uEe(q)=1hqEe(q).

4.3.2 Little Detour: Incremental Potential

We will do something very similar to above, but with more standard notation that we will later use when covering IPC. We start with Backward Euler discretization of the equations of motion and reformulate them as an optimization problem.

Mu˙=qU(q)=f,

which is a conservative system. Using Beckward Euler discretization of the continuous system and approximation of q with previous two time-steps we get:

Mqn+12qn+qn1h2=qU(qn+1)=fn+1,

and by rearranging with q~=2qnqn1 we get:

Mqn+1q~h2=qU(qn+1).

Seeing the above as a gradient of an expression, we see:

[12h2qq~nM2+U(q)]=0,

so the minimizer prediction of the next node position becomes:

qn+1=argminq[12h2qq~nM2+U(q)]=argminqE(q),

where E(q) is the incremental potential of the system. This is a very useful concept in contact simulation, because it allows us to write the equations of motion as a minimization problem. The first term of E is the inertia term, which is the energy of the system if it was at rest. The second term is the potential energy (e.g. elastic potential) of the system. The minimization problem is then to find the configuration of the system that minimizes the energy. For example, in context of elastic deformables we will have this optimization as:

qn+1=argminq[12qq~nM2+h2ψ(q)],

where note that since I multiplied the second term by h2 I can drop the 1/h2 in the first term, since the minimizer will be the same. Here ψ(q)=f(x)dx is the elastic potential of the system.

Recall, we want to solve the above minimization problem w.r.t to the constraint that ϕ(q)0, i.e. interpenetration free! This is very nonlinear, nonconvex, and hard to solve. In the next section we will see how to solve this using penalty and barrier methods.

4.4 Penalty and Barrier Methods

This is a completely different approach to handling contact than the constraint-based approaches we have been talking about so far. The idea is to use a potential function to penalize the interpenetration of objects. The potential function is a function of the penetration depth ϕ and the normal force λn^:

4.4.1 Overview

The methods we have covered so far attempted to remove interpenetration of objects by either shifting objects apart or applying impulses to them at the point of contact. In contrast, in penalty based methods, we use a spring-mass system to prevent / penalize interpenetration. The idea is that if we model the forces due to penetration as a* spring force with rest length of 0*, then we can find a force f (and torque τ)—external forces—s.t. at some t we can use them in the equations of motion to perform integration.

If a rigid body A penetrates B, then for the kth contact points we have a force fk,spring gives rise to a torque term τk,spring that is applied at the contact point. If the vectorf rom the center of mass of A to the contact point is rk,A, then the torque is τk,spring=rk,A×fk,spring. To create a “penalty method” affected external force vector we can sum all the force and torque vectors:

f=[fext+kfk,springτext+kτk,spring]. Then in the simulation loop we would: 1. find contact points (collision detection) 2. compute and accumulate spring forces 3. integrate equations of motion foward in time.

Contact Spring Forces. Considering the kth contact at pk between A,B with a contact normal n^ and a measure of penetration depth ϕk we can write the force exerted by body A onto B as a spring force:

fB,spring=(ksϕkbvkn^k)n^k

where ks is the spring constant, vk is the relative velocity of the contact points, and b is the damping constant. The force exerted by B onto A is then fB,spring. The torque is then τk,spring=rk,A×fk,spring. The n^k is in the paranthesses because we only really care about relative velocity in the normal direction.

Now recall how we computed relative velocity vk=ϕ˙k:

ϕ˙k=n^k((vA+ωA×rk,A)(vB+ωB×rk,B)), =n^k[I3×3,rk,A×,I3×3,rk,B×][vAωAvBωB]=Jku,

which we have seen before. Looking back at fB,spring we find its magnitude to be: |fB,spring|=ksϕkbϕ˙k.

HOWWWWWW IS THIS A MAGNITUDE???????????????????/ IT SHOULD HAVE A SIGN

Now we can write the forces on the whole system due to contact k as:

[fA,springτAfB,springτB]=[n^k|fB,s|rk,A×n^k|fB,S|n^k|fB,S|rk,B×n^k|fB,S|]=Jk|fB,s|.

For all the contacts we can generalize as:

ϕ˙=Ju, λ=Kϕϕ˙, Mu˙=f+Jλ

where K is a diagonal matrix with ks on the diagonal. If we have K contacts and N bodies we have dimensions JRK×6N and f,uR6N and ϕ,ϕ˙,λRK.

Soft Bodies. If we want to generalize this to soft bodies, we will replace the 6N dimension into 3×|V| dimension and remove τ, since there will be no torque component to the spring force. If the contact does not fall onto a specific node, then we distribute the penalty force on the enclosing nodes of the element, using some weighing method like Barycentric coordinates.

Finally, we can use the above general system, discretize it and perform timestepping. Xu [2014] shows an implict time-stepping scheme.

Penalty based friction. We will also use a spring system to model the friction in our simulator. Usually, we denote the first point of contact as a (anchor) and then track the actual point of contact p through time. If the coefficient of the spring from a to p is kf and its rest length is 0, then the friction force is:

ff,s=kf(ap). If ff,sμfinterpenetrationspring, where μ is the Coulomb coefficient of friction, then we have static friction. If not, then we are dealing with dynamic friction (objects are sliding relative to each other). In the latter case, we move a to the new contact point p so that the condition above is true.

Alternative way of computing the friction force is to relate it to the relative tangential velocity:

ff,s=μfspringvt^/vt^ but this model ignores static friction.

One problem with penalty based methods is that we have a tradeoff between having a stiff, difficult problem to solve for a high k and an easy system to solve with small k, that causes tunneling. The alternative is to use barrier methods.

4.5 Barrier Methods

The core idea of barrier methods is to prevent interpenetration by adding a barrier function to the potential function. These barrier functions diverge as we get closer to the object. Again, we have to be careful how to solve this stiff problem.

One simple method is called asynchronous contact mechanics. We start with a quadratic penality:

g(q,ν)=xbxaν,

where $is the thickness of th esurface and xa,xb are the closest points on the surfaces of the objects. We can then write the contact potential as:

V(q,ν,k)=1/2kg2(q,ν) if g0, else 0, where k is the penalty barrier stiffness. Some suggested we can stack these barriers as a sequence of quadratic barrier functions where ks are increasing and νs are decreasing. Then their sum will just converge to . That said, these methods are too computationally intesive.

While well-suited for small time-step explicit methods, the incremental construction of the barriers challenge application in implicit time integration with Newton-type optimization.

4.5.1 IPC - Incremental Potential Contact

Another way to achieve robust contact handling is by using barrier potentials within an optimization-based implicit time integration. As you can recall, we saw that implict time integration can be reframed as an optimization over nodal positions q and velocities u:

qt+h=argminqf(q,qt,ut)s.t.ϕk(q)0kC. Here C is set of all contacts that are active at time t. So far we treated contacts as inequality constraints, but we can also turn those constraints into barrier potentials. This is exactly what IPC does. This transforms our objective to:

qt+h=argminqf(q,qt,ut)+kkCb(dk(q),d^), where b is the barrier function, dk is the unsigned distance between the objects. We can define the barrier function:

b(d,d^)=(dd^)2ln(dd^),0<d<d^ if 0<d<d^, else 0. Here b is smoothly clamed barrier that goes to 0 as dd^. Now we can use d^ to trade-off accuracy and performance. The smaller d^ makes the barrier thinner and the simulation more realistic, but harder to optimizer. The larger d^ makes the barrier thicker and the simulation less realistic, but easier to optimize.

We could say all constraints are active, but becuase we have local support from the clamed barrier function, we can use a data structure like spatial hasing to not consider contacts with 0 force.

The main benefit of IPC approach is that it’s an unconstrained minimization, which can be robustly solved using Newton’s method with line search. By using CCD within the extend of line-search we can get a guarantee that for every step we will have no collisions independent of the parameter choices.

The limitatoin here is that we have to make sure that the input geometry and d^ do not cause interpenetration in the initial state.

(Consistent) Distance Functions. Commonly with distance-based constraints we use a measure like d(q)0 using a SDF. But under large dispalcements, this constraint can be violated without interpenetration.

IPC on the other hand uses an unsigned distnace function. This gives a consisten constraint measure as the contact moves through time. In 3D this boils down to computing minimal distance between 2 triangles; as long as the triangles do not interesect, the distance is positive. In tha case we can formulate the problem as minimum distance between vertices and triangles as well as between edges and edges.

First, the distance between a point and triangle as we have allready seen can be expressed using Barycentric coordinates u,v:

dPT(x1,x2,x3,p)=minα,β((1uv)x1+ux2+vx3)p

s.t. u0,v0,u+v1. The distance between two edges parametrized with a,b can be expressed as:

dEE(x1,x2,x3,x4)=mina,b(x1+a(x2x1))(x3+b(x4x3))

s.t. 0a,b1. The best thing is that dPT,dEE both have closed form solutions.