Skip to content

Pseudo code

Harsha KC edited this page Jul 28, 2016 · 2 revisions

Welcome to the closest-point-on-mesh wiki! Here is the pseudo code for the solution

If a point has to lie on a mesh, it should belong to any one of the following categories:

  • Point is a vertex of the mesh
  • Point lies on an edge of the mesh
  • Point lies in the interior of a triangle in the mesh

Our algorithm finds the distance from the query point (within the search radius) to all these three categories and returns the minimum distance, else returns Infinity.

Point ClosestPoint (Mesh M,Point p, float maxRadius)

    min_vertex_distance = for v in vertices : min_distance(p,i)

    min_edge_distance   = for e in edges    : min_distance(p,e)

    min_face_distance   = for f in faces    : min_distance(p,f)

return min (min_vertex_distance , min_edge_distance, min_face_distance)
Clone this wiki locally