Skip to main content

Projective Dynamics: Fusing Constraint Projections for Fast Simulation

Reading NotesResearchPhysicsProjective DynamicsAbout 5 minAbout 1467 words

Formula

G=E2(1+ν) G = \frac{E}{2 (1 + \nu)}

  • GG — shear modulus[1]
  • EE — Young’s modulus
  • ν\nu — Poisson’s ratio

Energy

W(\vbq,\vbT)=w2A\norm\vbXf\vbXg1\vbTF2 W(\vb{q}, \vb{T}) = \frac{w}{2} A \norm{\vb{X}_f \vb{X}_g^{-1} - \vb{T}}_F^2

  • WW — potential energy
  • ww (aka. GG) — shear modulus
  • (constant) AA — triangle area / tetrahedron volume
  • \vbXf=\bmqty\vbq0,1,2\vbq3\vb{X}_f = \bmqty{\vb{q}_{0, 1, 2} - \vb{q}_3} — deformed shape
  • (constant) \vbXg=\bmqty\vbq~0,1,2\vbq~3\vb{X}_g = \bmqty{\tilde{\vb{q}}_{0, 1, 2} - \tilde{\vb{q}}_3} — undeformed shape
  • (auxiliary) \vbT\vb{T} — rotation matrix

Force

\vbfi=\pdvW(\vbq,\vbT)\vbqi=wA(\vbXf\vbXg1\vbT)(\pdv\vbXf\vbqi\vbXg1) \vb{f}_{i} = \pdv{W(\vb{q}, \vb{T})}{\vb{q}_i} = w A \pqty{\vb{X}_f \vb{X}_g^{-1} - \vb{T}} \odot \pqty{\pdv{\vb{X}_f}{\vb{q}_i} \vb{X}_g^{-1}}

  • \vbf\vb{f} — force
  • (variable) \vbq\vb{q} — deformed position

Hessian Matrix

\vbHij=\pdvfi\vbqj=wA(\pdv\vbXf\vbqj\vbXg1)(\pdv\vbXf\vbqi\vbXg1) \vb{H}_{ij} = \pdv{f_i}{\vb{q}_j} = w A \pqty{\pdv{\vb{X}_f}{\vb{q}_j} \vb{X}_g^{-1}} \odot \pqty{\pdv{\vb{X}_f}{\vb{q}_i} \vb{X}_g^{-1}}

  • \vbH\vb{H} — Hessian matrix

Tips

\vbH\vb{H} is constant. The non-zero values of \vbHij\vb{H}_{ij} only appear in cases when \vbqi\vb{q}_i and \vbqj\vb{q}_j are both located within the same tetrahedron.

Detailed Formula

Force

fai=\pdvWqai=wA(\vbXf\vbXg1\vbT)(\pdv\vbXfqai\vbXg1) f_{a i} = \pdv{W}{q_{a i}} = w A \pqty{\vb{X}_f \vb{X}_g^{-1} - \vb{T}} \odot \pqty{\pdv{\vb{X}_f}{q_{a i}} \vb{X}_g^{-1}}

  • i=0,1,2,3i = 0, 1, 2, 3 — id of vertex
  • a=x,y,za = x, y, z — axis

\vbXf=[qx0qx0qx0qx0qx0qx0qy0qy0qy0qy0qy0qy0qz0qz0qz0qz0qz0qz0] \vb{X}_f = \begin{bmatrix} q_{x 0} - q_{x 0} & q_{x 0} - q_{x 0} & q_{x 0} - q_{x 0} \\ q_{y 0} - q_{y 0} & q_{y 0} - q_{y 0} & q_{y 0} - q_{y 0} \\ q_{z 0} - q_{z 0} & q_{z 0} - q_{z 0} & q_{z 0} - q_{z 0} \end{bmatrix}

