How to extract intersection between two 3D shapes

56 views (last 30 days)
I have a two 3D shapes, one defined by a patch object, the other by a simple analytical function (in my case a sphere):
[verts, faces, cindex] = teapotGeometry;
sphere_origin = [1 1 1];
sphere_radius = 1;
figure;
p = patch('Faces',faces,'Vertices',verts,'FaceVertexCData',cindex,'FaceColor','interp');
sph = drawSphere([sphere_origin sphere_radius]); % using matGeom (https://github.com/mattools/matGeom)
I'd like a way to slice the patch into 2 or more sub-objects that contains the part of the teapot outside the sphere, and the one that is inside.
My main problems are that I don't know:
  1. How to find the exact intersection between the sphere and the 3D shape (not just the closest vertice, but the extrapolated one). (DONE: using surfaceintersection as @darova suggested)
  2. How to add the faces to the extrapolated vertices in a way that conserve the integrity of the teapot if i were to plot only the sub-objects found.
I suppose the right way to start is to find the faces that are intersecting the sphere like this:
out_pnt = find(vecnorm(verts-sphere_origin,2,2)>=sphere_radius);
out_faces = any(ismember(faces,out_pnt),2);
But going from there to finding the exact set of points that define the intersection is really difficult for me right now.
Any part of the answer could really help me, thanks in advance.
  10 Comments
hagege ruben
hagege ruben on 12 Jul 2020
This seems like the function I need, too bad it's not available...
Joseph Olson
Joseph Olson on 21 Feb 2022
Seems like the inShape function is what you want!
https://www.mathworks.com/matlabcentral/answers/496500-intersection-volume-of-two-3d-alphashapes

Sign in to comment.

Answers (0)

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!