title: Computing the distance to a convex hull
body: <p>I am using the <a href="https://scipy.github.io/devdocs/generated/scipy.spatial.ConvexHull.html" rel="nofollow noreferrer">ConvexHull</a> class of scipy to construct a convex hull for a set of points. I am interested in a way to compute the minimum distance of a new point <em>P</em> from the convex hull.</p>
  
  <p>With the help of the internet and a little tweaking by myself I came up with this formula to compute the distance of a point <em>P</em> or a set of points <em>points</em> to the convex hull facets:</p>
  
  <pre><code>np.max(np.dot(self.equations[:, :-1], points.T).T + self.equations[:, -1], axis=-1)
  </code></pre>
  
  <p>For a convex hull in 2D the equation above will result in the following plot:</p>
  
  <p><a href="https://i.stack.imgur.com/MRM2n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MRM2n.png" alt="Distance to Convex Hull"></a></p>
  
  <p>As you can see the result is pretty good and correct for points within the convex hull (The distance here is negative and would need to be multiplied with <em>-1</em>). It is also correct for points that are closest to a facet but incorrect for points that are closest to a vertex of the convex hull. (I marked these regions with the dashed lines) For these points the correct minimum distance would be the minimum distance to the convex hull vertices.</p>
  
  <p>How can I distinguish between points that are closest to a facet or closest to a vertex to correctly compute the minimum distance to the convex hull for a point <em>P</em> or a set of points <em>points</em> in an n-Dimensional space (At least 3D)?</p>