Model Blood Cell Flow and Deformation in Matter.js
This article explains how to simulate the flow and mechanical deformation of red blood cells (erythrocytes) traveling through narrow capillary channels using the 2D physics engine Matter.js. Because Matter.js is fundamentally a rigid-body engine, capturing microvascular dynamics requires approximating soft-body mechanics through constrained particle rings, building static geometric constrictions, applying external hydrodynamics to emulate plasma flow, and tuning material parameters to prevent cell collapse while enabling realistic stretching.
1. Constructing Deformable Red Blood Cells
Matter.js does not provide native continuous soft-body or fluid-membrane physics, so each red blood cell must be modeled as a discretized spring-mass composite:
- Outer Membrane: Create a ring of 12 to 24 small,
circular rigid bodies (
Bodies.circle) arranged in an ellipse or biconcave disc shape. - Perimeter Constraints: Link adjacent nodes around
the perimeter using elastic constraints (
Constraint.create) with high stiffness (e.g.,0.7to0.9) to simulate the tensile strength of the cell's spectrin-actin cytoskeleton. - Internal Pressure (Volume Conservation): To prevent
the cell from inverting or collapsing into a flat line, connect opposing
nodes across the cell interior with radial and diagonal cross-springs at
lower stiffness (e.g.,
0.1to0.3). This structural scaffolding mimics the incompressibility of internal hemoglobin-rich cytoplasm. - Self-Collision Handling: Assign an identical
non-zero negative
collisionGroupacross all nodes within a single cell vianode.collisionFilter.groupto prevent internal nodes from snagging on one another during extreme elongation.
2. Setting Up the Capillary Channel Geometry
Capillaries are narrow biological passages often smaller in diameter than the resting diameter of a red blood cell (typically ~8 µm cell versus 4–7 µm channel):
- Create the channel walls using static rectangular bodies
(
Bodies.rectangle) withisStatic: true. - Shape the channel entrance with a tapered funnel (angled static bodies or polygonal hulls) to guide the cell smoothly into the bottleneck.
- Set the channel wall surface properties with near-zero friction
(
friction: 0.01to0.05) and zero restitution (restitution: 0). This replicates the natural lubricating layer of plasma that coats endothelium walls, reducing wall shear resistance.
3. Simulating Plasma Flow and Hydrodynamic Forces
Because Matter.js does not calculate Navier-Stokes fluid mechanics, fluid pressure gradients must be represented via direct programmatic force injection:
- Pressure-Driven Flow: In the
beforeUpdateengine event listener, apply a directional force (Body.applyForce) to each cell node along the channel axis (\(X\)-axis). - Poiseuille Velocity Profile: In real vessels, fluid moves fastest in the center and approaches zero at the walls. Calculate force magnitude based on the node’s \(Y\)-distance from the channel centerline: \[F_x = F_{max} \cdot \left(1 - \left(\frac{y - y_{center}}{R_{channel}}\right)^2\right)\]
- Viscous Drag: Add synthetic drag opposing motion relative to the fluid velocity to stabilize the simulation and damp violent elastic vibrations.
4. Tuning Physics Engine Constraints
Accurate microvascular deformation requires careful calibration of the Matter.js solver settings:
- Constraint Iterations: Increase
engine.constraintIterations(typically between8and16) to maintain structural integrity under high pressure and prevent spring stretching from tearing the membrane apart. - Position and Velocity Iterations: Increase
engine.positionIterationsto prevent thin wall boundaries from allowing high-speed nodes to tunnel through. - Air Friction: Increase
frictionAir(e.g.,0.05to0.1) on individual nodes to mimic the high viscosity (low Reynolds number) environment typical of microfluidic domains.
By combining an elastic ring structure with a parabolic force field and low-friction static boundaries, Matter.js can reliably demonstrate the parachute-like and bullet-like deformation patterns characteristic of erythrocyte transit through narrow microchannels.