Skip to main content

mesh_distance

Function mesh_distance 

Source
pub fn mesh_distance(
    mesh_a: &Mesh,
    bvh_a: &Bvh,
    mesh_b: &Mesh,
    bvh_b: &Bvh,
    xf: &Rigid,
    max_distance: f32,
) -> Result<Option<MeshDistance>>
Expand description

The minimum distance between the surfaces of A and B, with B placed in A’s space by xf, and a closest pair of points. None when the distance is greater than max_distance, or when either mesh has no alive triangle.

max_distance is inclusive and may be infinite; it is compared as f64 distance <= f64::from(max_distance). Positive distances are computed in f64 from B’s vertices as transformed by xf, and are exact up to rounding. Among pairs of triangles at the same minimum distance (equal squared distance in f64), the smallest (triangle_a, triangle_b) wins.

A distance of 0 means the meshes touch, intersect, or are closer than f64 rounding resolves: a positive gap whose computed distance rounds to 0 is reported as 0. The search stops at the first pair of triangles with distance 0 that it finds. That pair intersects (decided exactly) or has a computed distance of 0; it is not necessarily the smallest such pair, and its two points coincide up to rounding. Use intersecting_pairs for every intersecting pair.

Both points are in A’s space; see MeshDistance. Passing the same mesh twice means two coincident copies, as for intersects.

§Errors

QueryError::InvalidInput for an invalid xf (see Rigid) or a max_distance that is negative or NaN; then QueryError::MeshMismatch or QueryError::StaleBvh as for intersects.