MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/TriangleMeshDistance

github.com/InteractiveComputerGraphics/TriangleMeshDistance @v1.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.0 ↗ · + Follow
1,195 symbols 2,192 edges 4 files 47 documented · 4% updated 5mo agov1.1.0 · 2025-12-11★ 180

Browse by type

Functions 858 Types & classes 337
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

TriangleMeshDistance

Header only, single file, simple and efficient C++11 library to compute the signed distance function (SDF) to a triangle mesh.

The distance computation to the triangle collection is accelerated with a sphere bounding volume hierarchy. The sign of the distance is resolved with the method presented in "Generating Signed Distance Fields From Triangle Meshes" by Bærentzen, Andreas & Aanæs, Henrik. (2002).

Assuming triangle normals point outwards from the enclosed volume, the sign of the distance will be positive outside and negative inside.

Example

// Declare mesh vertices and triangles
std::vector<std::array<double, 3>> vertices;
std::vector<std::array<int, 3>> triangles;

// (... fill the `vertices` and `triangles` with the mesh data ...)

// Initialize TriangleMeshDistance
tmd::TriangleMeshDistance mesh_distance(vertices, triangles);

// Query TriangleMeshDistance
tmd::Result result = mesh_distance.signed_distance({ x, y, z });

// Print result
std::cout << "Signed distance: " << result.distance << std::endl;
std::cout << "Nearest entity: " << result.nearest_entity << std::endl;
std::cout << "Nearest triangle index: " << result.triangle_id << std::endl;
std::cout << "Nearest point: " << result.nearest_point << std::endl;
std::cout << "Nearest point barycentric coordinates: " << result.barycentric << std::endl;

What you need to know about TriangleMeshDistance

  • The input triangle mesh must be fully connected and watertight. Triangle soups and meshes with holes will return the correct distance but the sign will be undefined.
  • Triangle winding (consistent normals orientation) is not verified. The input mesh is required to have consistent normals.
  • TriangleMeshDistance keeps a copy of the vertex and triangle data.
  • The pseudonormals required to compute signed distances are calculated and stored at building time.
  • TriangleMeshDistance can be declared empty and constructed multiple times with different meshes. If the new mesh needs less memory than the curent one, memory allocations will be avoided.

Projects using TriangleMeshDistance

  • Discregrid - A static C++ library for the generation of discrete functions on a box-shaped domain. This is especially suited for the discretization of signed distance fields.
  • PBD - A C++ library for physically-based simulation of rigid bodies, deformables, cloth and fluids using Position-Based Dynamics.
  • SPlisHSPlasH - A C++ library for the physically-based simulation of fluids using Smoothed Particle Hydrodynamics.

Core symbols most depended-on inside this repo

Shape

Method 728
Class 312
Function 130
Enum 25

Languages

C++100%

Modules by API surface

tests/catch.hpp1,163 symbols
TriangleMeshDistance/include/tmd/TriangleMeshDistance.h31 symbols
tests/tests.cpp1 symbols

For agents

$ claude mcp add TriangleMeshDistance \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page