Loren Petrich has done a wonderful job of implementing quite a few convex hull algorithms in Mathematica, and you can get all of his original code from his website. Since it is written under the MIT license I took the liberty of wrapping the code relevant to an N-dimensional convex hull into a package.
Included are the functions CHNGiftWrapping, CHNChanShattering, CHNQuickHull, and CHNIncremental, which use the gift wrapping algorithm, Chan's algorithm, quick hull, and the incremental algorithms, respectively.
All these functions work the same, they take a list of N-dimensional vertices and return a sorted list of vertices which make up the hull and a list of simplexes.
(* load the package *)
<<"https://gist.githubusercontent.com/jasondbiggs/c3d9410af3195da514a442be5b563ab8/raw/80ac5074077f0d4b1366540c8c710e35cb530ddd/NDConvexHull.m"
Here I apply the quick hull function to a list of 4-dimensional points:
SeedRandom[4];
list = RandomReal[5, {50, 4}];
CHNQuickHull[list]
(* {{2, 3, 7, 8, 11, 12, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
26, 27, 28, 29, 31, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 45, 46,
47, 48, 49,
50}, {{2, 15, 21, 47}, {2, 15, 47, 50}, {2, 15, 50, 21}, {2, 21, 35,
47}, {2, 21, 50, 35}, {2, 22, 35, 50}, {2, 22, 47, 35}, {2, 22,
50, 47}, {3, 16, 17, 22}, {3, 16, 22, 49}, {3, 16, 49, 17}, {3, 17,
49, 22}, {7, 22, 29, 35}, {7, 22, 34, 49}, {7, 22, 35, 34}, {7,
22, 36, 29}, {7, 22, 49, 36}, {7, 29, 34, 35}, {7, 29, 36, 49}, {7,
29, 49, 34}, {8, 16, 17, 49}, {8, 16, 18, 24}, {8, 16, 24,
17}, {8, 16, 49, 18}, {8, 17, 20, 32}, {8, 17, 24, 20}, {8, 17, 32,
49}, {8, 18, 20, 24}, {8, 18, 23, 20}, {8, 18, 29, 37}, {8, 18,
36, 23}, {8, 18, 37, 36}, {8, 18, 49, 29}, {8, 20, 23, 33}, {8, 20,
33, 41}, {8, 20, 41, 32}, {8, 23, 36, 33}, {8, 29, 49, 37}, {8,
32, 33, 36}, {8, 32, 36, 49}, {8, 32, 41, 33}, {8, 36, 37,
49}, {11, 12, 15, 23}, {11, 12, 17, 40}, {11, 12, 18, 42}, {11, 12,
21, 45}, {11, 12, 23, 18}, {11, 12, 40, 21}, {11, 12, 42,
17}, {11, 12, 45, 15}, {11, 15, 18, 23}, {11, 15, 21, 26}, {11, 15,
26, 27}, {11, 15, 27, 18}, {11, 15, 45, 21}, {11, 16, 17,
24}, {11, 16, 19, 28}, {11, 16, 21, 40}, {11, 16, 24, 19}, {11, 16,
28, 21}, {11, 16, 40, 17}, {11, 17, 42, 24}, {11, 18, 19,
24}, {11, 18, 24, 42}, {11, 18, 27, 29}, {11, 18, 29, 19}, {11, 19,
29, 46}, {11, 19, 35, 28}, {11, 19, 46, 35}, {11, 21, 28,
35}, {11, 21, 35, 38}, {11, 21, 38, 26}, {11, 26, 38, 27}, {11, 27,
38, 46}, {11, 27, 46, 29}, {11, 35, 46, 38}, {12, 15, 23,
45}, {12, 17, 20, 42}, {12, 17, 40, 45}, {12, 17, 45, 20}, {12, 18,
42, 23}, {12, 20, 23, 42}, {12, 20, 45, 23}, {12, 21, 45,
40}, {15, 18, 23, 27}, {15, 21, 26, 50}, {15, 21, 47, 45}, {15, 23,
36, 27}, {15, 23, 45, 48}, {15, 23, 48, 36}, {15, 26, 27,
38}, {15, 26, 38, 50}, {15, 27, 36, 50}, {15, 27, 50, 38}, {15, 31,
36, 47}, {15, 31, 47, 50}, {15, 31, 50, 36}, {15, 36, 48,
47}, {15, 45, 47, 48}, {16, 17, 21, 40}, {16, 17, 22, 47}, {16, 17,
47, 21}, {16, 18, 19, 29}, {16, 18, 24, 19}, {16, 18, 29,
49}, {16, 19, 21, 35}, {16, 19, 28, 21}, {16, 19, 34, 29}, {16, 19,
35, 34}, {16, 21, 47, 35}, {16, 22, 34, 35}, {16, 22, 35,
47}, {16, 22, 49, 34}, {16, 29, 34, 49}, {17, 20, 32, 47}, {17, 20,
42, 24}, {17, 20, 47, 45}, {17, 21, 40, 47}, {17, 22, 32,
49}, {17, 22, 47, 32}, {17, 40, 45, 47}, {18, 20, 24, 42}, {18, 20,
42, 23}, {18, 23, 27, 37}, {18, 23, 37, 36}, {18, 27, 29,
37}, {19, 21, 35, 28}, {19, 29, 35, 34}, {19, 29, 46, 35}, {20, 23,
33, 41}, {20, 23, 41, 45}, {20, 32, 47, 41}, {20, 41, 47,
45}, {21, 26, 50, 38}, {21, 35, 38, 50}, {21, 40, 47, 45}, {22, 29,
35, 36}, {22, 31, 36, 50}, {22, 31, 47, 36}, {22, 31, 50,
47}, {22, 32, 36, 47}, {22, 32, 49, 36}, {22, 35, 50, 36}, {23, 27,
37, 36}, {23, 33, 41, 36}, {23, 36, 41, 48}, {23, 41, 45,
48}, {27, 29, 36, 38}, {27, 29, 37, 36}, {27, 29, 38, 46}, {27, 36,
50, 38}, {29, 35, 36, 38}, {29, 35, 38, 46}, {29, 36, 49,
37}, {32, 33, 36, 41}, {32, 36, 47, 48}, {32, 36, 48, 41}, {32, 41,
48, 47}, {35, 36, 38, 50}, {41, 45, 48, 47}}} *)
You can verify that they all produce the same results:
CHNAlgorithms = {CHNGiftWrapping, CHNChanShattering,
CHNQuickHull, CHNIncremental};
SameQ[Through[CHNAlgorithms][list]]
(* True *)
LinearOptimizationlike I did in this answer – flinty May 05 '23 at 11:43