(\pdv\vbXfqai)lm=1    i=0,1,2,a=x,y,z,l=a,m=i(\pdv\vbXfqai)lm=1    i=3,a=x,y,z,l=a,m=0,1,2 \pqty{\pdv{\vb{X}_f}{q_{a i}}}_{l m} = 1 \iff i = 0, 1, 2 \qc a = x, y, z \qc l = a \qc m = i \\ \pqty{\pdv{\vb{X}_f}{q_{a i}}}_{l m} = -1 \iff i = 3 \qc a = x, y, z \qc l = a \qc m = 0, 1, 2

Therefore, when i=0,1,2i = 0, 1, 2

fai=lnwA(\vbXf\vbXg1\vbT)ln(\pdv\vbXfq0x\vbXg1)ln=lmnwA(\vbXf\vbXg1\vbT)ln(\pdv\vbXfq0x)lm(\vbXg1)mn=nwA(\vbXf\vbXg1\vbT)an(\vbXg1)in=nwA(\vbXf\vbXg1\vbT)an(\vbXgT)ni \begin{equation*} \begin{split} f_{a i} & = \sum_{l n} w A \pqty{\vb{X}_f \vb{X}_g^{-1} - \vb{T}}_{l n} \pqty{\pdv{\vb{X}_f}{q_{0 x}} \vb{X}_g^{-1}}_{l n} \\ & = \sum_{l m n} w A \pqty{\vb{X}_f \vb{X}_g^{-1} - \vb{T}}_{l n} \pqty{\pdv{\vb{X}_f}{q_{0 x}}}_{l m} \pqty{\vb{X}_g^{-1}}_{m n} \\ & = \sum_n w A \pqty{\vb{X}_f \vb{X}_g^{-1} - \vb{T}}_{a n} \pqty{\vb{X}_g^{-1}}_{i n} \\ & = \sum_n w A \pqty{\vb{X}_f \vb{X}_g^{-1} - \vb{T}}_{a n} \pqty{\vb{X}_g^{-T}}_{n i} \end{split} \end{equation*}

\bmqty{\vb{f}_0 & \vb{f}_1 & \vb{f}_2} = f_{a i} = w A \pqty{\vb{X}_f \vb{X}_g^{-1} - \vb{T}} \vb{X}_g^{-T}

Hessian Matrix

When i,j=0,1,2i, j = 0, 1, 2

Haibj=lnwA(\pdv\vbXfqai\vbXg1)ln(\pdv\vbXfqbj\vbXg1)ln=lmnkwA(\pdv\vbXfqai)lm(\vbXg1)mn(\pdv\vbXfqbj)lk(\vbXg1)kn=nwA(\pdv\vbXfqai)ai(\vbXg1)in(\pdv\vbXfqbj)bj(\vbXg1)jn(l=a=b)=nwA(\vbXg1)in(\vbXgT)nj \begin{equation*} \begin{split} H_{a i b j} & = \sum_{l n} w A \pqty{\pdv{\vb{X}_f}{q_{a i}} \vb{X}_g^{-1}}_{l n} \pqty{\pdv{\vb{X}_f}{q_{b j}} \vb{X}_g^{-1}}_{l n} \\ & = \sum_{l m n k} w A \pqty{\pdv{\vb{X}_f}{q_{a i}}}_{l m} \pqty{\vb{X}_g^{-1}}_{m n} \pqty{\pdv{\vb{X}_f}{q_{b j}}}_{l k} \pqty{\vb{X}_g^{-1}}_{k n} \\ & = \sum_n w A \pqty{\pdv{\vb{X}_f}{q_{a i}}}_{a i} \pqty{\vb{X}_g^{-1}}_{i n} \pqty{\pdv{\vb{X}_f}{q_{b j}}}_{b j} \pqty{\vb{X}_g^{-1}}_{j n} \quad \pqty{l = a = b} \\ & = \sum_n w A \pqty{\vb{X}_g^{-1}}_{i n} \pqty{\vb{X}_g^{-T}}_{n j} \end{split} \end{equation*}

\vbH=Hij=wA\vbXg1\vbXgT \vb{H} = H_{i j} = w A \vb{X}_g^{-1} \vb{X}_g^{-T}

When i=0,1,2,j=3i = 0, 1, 2 \qc j = 3

