Interseption of a sphere in a triangular meshed surface

13 visualizaciones (últimos 30 días)
Cristiana Abilheira
Cristiana Abilheira el 1 de Abr. de 2019
Respondida: DGM el 28 de Sept. de 2025 a las 4:32
The problem I'm presenting is very particular.
I have one surface. Wich I get from a STL file. So this surface is triangular and I have the nodal information and face normals in a matrix...
The thing is...
I also have one long matrix with x,y coordinates. Each row represent the center of a circle. I have a value for the radius.
each circle center in the image is represented by the blue dots.
What I need is to know what nodes, if I use a circle with radio=2 aroud each center, what nodes are catched inside each circle. And finally wich triangles share this node.
Please, I really need help here
matanswers.PNG

Respuestas (2)

KSSV
KSSV el 1 de Abr. de 2019
Read about inpolygon.
  1. Draw your circle.
  2. Have (x,y) coordinates of circle in hand.
  3. Use inpolygon
  4. After knowing indices of points lying inside the circle to get the node numbers use ismember

DGM
DGM el 28 de Sept. de 2025 a las 4:32
I'm going to do this with both the mesh and the centers in 3D for sake of generalization. Assuming they all have the same radius, then:
% a triangulated mesh
% this could be from an STL or whatever
% V should be unique
[x y z] = peaks(20);
[F V] = surf2patch(x,y,z/4,'triangles');
% sphere parameters
C = (rand(10,3)-0.5).*[6 6 4]; % centers
r = 0.5; % radius
% find vertices which are within a sphere
% mask is 2D, one row per mesh vertex, one col per sphere
D = pdist2(V,C,'euclidean');
mask = D <= r;
Vs = find(any(mask,2)); % select vertices in any sphere
% find faces which are incident on those vertices
[fidx vidx] = getincidentfaces(F,Vs);
% plot the mesh
patch('faces',F,'vertices',V, ...
'facecolor',[1 1 1]*0.8,'edgecolor','k','facealpha',0.5);
view(3); view(-35,45); axis equal; grid on; hold on
% draw the sphere centers
plot3(C(:,1),C(:,2),C(:,3),'r.','markersize',20)
% draw the selected faces
patch('faces',F(fidx,:),'vertices',V, ...
'facecolor',[1 1 0]*0.5,'edgecolor','k','facealpha',0.5);
% draw the selected vertices
plot3(V(Vs,1),V(Vs,2),V(Vs,3),'y.','markersize',10)
If the spheres have different radii, then r should be a row vector of length of size(C,1).
If you want to deal with a specific sphere instead of any sphere, then arrange the conditionals accordingly.
If you want to keep track of which vertices bound the selected faces, then use vidx, as F(fidx(k),:) is a triangle incident on the vertex V(vidx(k),:).

Community Treasure Hunt

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

Start Hunting!

Translated by