How to place/ define points on a triangulated meshed surface?

24 views (last 30 days)
Hello all,
I need your help and ideas to solve the following problem.
I have a surface that is meshed with triangles. I know the positions of the nodes, as well as the normal vector of the node and the surfaces (as a unit vector).
For example, the surface looks like this:
However, the surface can also be round, have holes in it or have a completely free external shape. In extreme cases, the surface is even curved in space (e.g. like a spherical surface).
I would now like to place as many cylinders as I want on this surface, which always have the maximum distance from each other.
Does anyone know how this can be done?
Or how can I find and define points on this "surface"?
Many thanks and greetings
Tom Engels
Tom Engels on 9 Aug 2021
Edited: Tom Engels on 9 Aug 2021
The following cases represent an example of an extreme case:
For one cylinder, I determine the centroid of the surface and use the local curvature to check whether I could place it there.

Sign in to comment.

Accepted Answer

darova on 14 Aug 2021
Here is another approach, but works only if you don't have points inside:
  • pick a point inside a contour (center)
  • convert data into polar coordinates
  • sort by angle
coord = load('coordVERTICIES.mat');
coordVERTICES = coord.coordVERTICES;
xco = coordVERTICES(:,1,:);
yco = coordVERTICES(:,2,:);
zco = coordVERTICES(:,3,:);
[x,y,z] = deal(xco(:),yco(:),zco(:));
[t,r] = cart2pol(x-mean(x),y-mean(y)); % convert to polar system
[~,k] = sort(t); % sort angle
x1 = x(k);
y1 = y(k);
dl = hypot(diff(x1),diff(y1)); % find distance between points
k1 = find(dl > 0.01); % remove zero distances (duplicate points)
gd = [2;numel(k1);x1(k1);y1(k1)]; % geom descr
dl = decsg(gd); % decomposition
[p,e,t] = initmesh(dl); % build a new mesh
plot(x,y,'.g') % plot all points
hold on
plot(x(k),y(k)) % plot boundary curve
pdemesh(p,e,t) % plot mesh
plot(mean(x),mean(y),'ob','markersize',15,'linewidth',3) % center of a figure
hold off
axis equal tight
  1 Comment
Tom Engels
Tom Engels on 16 Aug 2021
Hello darova,
thank you very much for your good support. With this idea, I can definitely serve all flat surfaces without interruptions.

Sign in to comment.

More Answers (2)

darova on 9 Aug 2021
How about simple griddata with using initmesh
t = 0:.2:5;
x = [t; t]; % some data
y = [t*0; t*0+3]; % some data
z = [sin(t); sin(1.2*t)]; % some data
k = boundary(x(:),y(:)); % simply find only boundary
x1 = x(k(2:end)); % boundary should be unclosed curve
y1 = y(k(2:end)); % boundary should be unclosed curve
gd = [2;numel(x1);x1(:);y1(:)]; % geometry description
dl = decsg(gd); % decomposition
[p,e,t] = initmesh(dl,'Hmax',0.1);% build a mesh (control mesh size)
z2 = griddata(x(:),y(:),z(:),p(1,:),p(2,:)); % find Z coordinate for each point
pp.vertices = [p' z2(:)]; % create struct for patch
pp.faces = t(1:3,:)'; % create struct for patch
pp.facecolor= 'r'; % create struct for patch
h1 = plot3(x,y,z,'.-g');
h2 = patch(pp);
legend([h1(1) h2],'original data','gridata/initmesh')
axis equal
Work with cartesian/spherical system of coordinates to manipulate elements of a spherical objects
darova on 12 Aug 2021
Edited: darova on 12 Aug 2021
Here is another example with using feeBoundary. It find free edges. The problem with separating outer and inner edges remains.
% generating the data
t = linspace(0,2*pi,50);
[x1,y1] = pol2cart(t,1); % inner curvw
x2 = 2*x1 + 0.2*cos(5*t); % outer curve
y2 = 2*y1 + 0.2*sin(5*t);; % outer curve
x = zeros(numel(x1),10); % preallocation
y = x;
for i = 1:numel(x1)
x(i,:) = linspace(x1(i),x2(i),10); % create nodes between curves
y(i,:) = linspace(y1(i),y2(i),10);
h = surf(x,y,x*0); % create surface object
p = surf2patch(h,'triangles'); % conver surface object to patch
TR = triangulation(p.faces,p.vertices); % trinagulation
v = p.vertices;
E = freeBoundary(TR); % find boundary edges
p.vertices(:,1) = p.vertices(:,1) + 5; % move patch object
patch(p,'facecolor','r') % display triangles
line(v(E,1)+5,v(E,2),'color','g','linewidth',2) % ree boundary
axis equal

Sign in to comment.

Tom Engels
Tom Engels on 13 Aug 2021
Hello davora. Thank you for your answer and help. I am currently creating the network from the data in the .stl file as follows:
coord = load('coordVERTICIES.mat')
coordVERTICES = coord.coordVERTICES;
xco = squeeze( coordVERTICES(:,1,:) )';
yco = squeeze( coordVERTICES(:,2,:) )';
zco = squeeze( coordVERTICES(:,3,:) )';
axis equal tight
Unfortunately, if I understand the freeboundary command correctly, it is limited to meshing a two-dimensional surface. The consideration of curvatures would therefore unfortunately not be possible.
Do you have any idea how I could create points on the surface efficiently in a different way?
Greetings Tom


Find more on Triangulation Representation in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!