Simulation - Shape Matching with PPD
Path of the code: [04_shape_matching]
The objective of this exercise is to implement a Rigid Body simulation using PPD approach and Shape Matching.
This approach relates to the publications
Program structure
The current program applies a standard integration using the Position Based Dynamics approach over object (cubes, cylinder, cones, etc.) made from multiple particles positionned at the vertex of their respective mesh. This integration is performed in the filesimulation/simulation.cpp
.
During the simulation, the positions are constrained with three functions:
-
-
collision_with_walls
: Ensure that the particles don't enter in the ground and the two walls. -
-
collision_between_particles
: Handle the collision between particles belonging to different objects. -
-
shape_matching
: Ensure the particle of a given object preserves its original shape.
collision_with_walls
is completed, and the two other functions need to be filled.
Shape matching
First start by implementing the functionshape_matching
for a rigid transformation.
Reminders on shape matching:
- We consider an object initially defined by a reference shape with vertex positions \(p_i^{ref}\), and barycenter \(c^\text{ref}\).
- We call \(p_i\) the vertex position, and \(c\) the barycenter of the current deformed object state.
- We call \(\mathrm{T}\) the transformation matrix such that
-
- \(\displaystyle \mathrm{T}=\sum_i (p_i-c)\,(p_i^\text{ref}-c^\text{ref})^T\)
- This matrix represents the transformation that minimizes \(\|\mathrm{T}\,(p_i^\text{ref}-c^\text{ref})-(p_i-c)\|^2\)
- The shape matching approach for rigid deformation consists in
-
- 1- Computing the rotation matrix \(\mathrm{R}\) given as the polar decomposition of \(\mathrm{T}\), i.e. the rotation approximating at best the transformation \(\mathrm{T}\).
- 2- And use it to set the new vertex positions \(q_i\) as \(q_i=\mathrm{R}(p_i^\text{ref}-c^\text{ref})+c\)
Collision between particles
Now add the collision between shapes. To this end, we can consider that each particle is associated to a colliding sphere with a specific radius (simulation_parameter.collision_radius
).
Handling the collision between the object consists in handling collision between two spheres belonging to different shapes.
-
> Fill the function
collision_between_particles
in order to handle such collision.
- The treatment of the collision should be handled via positional modification, i.e. projecting collising spheres onto their contact surface.
- When projecting shapes at high speed, some collisions between shapes can be missed with particles traversing fully through another one. To reduce this effect, you can
-
-
- Increase the
collision steps
: number of iterations handling collisions + shape matching at each simulation step. -
- Decrease the
Time step
-
- Increase the
Collision radius
-
- Increase the
Elasticity and Plasticity
Extend the model to handle a notion of elasticity and plasticity to deformation.- - Elasticity can be modeled in considering the following deformation
-
- \(q_i = (1-\alpha)\;(\mathrm{R}(p_i^\text{ref}-c^\text{ref})+c) + \alpha p_i\)
-
\(\alpha\) is the elasticity parameter (in the code:
param.elasticity
)
- - Plasticity can be modeled in consideing a modification of \(p_i^\text{ref}\) (and \(c^\text{ref}\)) when a large deformation occurs. Ex:
-
- If \(\|\mathrm{R}\,(p_i^\text{ref}-c^\text{ref})-(p_i-c)\| \geq \epsilon\) :
- Then update \(p_i^\text{ref}\) and \(c^\text{ref}\) to take into account such deformation in their new state.
Example of elastic deformation
Example of plastic deformation