Skip to main content

mean_value_coordinates3

Function mean_value_coordinates3 

Source
pub fn mean_value_coordinates3(
    vertices: &[Point3],
    faces: &[[usize; 3]],
    point: Point3,
    tolerance: Tolerance,
) -> Result<Vec<Scalar>, BarycentricError>
Expand description

Mean-value coordinates of point in a closed triangle mesh, one weight per vertex (Floater, Kos and Reimers 2005).

faces lists each triangle as three indices into vertices. The mesh’s closedness (every edge shared by exactly two faces, consistently wound) is the caller’s responsibility, same as mean_value_coordinates2 leaves polygon repair to its caller: this function does not audit topology, only computes weights from the faces given. On a vertex, that vertex alone gets weight one. When point lies exactly on a face’s plane, inside that triangle, the weights are that triangle’s own 2D barycentric coordinates (all other vertices zero) – the formula’s own closed form for the coplanar case, not a fallback. Elsewhere on a face’s plane but outside its triangle, that face contributes nothing (its spherical angles fold flat without enclosing point); a mesh with no other face to carry the point returns BarycentricError::Undefined.

§Errors

BarycentricError::NonFinite for a non-finite vertex or point, BarycentricError::TooFewVertices for fewer than three vertices or no faces, BarycentricError::VertexIndex for a face naming a vertex index past the end of vertices, and BarycentricError::Undefined where the weights do not sum to a nonzero, finite total.