A Linear Complementarity Problem (LCP) is a mathematical framework used in physics engines to model contact forces and friction, ensuring non-penetration and non-adhesive constraints are satisfied. Given a matrix M, a vector q, and unknown vectors w and z, it solves for w = Mz + q subject to the complementarity condition w ≥ 0, z ≥ 0, and wᵀz = 0. This structure perfectly captures the "either-or" nature of contact: bodies either touch (with force) or are separate (with zero force).
Glossary
Linear Complementarity Problem (LCP)

What is Linear Complementarity Problem (LCP)?
A mathematical framework central to modeling contact and friction in physics engines.
In rigid body dynamics, the LCP is solved by the constraint solver each time step to compute impulses that prevent interpenetration. Solvers like Projected Gauss-Seidel (PGS) iteratively approximate the solution. The LCP's formulation is crucial for deterministic simulation and stable Sim-to-Real Transfer, as it provides a consistent mathematical model for the complex, discontinuous physics of collisions and resting contact found in real-world robotics.
Key Characteristics of LCPs
The Linear Complementarity Problem (LCP) is a specialized mathematical formulation used in physics engines to model contact mechanics. It enforces non-penetration and friction constraints by solving for forces that satisfy complementarity conditions.
Core Complementarity Condition
The defining mathematical structure of an LCP is the complementarity condition. For vectors w and z, the problem requires w ≥ 0, z ≥ 0, and wᵀz = 0. In physics, z often represents contact forces or impulses, and w represents the relative velocities or distances at contact points. The condition wᵀz = 0 means that for each contact, either the force is zero (objects are separating) or the relative velocity is zero (objects are in resting or sliding contact), but not both. This elegantly encodes the non-adhesive nature of standard contact.
Modeling Non-Penetration
A primary application is enforcing the non-penetration constraint between rigid bodies. The LCP framework ensures that contact forces are only applied when bodies are touching or interpenetrating, and that these forces are exactly sufficient to push them apart.
- The gap function (distance between bodies) and the normal force form a complementary pair.
- If the gap is positive (bodies are separated), the normal force must be zero.
- If the gap is zero or negative (penetration), a positive normal force must be generated to resolve it. This prevents objects from passing through each other, a fundamental requirement for stable simulation.
Incorporating Friction Cones
LCPs naturally extend to model Coulomb friction, which states that the tangential friction force magnitude is bounded by the normal force multiplied by a coefficient of friction. This relationship forms a friction cone.
In simulation, this is typically approximated as a pyramidal friction cone (a linearized version). The LCP is then formulated to solve for both normal and friction forces simultaneously, ensuring that:
- The friction force lies within the linearized cone.
- A stick-slip condition is enforced: if the relative tangential velocity is zero (sticking), the friction force can be anywhere inside the cone; if sliding occurs, the friction force must be at the cone's boundary, opposing the slide direction.
Formulation as a Linear System
An LCP is derived from the equations of motion and contact constraints. For a rigid body system, the forward dynamics with contact can be expressed as:
M dv = Jᵀ λ + F_ext dt
Where M is the mass matrix, dv is the change in velocity, J is the Jacobian mapping contact forces λ to generalized forces, and F_ext are external forces. Combining this with the complementarity conditions on λ and the relative velocities (J v) transforms the problem into the standard LCP form: w = A z + b, with w ≥ 0, z ≥ 0, wᵀz = 0. The matrix A encodes mass properties and contact geometry, making it positive semi-definite for physical systems, which guarantees solvability.
Solution Algorithms (PGS, PI)
Solving the LCP is computationally intensive. Iterative methods are preferred for real-time physics engines.
- Projected Gauss-Seidel (PGS): A widely used iterative solver. It cycles through each contact constraint, solving for its force while holding others fixed, and then projects the solution onto the feasible set (force ≥ 0). It is robust and relatively simple to implement.
- Pivoting Methods (Lemke's Algorithm): Direct methods that can find an exact solution for smaller or medium-sized problems but have worse worst-case complexity for large-scale simulations common in robotics. The choice of solver directly impacts the stability, speed, and determinism of the simulation.
Relation to Constraint Solvers
The LCP is the mathematical backbone of many velocity-level constraint solvers in physics engines like Bullet or ODE. It provides a unified framework to handle:
- Contact constraints (non-penetration).
- Friction constraints (stick-slip).
- Joint constraints (e.g., hinges, sliders) can also be formulated as LCPs or similar Mixed LCPs (MLCPs) to enforce limits like joint ranges.
This unification allows a single solver iteration to resolve all interdependent constraints simultaneously, leading to more stable and physically plausible results compared to sequential resolution methods. It is a key differentiator between simple collision response and high-fidelity multibody dynamics.
LCP vs. Other Constraint Resolution Methods
A feature comparison of the Linear Complementarity Problem (LCP) solver against other common numerical methods used in physics engines to resolve contact and joint constraints.
| Feature / Metric | Linear Complementarity Problem (LCP) | Projected Gauss-Seidel (PGS) | Sequential Impulses (SI) |
|---|---|---|---|
Primary Mathematical Formulation | Solves w = Mz + q, w ≥ 0, z ≥ 0, wᵀz = 0 | Iteratively solves linear inequalities Ax ≤ b with projection | Applies corrective impulses per constraint each iteration |
Native Support for Friction Cones | |||
Guarantees Non-Penetration (Hard Constraints) | |||
Guarantees Non-Adhesive Forces (wᵀz = 0) | |||
Solution Optimality (for Convex Problems) | Finds a complementarity solution | Finds a feasible solution | Finds a feasible solution |
Typical Convergence Behavior | Finite termination for LCPs (e.g., with Lemke) | Linear convergence | Linear convergence |
Computational Cost per Iteration | High (matrix operations) | Medium | Low |
Common Use Case in Physics Engines | High-accuracy contact with friction (e.g., robotic grasping) | General-purpose contact and joint resolution | Real-time games and interactive applications |
Where is the Linear Complementarity Problem Used?
The Linear Complementarity Problem (LCP) is a foundational mathematical framework with critical applications beyond its core role in physics simulation. It provides the computational structure for solving a wide range of equilibrium and optimization challenges.
Mathematical Programming & Economics
LCPs are fundamental in operations research and equilibrium economics. They generalize several classic problems:
- Linear Programming (LP): Can be formulated as an LCP.
- Quadratic Programming (QP): With certain conditions, the Karush–Kuhn–Tucker (KKT) optimality conditions form an LCP.
- Bimatrix Game Nash Equilibria: Finding a mixed-strategy Nash equilibrium for a two-player game can be reduced to solving an LCP. This makes LCPs crucial for modeling market equilibria, traffic networks, and competitive strategies where multiple agents with opposing interests reach a stable state.
Structural & Mechanical Engineering
LCPs model systems with unilateral constraints that switch states. Key engineering applications include:
- Contact in Mechanical Assemblies: Analyzing stresses in structures with components that may separate or impact under load.
- Cable and Tensegrity Structures: Determining which cables are under tension (active) and which are slack (inactive) for a given load.
- Frictional Contact Problems: Such as the classic frictional beam problem, where a beam contacts a foundation with friction, and regions of stick and slip must be determined. These are complementarity problems because a constraint is either active (e.g., cable taut) or inactive (cable slack), but not both.
Computational Geometry
Certain geometric computation and optimization problems are naturally expressed as LCPs. A prominent example is the linear programming problem of finding the smallest enclosing circle or the convex hull of a point set from a specific perspective. The Lemke-Howson algorithm, a pivotal method for solving LCPs, has deep connections to algorithms for finding fixed points and solving for Nash equilibria, which have geometric interpretations in strategy space. This links LCPs to the study of polyhedra and complementary cones.
Optimization with Equilibrium Constraints (MPEC)
LCPs appear as sub-problems or constraints in more complex bilevel optimization frameworks. A Mathematical Program with Equilibrium Constraints (MPEC) is an optimization problem where the constraints include an equilibrium condition, often modeled by a Variational Inequality (VI) or an LCP. This is used in:
- Engineering Design: Optimizing the shape of a structure where the constraint is that it must be in mechanical equilibrium under load (solved via LCP).
- Economic Policy: A government (upper level) sets taxes to maximize social welfare, constrained by a market that reaches a competitive equilibrium (lower level LCP).
Numerical Algorithms & Solvers
The development of robust LCP solvers is a field of numerical analysis with broad impact. Key algorithms include:
- Lemke's Algorithm: A pivotal method that can process LCPs with positive semi-definite matrices, widely used in economics and engineering.
- Projected Gauss-Seidel (PGS) & Successive Over-Relaxation (SOR): Iterative methods adapted for the LCP's complementarity condition, favored in real-time physics engines for their speed and simplicity.
- Interior-Point Methods: Adapted from convex optimization to solve large-scale LCPs efficiently. The performance and robustness of these solvers directly enable the applications in simulation, robotics, and economics.
Frequently Asked Questions
A Linear Complementarity Problem (LCP) is a core mathematical formulation used in physics engines to model contact and friction. This FAQ addresses its role in robotics simulation and sim-to-real transfer.
A Linear Complementarity Problem (LCP) is a mathematical framework used in physics engines to model contact forces and friction, ensuring that simulated rigid bodies do not interpenetrate and that contact forces satisfy physical constraints like non-adhesion. It formulates the conditions at a contact point as a system where the force must be zero if bodies are separating (non-penetration) and positive if they are in contact (non-adhesion), with the product of these complementary variables being zero. This is expressed as finding vectors w and z such that w = Mz + q, w ≥ 0, z ≥ 0, and w^T z = 0, where M is a matrix derived from system inertia and contact geometry, and q encodes relative velocities.
In practice, the constraint solver of a physics engine sets up and solves an LCP (or a related Mixed Linear Complementarity Problem (MLCP) for friction) each time step to compute the impulses that correctly resolve collisions and resting contacts for rigid body dynamics. This is fundamental for creating stable, realistic simulations used to train robotic policies via reinforcement learning before sim-to-real transfer.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
The Linear Complementarity Problem (LCP) is a core mathematical formulation within physics engines. These related concepts define the computational pipeline for simulating rigid body dynamics, contact, and constraints.
Constraint Solver
A constraint solver is the algorithmic core of a physics engine that resolves forces and impulses to satisfy physical rules. It takes constraints—such as 'these two bodies should not interpenetrate' or 'this joint should rotate only 90 degrees'—and computes the necessary corrections.
- Primary Role: Enforces non-penetration, joint limits, and friction.
- Mathematical Methods: Often solves a Linear Complementarity Problem (LCP) or a related optimization problem like a Quadratic Program (QP).
- Iterative Nature: Uses solvers like Projected Gauss-Seidel (PGS) to find an approximate solution efficiently for real-time simulation.
Projected Gauss-Seidel (PGS) Solver
The Projected Gauss-Seidel (PGS) solver is an iterative numerical algorithm used to solve constraint problems in physics engines. It is a common, efficient method for handling contact and joint constraints.
- How it Works: It cycles through constraints one by one, projecting the system state onto the feasible set defined by each constraint, repeating until convergence.
- Relation to LCP: PGS is frequently applied to solve the Linear Complementarity Problem formulation of contact. It's favored for its simplicity and good performance with a warm start from the previous frame.
- Use Case: The standard solver in many real-time engines like Bullet and early versions of Havok for simulating stacked boxes and ragdolls.
Contact Generation
Contact generation is the computational process, following narrowphase collision detection, that produces the specific data needed to resolve a collision. This data is the direct input to the constraint solver and LCP formulation.
- Outputs: For each colliding pair, it calculates contact points, penetration depth, contact normal, and often local contact geometry.
- Pre-Solver Role: This stage transforms geometric intersection into a set of mathematical constraints (e.g., non-penetration, friction cone).
- Critical for Fidelity: Accurate contact generation is essential for stable stacking, realistic sliding, and preventing objects from jittering or sinking into each other.
Rigid Body Dynamics
Rigid body dynamics is the branch of mechanics and simulation dealing with the motion of non-deformable objects. The Linear Complementarity Problem arises naturally when modeling the contact forces between such bodies.
- Core Equations: Governed by Newton-Euler equations, which describe translational and rotational motion from forces and torques.
- Contact Challenge: The primary difficulty is calculating the correct contact forces that prevent interpenetration without causing adhesion. This is where the LCP formulation is applied.
- Simulation Pipeline: The dynamics system integrates forces, detects collisions, generates contacts, and uses an LCP solver to compute collision responses before updating body positions.
Featherstone's Algorithm
Featherstone's algorithm refers to a family of O(n) algorithms for efficiently solving the forward and inverse dynamics of articulated multi-body systems, like robotic arms. While it solves joint constraints, it often hands off contact resolution to a separate LCP solver.
- Efficiency: The Articulated Body Algorithm (ABA) computes forward dynamics in linear time relative to the number of joints.
- Domain: Specialized for tree-structured systems with rotational and prismatic joints.
- Integration with LCP: In full physics simulation, Featherstone's algorithm computes motion from applied torques, while a separate constraint solver (solving an LCP) handles contact forces between the robot and its environment.
Deterministic Simulation
A deterministic simulation produces an identical sequence of states when run repeatedly with the same initial conditions and inputs. Achieving this when using LCP solvers is non-trivial but critical for debugging and replay.
- Challenge with LCP: Iterative solvers like PGS may have convergence thresholds and order-dependent operations that can lead to minute, cascading differences.
- Engineering Requirement: For robust sim-to-real training and hardware-in-the-loop testing, engineers must ensure the entire physics pipeline, including the LCP solution, is bit-wise reproducible.
- Methods: Using fixed-precision math, fixed iteration counts, and deterministic constraint ordering.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us