Alec JacobsonandClaude Opus 5 c678e8658b Squared distance between two simplices (#2548)
Adds igl::simplex_simplex_squared_distance, which computes the squared
distance between the closest pair of points on two simplices along with
the barycentric coordinates of that pair. The simplices may have
different sizes (point, segment, triangle, tet, ...) and may be
degenerate; they only have to share a dimension.

Ported from gptoolbox's simplex_simplex_squared_distance.m. The
algorithm parameterizes both affine hulls, finds their closest pair by
minimum-norm least squares, and recurses over codimension-one facets
when that pair falls outside either simplex. The affine-hull distance is
a lower bound for the whole subproblem, so it doubles as a pruning test.

The implementation is templated on the corner counts so that statically
sized inputs (e.g. Matrix3d in, Vector3d out) unroll into fixed-size
linear algebra with no heap allocation. Faces are represented as
bitmasks and memoized, which is exact here because the running best only
decreases: a face pair that was pruned once stays pruned, and one that
was explored cannot improve on a second visit. A closest-corner seed and
a per-node bounding-box bound give the pruning test something to bite
on, and single-unknown nodes use the closed-form projection, which is
already the minimum-norm solution.

Relative to a straightforward dynamically sized recursion this is ~14x
faster for triangle-triangle queries on Matrix3d, ~74x for tet-tet, and
~5x even for MatrixXd, with zero allocations on the static path.

Tested against analytic point/segment/triangle/tet cases, degenerate
simplices, mixed and fixed-size scalar types, and an exhaustive
unpruned enumeration of every face-pair subproblem over random inputs.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 12:23:39 -04:00
2026-04-04 14:43:44 -04:00
2023-09-02 10:44:09 -04:00
2026-04-04 14:43:44 -04:00
2014-06-17 16:26:13 -04:00
2013-11-25 14:20:30 +01:00
2013-11-25 14:20:30 +01:00
2023-08-16 13:15:48 -04:00

libigl - A simple C++ geometry processing library

Documentation, tutorial, and instructions at https://libigl.github.io.

🆕 Doxygen Documentation
The latest version of libigl (v2.5.0) introduces doxygen generated detailed documentation
S
Description
No description provided
Readme
375 MiB
Languages
C++ 96.4%
CMake 2.6%
C 1%