Position Based Dynamics

Last Update:May 18, 2024 am

Algorithm

The dynamics of an object can be described by $n$ vertices and $M$ constraints on vertex position. The mass, position and velocity of the $i$-th vertex are denoted as respectively. The $j$-th constraint may be an equality or inequality, written as

We use the symbol $\succ$ to denote $=$ or $\ge$ and let . Then the $j$-th constraint is denoted as .

Position based dynamics can be abbreviated as PBD. The algorithm first calculates the initial predicted position of each vertex , and then try to move to satisfy all the constraints

The specific algorithm of PBD can be represented by the following pseudo code.


Figure 1 - Pseudo code for PBD

Solver

In the PBD pseudocode, lines 8 to 10 are the iterative solver. Here, the function

is a nonlinear Gauss-Seidel solver for the system of equations/inequalities

The solver will linearize and solve each constraint in turn. Each time a constraint is solved, the solver will immediately update the values of to affect the solution of . Below we will specifically introduce the solution method for .

If the constraint is an equation, we want to find a such that , where . Linearizing it to the first order, we get

The above equation generally has infinitely many solutions. If we restrict the solution to be in the direction of

that is, let

we can obtain a particular solution

The solution method for is to update the original with . Therefore, the function can be represented in pseudocode as follows


Figure 2 - Pseudocode for the $\mathrm{projectConstraints}$ Solver

Specific constraints

Stretch

The stretch constraint is

where $d$ represents the initial length. The gradient is calculated as

Thus

SDF Collision

The SDF collision constraint is

The correction term is

Example:SDF collision for sphere

Given a sphere with radius $r$, its SDF collision constraint is

The correction term is

The calculation of numerical integral

We can use the tetrahedron technique to optimize the calculation of numerical differentiation of SDF. Let

Consider the sum

From this we can get


Copyright Notice: All articles in this blog are licensed under CC BY-SA 4.0 unless declaring additionally.