Inferensys

Glossary

Linear Complementarity Problem (LCP)

A Linear Complementarity Problem (LCP) is a mathematical formulation used in physics engines to model contact and friction constraints, where the solution must satisfy conditions that forces are non-penetrating and non-adhesive.
MLOps engineer reviewing model serving infrastructure on laptop, container orchestration visible, technical workspace.
PHYSICS SIMULATION

What is Linear Complementarity Problem (LCP)?

A mathematical formulation central to physics engines for modeling contact and friction constraints, ensuring non-penetration and realistic force interactions.

A Linear Complementarity Problem (LCP) is a mathematical framework for finding vectors w and z that satisfy the conditions w = Mz + q, w ≥ 0, z ≥ 0, and wᵀz = 0, where M is a matrix and q is a vector. In physics simulation, it is the canonical form for solving contact constraints and Coulomb friction, ensuring that contact forces are non-adhesive (non-negative) and only act when bodies are touching (the complementarity condition).

Within a constraint solver, the LCP encodes the Karush–Kuhn–Tucker (KKT) conditions for rigid body dynamics with unilateral constraints. Solving it yields the normal impulses and friction impulses required to prevent interpenetration while respecting the friction cone. Algorithms like Projected Gauss-Seidel (PGS) or Lemke's algorithm are used iteratively, often with warm starting from the previous time step to accelerate convergence in real-time engines.

MATHEMATICAL FOUNDATIONS

Key Characteristics of the LCP Formulation

The Linear Complementarity Problem (LCP) provides a compact, algebraic framework for modeling unilateral constraints like contact and friction. Its defining features make it particularly suited for real-time physics simulation.

01

Complementarity Condition

The core of an LCP is the complementarity condition, expressed as 0 ≤ z ⟂ w ≥ 0. This means the solution variables z and w must be non-negative and orthogonal: for each component i, either z_i = 0 or w_i = 0 (or both). In physics, this elegantly encodes the non-penetration and non-adhesion of contact: a contact force (z) can only be positive if the bodies are exactly touching (w=0), and if bodies are separating (w>0), the contact force must be zero.

02

Linear Relationship

The 'Linear' in LCP refers to the relationship w = Mz + q, where M is a known matrix and q is a known vector. This linear system is derived from the physics of the problem. For contact, M encodes the system's mass matrix and contact geometry (Jacobians), while q contains external forces and relative velocities. This structure allows the problem to be solved with efficient, specialized numerical algorithms rather than general non-linear solvers.

03

Unilateral Constraints

LCPs naturally model unilateral constraints, which are inequalities that can be active or inactive. A classic example is contact: bodies cannot push into each other (the normal force must be ≥ 0), but they can freely separate. This is distinct from bilateral constraints (like a hinge joint), which are always active equalities. The LCP's solution automatically determines which contacts are active (exerting force) and which are inactive (separating), a process known as contact state determination.

04

Friction Cone Approximation

Coulomb friction is non-linear, but it can be incorporated into an LCP through a polyhedral approximation of the friction cone. The continuous cone of allowable friction forces is approximated by a pyramid with 4, 8, or more sides. Each side becomes a linear complementarity constraint. This transforms the non-linear friction problem into a larger, but still linear, complementarity problem that can be solved with the same numerical machinery, enabling stable simulation of sticking and sliding.

05

Solution Algorithms (Lemke's Pivoting)

A standard algorithm for solving LCPs is Lemke's algorithm, a pivotal method similar to the simplex algorithm for linear programming. It systematically explores vertices of a complementary cone to find a solution. For physics simulation, the Projected Gauss-Seidel (PGS) method is often preferred for its simplicity and efficiency in handling large, sparse systems, even though it provides an approximate solution. The choice of solver balances accuracy, speed, and robustness for real-time applications.

06

Connection to Optimization

The LCP is intimately related to convex optimization. Solving the LCP 0 ≤ z ⟂ Mz + q ≥ 0 is equivalent to finding a Karush-Kuhn-Tucker (KKT) point for a specific Quadratic Program (QP) when M is positive semi-definite. This link provides a rich theoretical foundation and allows the use of optimization-based techniques like Sequential Quadratic Programming (SQP) for more complex, non-linear contact problems, bridging the gap between game physics and high-precision engineering simulation.

COMPARISON

LCP vs. Other Constraint Resolution Methods

A feature and performance comparison of the Linear Complementarity Problem (LCP) formulation against other common methods for resolving contact and friction constraints in physics simulation.

Feature / MetricLinear Complementarity Problem (LCP)Penalty MethodImpulse-Based Dynamics

Mathematical Foundation

Complementarity conditions (w ≥ 0, z ≥ 0, wᵀz = 0)

Spring-damper force law (F = -kx - bv)

Instantaneous velocity change via impulse (Δv = M⁻¹Jᵀλ)

Constraint Enforcement

Exact (within solver tolerance)

Approximate (penetration-dependent)

Exact (per-iteration)

Handles Friction Cone

Guarantees Non-Penetration

Guarantees Non-Adhesive Forces

Solution Stability (Stiffness)

High (no artificial stiffness parameters)

Low (requires careful tuning of k, b)

Medium (depends on iteration count)

Typical Solver Type

Iterative (Projected Gauss-Seidel) or Pivoting (Lemke)

Explicit force integration

Sequential impulse application

Computational Cost per Contact

High (solves matrix/MLCP)

Low (direct calculation)

Medium (iterative per contact)

Simulation Scale Performance

O(n²) to O(n) with good warm-starting

O(n)

O(n)

Common Use Case

High-accuracy robotics, off-line simulation

Real-time games, simple interactions

Real-time games, interactive applications

APPLICATIONS

Where is the LCP Used?

The Linear Complementarity Problem is a foundational mathematical formulation with critical applications in computational physics, optimization, and robotics. Its structure elegantly captures the 'either-or' conditions inherent in unilateral constraints like contact and friction.

LINEAR COMPLEMENTARITY PROBLEM (LCP)

Frequently Asked Questions

The Linear Complementarity Problem (LCP) is a fundamental mathematical formulation in physics simulation engines, used to model contact and friction constraints between rigid bodies. These questions address its core mechanics, applications, and role in bridging simulation to reality.

A Linear Complementarity Problem (LCP) is a mathematical framework used in physics engines to model contact constraints and Coulomb friction between rigid bodies, where the solution must satisfy conditions that forces are non-penetrating and non-adhesive. Formally, it solves for vectors z and w such that w = Mz + q, z ≥ 0, w ≥ 0, and z^T w = 0. This last condition, the complementarity condition, is key: it enforces that for each contact, either the normal force is zero (bodies are separating) or the penetration depth/velocity is zero (bodies are in contact but not penetrating). This elegantly captures the "either/or" nature of contact—objects cannot both be pushing on each other and moving apart at the same point.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.