Skip to main content

Module nearest_point_finding

Module nearest_point_finding 

Source
Expand description

Closest-point queries: the point of a primitive nearest to a query point.

Points and vectors are plain [f64; D] arrays. Every query returns the closest point together with whatever parameterisation is natural for the primitive (a segment parameter, barycentric coordinates, …), and distances are Euclidean. For nearest neighbours within a large point set, build a KdTree instead.

See the book entry Intersections and closest points.

Structs§

Closest
A closest point and its distance from the query.

Functions§

closest_point_on_aabb
The closest point in the axis-aligned box [min, max] (the point itself if inside).
closest_point_on_line
The closest point on the infinite line through origin with direction dir, and its (unclamped) parameter. A zero direction returns origin.
closest_point_on_mesh
The closest point on a triangle mesh (brute force over triangles) with the triangle index. Triangles index into vertices; None for an empty mesh or out-of-range indices.
closest_point_on_plane
The closest point on a plane given by a point on it and a normal (need not be unit); also the signed distance (positive on the side the normal points to). None for a zero normal.
closest_point_on_polygon_boundary
The closest point on the boundary of a closed polygon (its last vertex joins the first).
closest_point_on_polyline
The closest point on a polyline’s segments, with the index of the segment it lies on and the parameter along it. None if there are fewer than two vertices.
closest_point_on_ray
The closest point on the ray from origin along dir (parameter t >= 0).
closest_point_on_segment
The closest point on segment a-b, and its parameter t in [0, 1] (a + t (b - a)). A degenerate segment (a == b) returns a with t = 0.
closest_point_on_sphere
The closest point on the surface of a sphere (the centre direction is arbitrary if p is at the centre: the +x pole is returned).
closest_point_on_triangle
The closest point on the (filled) triangle abc in 3D, with its barycentric coordinates [wa, wb, wc] (non-negative, summing to 1). Works for degenerate triangles too.
closest_points_between_segments
The closest points between segments p1-q1 and p2-q2: (point on first, point on second, distance); the segments may be degenerate (points). Ericson 5.1.9.
distance_point_to_line_3d
The distance from p to the infinite 3D line through a and b (the point distance to a if they coincide).