Haibj=lnwA(\pdv\vbXfqai\vbXg1)ln(\pdv\vbXfqbj\vbXg1)ln=lmnkwA(\pdv\vbXfqai)lm(\vbXg1)mn(\pdv\vbXfqbj)lk(\vbXg1)kn=nkwA(\pdv\vbXfqai)ai(\vbXg1)in(\pdv\vbXfqbj)bk(\vbXg1)kn(l=a=b)=nkwA(\vbXg1)in(\vbXgT)nk \begin{equation*} \begin{split} H_{a i b j} & = \sum_{l n} w A \pqty{\pdv{\vb{X}_f}{q_{a i}} \vb{X}_g^{-1}}_{l n} \pqty{\pdv{\vb{X}_f}{q_{b j}} \vb{X}_g^{-1}}_{l n} \\ & = \sum_{l m n k} w A \pqty{\pdv{\vb{X}_f}{q_{a i}}}_{l m} \pqty{\vb{X}_g^{-1}}_{m n} \pqty{\pdv{\vb{X}_f}{q_{b j}}}_{l k} \pqty{\vb{X}_g^{-1}}_{k n} \\ & = \sum_{n k} w A \pqty{\pdv{\vb{X}_f}{q_{a i}}}_{a i} \pqty{\vb{X}_g^{-1}}_{i n} \pqty{\pdv{\vb{X}_f}{q_{b j}}}_{b k} \pqty{\vb{X}_g^{-1}}_{k n} \quad \pqty{l = a = b} \\ & = \sum_{n k} - w A \pqty{\vb{X}_g^{-1}}_{i n} \pqty{\vb{X}_g^{-T}}_{n k} \end{split} \end{equation*}

Hi3=kwA(\vbXg1\vbXgT)ik H_{i 3} = \sum_{k} - w A \pqty{\vb{X}_g^{-1} \vb{X}_g^{-T}}_{i k}

When i=j=3i = j = 3

Haibj=lnwA(\pdv\vbXfqai\vbXg1)ln(\pdv\vbXfqbj\vbXg1)ln=lmnkwA(\pdv\vbXfqai)lm(\vbXg1)mn(\pdv\vbXfqbj)lk(\vbXg1)kn=mnkwA(\pdv\vbXfqai)am(\vbXg1)mn(\pdv\vbXfqbj)bk(\vbXg1)kn(l=a=b)=mnkwA(\vbXg1)mn(\vbXgT)nk \begin{equation*} \begin{split} H_{a i b j} & = \sum_{l n} w A \pqty{\pdv{\vb{X}_f}{q_{a i}} \vb{X}_g^{-1}}_{l n} \pqty{\pdv{\vb{X}_f}{q_{b j}} \vb{X}_g^{-1}}_{l n} \\ & = \sum_{l m n k} w A \pqty{\pdv{\vb{X}_f}{q_{a i}}}_{l m} \pqty{\vb{X}_g^{-1}}_{m n} \pqty{\pdv{\vb{X}_f}{q_{b j}}}_{l k} \pqty{\vb{X}_g^{-1}}_{k n} \\ & = \sum_{m n k} w A \pqty{\pdv{\vb{X}_f}{q_{a i}}}_{a m} \pqty{\vb{X}_g^{-1}}_{m n} \pqty{\pdv{\vb{X}_f}{q_{b j}}}_{b k} \pqty{\vb{X}_g^{-1}}_{k n} \quad \pqty{l = a = b} \\ & = \sum_{m n k} w A \pqty{\vb{X}_g^{-1}}_{m n} \pqty{\vb{X}_g^{-T}}_{n k} \end{split} \end{equation*}

H33=mkwA(\vbXg1\vbXgT)mk H_{3 3} = \sum_{m k} - w A \pqty{\vb{X}_g^{-1} \vb{X}_g^{-T}}_{m k}

Solver

\vbsn=\vbqn+h\vbvn+h2\vbM1\vbf \vb{s}_n = \vb{q}_n + h \vb{v}_n + h^2 \vb{M}^{-1} \vb{f}

  • hh (aka. Δt\Delta{t}) — time step
  • \vbM\vb{M} — mass matrix

