If the point is in the convex hull, the nearest point is itself. Otherwise, the nearest point is the nearest point on any face.
nearest_in_convex_hull(point, hull):
if point_is_in_convex_hull(point, hull):
return 0
else:
return min(nearest_on_face(point, face) for face in hull.faces, lambda p: return distance(point, p))
nearest_on_face(point, face):
return min(face.vertices +
[nearest_on_edge(point, edge) for edge in face.edges] +
nearest_on_plane(point, Plane(face.vertices))
nearest_on_edge and nearest_on_plane to be implemented...
If the point is in the convex hull, the nearest point is itself. Otherwise, the nearest point is the nearest point on any face.
nearest_on_edge
andnearest_on_plane
to be implemented...