Finding equations of planes of Convex Hull in MATLAB

115 Views Asked by At

I am new to MATLAB. I want to find the equations of a set of planes that are part of a convex hull that I calculated using convhulln. It is a convex polyhedron. I tried to search quite a bit but couldn't find anything. Any help is appreciated.

Here's a set of points that I find the convex hull of. The code is not in MATLAB but can be understood easily. All points are 3D points.

pts = {{-0.00033004023134713956, 0, 0},{-0.00033004023134713956, -0.001, 0},
{0.00033004023134713956, -0.001, 0},{0.00033004023134713956, -0.00033004023134713956, 0},
{0,0,0},{-0.00033004023134713956, 0.001, -0.00033004023134713956},{0.00033004023134713956, 
0.001, 0.00033004023134713956},{0.00033004023134713956, 0, 0.00033004023134713956},
{-0.00033004023134713956, 0.00033004023134713956, -0.00033004023134713956},{0,0,0},
{-0.00033004023134713956, 0, 0},{-0.00033004023134713956, 0.00033004023134713956, 
-0.00033004023134713956},{0,0,0},{0.00033004023134713956, 0, 0.00033004023134713956},
{0.00033004023134713956, -0.00033004023134713956, 0},{0,0,0}};
1

There are 1 best solutions below

0
On

first you need to convert your data to a N-by-3 numerical array:

pts = ...
[[-0.00033004023134713956, 0, 0]; [-0.00033004023134713956, -0.001, 0]; ...
[0.00033004023134713956, -0.001, 0];...
[0.00033004023134713956, -0.00033004023134713956, 0]; [0,0,0];...
[-0.00033004023134713956, 0.001, -0.00033004023134713956];...
[0.00033004023134713956, 0.001, 0.00033004023134713956];...
[0.00033004023134713956, 0, 0.00033004023134713956];...
[-0.00033004023134713956, 0.00033004023134713956, -0.00033004023134713956];...
[0,0,0]; [-0.00033004023134713956, 0, 0];...
[-0.00033004023134713956, 0.00033004023134713956, -0.00033004023134713956];...
[0,0,0];[0.00033004023134713956, 0, 0.00033004023134713956];...
[0.00033004023134713956, -0.00033004023134713956, 0];[0,0,0]];

(numerical arrays are defined with brackets, use semicolon to separate rows)

Then you can call the convhulln function

K = convhulln(pts);

The result is a NF-by-3 array containing indices of polyhedron faces. To get the origin and the direction vectors of plane containing the first face, you can process as is:

indF = 1;
pnt1 = pts(K(indF, 1), :);
pnt2 = pts(K(indF, 2), :);
pnt3 = pts(K(indF, 3), :);
origin = pnt1;
vect1 = pnt2 - pnt1;
vect2 = pnt3 - pnt1;