For k=0KSolve(1h2\vbM+\vbH)Δ\vbq=1h2\vbM(\vbq(k)\vbsn)+\vbf(\vbq(k))\vbq(k+1)\vbq(k)+Δ\vbq\vbqn+1=\vbq(k+1)\vbvn+1=(\vbqn+1\vbqn)/h \begin{align*} & \text{For} \ k = 0 \dots K \\ & \quad \text{Solve} \pqty{\frac{1}{h^2} \vb{M} + \vb{H}} \Delta{\vb{q}} = - \frac{1}{h^2} \vb{M} \pqty{\vb{q}^{(k)} - \vb{s}_n} + \vb{f}\pqty{\vb{q}^{(k)}} \\ & \quad \vb{q}^{(k + 1)} \leftarrow \vb{q}^{(k)} + \Delta{\vb{q}} \\ & \vb{q}_{n + 1} = \vb{q}^{(k + 1)} \\ & \vb{v}_{n + 1} = (\vb{q}_{n + 1} - \vb{q}_{n}) / h \end{align*}

Conjugate gradient method

  • used to solve \vbA\vbx=\vbb\vb{A} \vb{x} = \vb{b}
  • \vbA=1h2\vbM+\vbH\vb{A} = \frac{1}{h^2} \vb{M} + \vb{H}
  • \vbb=1h2\vbM(\vbq(k)\vbsn)+\vbf(\vbq(k))\vb{b} = - \frac{1}{h^2} \vb{M} \pqty{\vb{q}^{(k)} - \vb{s}_n} + \vb{f}\pqty{\vb{q}^{(k)}}

\vbr0=\vbb\vbA\vbx0if \vbr0 is sufficiently small, then return \vbx0 as the result\vbp0=\vbr0repeatαk=\vbrkT\vbrk\vbpkT\vbA\vbpk=\vbrk\vdot\vbrk\vbpk\vdot\vbA\vbpk\vbxk+1=\vbxk+αk\vbpk\vbrk+1=\vbrkαk\vbA\vbpkif \vbrk+1 is sufficiently small, then exit loopβk=\vbrk+1T\vbrk+1\vbrkT\vbrk=\vbrk+1\vdot\vbrk+1\vbrk\vdot\vbrk\vbpk+1=\vbrk+1+βk\vbpkk=k+1end repeatreturn \vbxk+1 as the result \begin{align*} & \vb{r}_0 = \vb{b} - \vb{A} \vb{x}_0 \\ & \text{if $\vb{r_0}$ is sufficiently small, then return $\vb{x}_0$ as the result} \\ & \vb{p}_0 = \vb{r}_0 \\ & \text{repeat} \\ & \qquad \alpha_k = \frac{\vb{r}_k^T \vb{r}_k}{\vb{p}_k^T \vb{A} \vb{p}_k} = \frac{\vb{r}_k \vdot \vb{r}_k}{\vb{p}_k \vdot \vb{A} \vb{p}_k} \\ & \qquad \vb{x}_{k + 1} = \vb{x}_k + \alpha_k \vb{p}_k \\ & \qquad \vb{r}_{k + 1} = \vb{r}_k - \alpha_k \vb{A} \vb{p}_k \\ & \qquad \text{if $\vb{r}_{k + 1}$ is sufficiently small, then exit loop} \\ & \qquad \beta_k = \frac{\vb{r}_{k + 1}^T \vb{r}_{k + 1}}{\vb{r}_k^T \vb{r}_k} = \frac{\vb{r}_{k + 1} \vdot \vb{r}_{k + 1}}{\vb{r}_k \vdot \vb{r}_k} \\ & \qquad \vb{p}_{k + 1} = \vb{r}_{k + 1} + \beta_k \vb{p}_k \\ & \qquad k = k + 1 \\ & \text{end repeat} \\ & \text{return $\vb{x}_{k + 1}$ as the result} \end{align*}


  1. Shear modulus - Wikipediaopen in new window ↩︎