-->

Intersecting Volume in Matlab

2020-06-26 19:10发布

问题:

I have developed a code that takes a set of 3D coords, and performs triangulation to generate the convex hull/Delaunay .

This has gone well and using the Deluanay triangulation I can test whether points are contained in a given volume using tsearchn.

Now I want to take two of such 3D volumes, and test whether they intersect. Futhermore I would like to know what the percentage of volume A is intersected by Volume B.

I think that I could generate a mesh grid of points that are within one of the volumes, then test them into the other using tsearchn. But I wanted to know if anyone knows of more convenient way. Or has advice for doing similar analyses.

Many Thanks!

EDIT ... Example Code

For this sample code, shapeA would be 50% intersected by shapeB.
I included a section at the end of the code that shows the usability of tsearchn
I know that I could solve my problem by increasing the number of points for the shapes and testing them using tsearchn

% Establish shapes by coordinates
botA = [ 0 0 0 ; ...
   1 0 0;  ...
   1 1 0;  ...
   0 1 0 ];

topA = botA; topA(:,3) = 1; 
midA = [0.5 0.5 0.5];

botB = [ 0 0 0.5 ; ...
   1 0 0.5;  ...
   1 1 0.5;  ...
   0 1 0.5 ];

topB = botA; topB(:,3) = 1.5; 
midB = [0.5 0.5 1];

% Shape arrays
shapeA = [botA;midA;topA];
shapeB = [botB;midB;topB];

% Establish volume by using the delaunayn() function
dtA = delaunayn(shapeA);
dtB = delaunayn(shapeB);

% Plot the volume surfaces 
shapesurfA=tetramesh(dtA,shapeA);
set(shapesurfA,'FaceColor','b','FaceAlpha',.90,'EdgeAlpha',1);

hold on
shapesurfB=tetramesh(dtB,shapeB);
set(shapesurfB,'FaceColor','y','FaceAlpha',.90,'EdgeAlpha',1);
hold off
axis equal

%example of point in volume test
%if tsearchn output = NaN then testpoint is not in volume
testpoint1 = tsearchn(shapeA,dtA, [ 2 2 2]) % [test point [2 2 2] in volume A
testpoint2 = tsearchn(shapeA,dtA, [0.75 0.75 0.75])