Skip to main content

Module distance

Module distance 

Source
Expand description

Signed distances from many points to a mesh or a shape.

to_mesh measures to a triangle mesh through its Bvh, and to_shape to a B-rep’s own surfaces, curves and points, never to a tessellation of them. Both answer every point independently, in parallel, in the points’ order, and the same points give the same answers bit for bit on any thread count.

§The sign

A distance is positive outside and negative inside. On a mesh the side is read from the closest feature’s angle-weighted pseudonormal: the triangle’s normal where the closest point is inside a triangle, the sum of the two triangles’ normals where it is on an edge, and the sum of the triangles’ normals at a vertex weighted by their corner angles there. For a closed, consistently wound mesh the displacement from the closest point to the query lies in that feature’s normal cone, and its dot with the pseudonormal has the sign of the side, so a point beside an edge or a corner is never read on the wrong side. Corners that share a position are one vertex, so a mesh written with its vertices repeated per face reads as the surface it draws.

On a shape the side is the face’s own: the oriented normal at the foot where the closest point is inside a face, the sum of the faces’ normals where it is on an edge (the displacement then lies in the plane across the edge, between the two normals outside or their opposites inside), and the solid’s own classification of the point where it is at a vertex. A shape with no closed boundary, or a point the classification puts on it, reads a vertex by the sum of its faces’ normals.

§Facing

With DistanceOptions::facing_limit, each point carries a normal of its own (a scan’s) and only surface turned within the limit of it is measured to: on a mesh, the triangles whose normals are; on a shape, the face feet whose normals are, and the edges and vertices where one of their faces’ normals is. The nearest of what is left is the answer, so a point scanned on one side of a thin wall reads that side however near the other is. The test is on cosines, n·m ≥ cos(limit) for unit normals, so a surface exactly at the limit is in when the rounding of the cosine allows. The sign is still the side of the feature the answer lies on, read as above.

Structs§

Closest
What a point is nearest to.
DistanceOptions
How to_mesh and to_shape measure.

Enums§

MeshFeature
A feature of a triangle mesh, by a triangle that has it.
ShapeFeature
A feature of a shape: the face, edge or vertex the closest point lies on, as the shape holds it.

Functions§

to_mesh
The signed distance from each point to the mesh index was built over, with the closest point, the feature it lies on and the normal there; in the points’ order, None where nothing is within DistanceOptions::max.
to_shape
The signed distance from each point to shape‘s faces, edges and vertices, measured on their own surfaces, curves and points, with the closest point, the feature it lies on and the normal there; in the points’ order, None where nothing is within DistanceOptions::max.