Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query volume of artifical blocks inside a convex hull

Problem:

I have a three-dimensional point cloud each centroid of a block representing a block. For simplicity this example is just two dimensional. As illustrated in the picture I want to include blocks of interest, based on a parameter. In the case here block 1,6,5,4. In order to further process them i need to find the smallest hull around them by either using an alpha shape or a convex hull. I have the coordinates of every centroid and i know the block extension so I can find easily the edge point of the blocks by:

    xdimension=5;
ydimension=5;
block1=[5 15 1];
block2=[5 10 0];
block3=[5 5 0];
block4=[10 5 1];
block5=[10 10 1];
block6=[10 15 1];
block7=[15 5 0];
block8=[15 10 0];
block9=[15 15 0];
blocks=[block1;block2;block3;block4;block5;block6;block7;block8;block9]

dimension=[xdimension/2 ydimension/2];
point1=[1 1].*dimension;
point2=[1 -1].*dimension;
point3=[-1 1].*dimension;
point4=[-1 -1].*dimension;
i=size(blocks,1);
point1=repmat(point1,i,1);
point2=repmat(point2,i,1);
point3=repmat(point3,i,1);
point4=repmat(point4,i,1);
edges1=[blocks(:,1:2)+point1, blocks(:,3)] ;
edges2=[blocks(:,1:2)+point2, blocks(:,3)];
edges3=[blocks(:,1:2)+point3, blocks(:,3)];
edges4=[blocks(:,1:2)+point4, blocks(:,3)];
edges=[edges1;edges2;edges3;edges4];
x=edges(edges(:,3)==1,1);
y=edges(edges(:,3)==1,2);
K=convhull(x,y)
scatter(edges(:,1), edges(:,2))
hold on
plot(x(K),y(K),'r-')
hold off

This produces a picture similar to the one here.

Question

How can I query the surface (or in my real problem the volume) that is included by the convex hull of block 2 and 3 ? I need the exact surface/ volume of every individual block included apart from those that I specify to be in (here with the binary indicator). Please note that this is an example and I am looking for ideas how to do this independant of the example. I would really appreciate some help, cause I a majorly stuck here and I have no idea how to tackle it.

enter image description here

like image 439
KiW Avatar asked Nov 09 '22 08:11

KiW


1 Answers

In 2D I would use the inpolygon function to test if a point is inside the intersection of the convex Hull and squares 2 and 3.

For 3D I didn't found an equivalent in MATLAB but the following matlab exchange file supposed to be the solution.

An example of how to use the function inhull to find the points of the areas inside:

% Create a 3D cube
cubePoints = randi(5,[500,3]);

% Bounding volume
boundingVolume = zeros(8,3);
boundingVolume(1,:) = [1,3,1];
boundingVolume(2,:) = [1,3,3];
boundingVolume(3,:) = [3,3,1];
boundingVolume(4,:) = [3,3,3];
boundingVolume(5,:) = [3,1,3];
boundingVolume(6,:) = [3,1,1];
boundingVolume(7,:) = [2,1,1];
boundingVolume(8,:) = [2,1,3];

% Find points inside area
inVol = inhull(cubePoints,boundingVolume);

% Plot the point in the bounding volume in blue and the points outsode the
% bounding volume in red
scatter3(cubePoints(:,1).*inVol,cubePoints(:,2).*inVol,cubePoints(:,3).*inVol,36,'blue');
hold on
scatter3(cubePoints(:,1).*~inVol,cubePoints(:,2).*~inVol,cubePoints(:,3).*~inVol,36,'red');
like image 125
Amitay Nachmani Avatar answered Dec 10 '22 12:12

Amitay Nachmani