I like the function ConvexHullMesh
very much, since I often need to take a look at the convex hull of points in 2D and 3D, which as an example can be generated and tested with the following code
(*Dimension and number of points*)
d = 2;
np = 10^1;
(*Generate data*)
data = RandomReal[{-1, 1}, {np, d}];
(*Construct convex hull*)
ch = ConvexHullMesh@data;
(*Test new point*)
new = RandomReal[{-1, 1}, d];
Element[new, ch]
True
But just out of fun, I wanted to do this with higher dimensional points, e.g., with 5D points. But how do you construct in Mathematica the convex hull then out of the data and create a set for testing new points?
Answer
As others mentioned, Qhull can do this. There are multiple ways to access Qhull from Mathematica.
One way is through the mPower
package, now part of xCellerator. An answer discussing how to install the package is here: https://mathematica.stackexchange.com/a/18909/12
Another way is the qh-math package, described in this answer: https://mathematica.stackexchange.com/a/13445/12
Yet another way is through MATLAB and MATLink (MATLAB has Qhull built in).
< OpenMATLAB[]
convhulln = MFunction["convhulln"]/*Round
pts = RandomReal[1, {20,5}] (* 20 points in 5D *)
convhulln[pts]
This returns a list of facets encoded as point-index-lists.
Comments
Post a Comment