How to fill 2-D closed loops with lines? Boundary of this closed loops are extracted as output from slicing a STL file.

10 views (last 30 days)
My main task is to slice STL file and generation of tool path into MATLAB for Laser metal deposition process.I have a list of polylines for each layer which I got after slicing a STL file in MATLAB. Now I have to develop the algorithm for filling these polygons using lines. I have to define the internal filling pattern for 2D closed-contour. so at the end I just want to fill this 2D closed loops with lines. IS there any functions, algorithms or opensource library for this work in MATLAB available? Each and every help will be appreciated as it is the first step of my new project.
  8 Comments
yogi patel
yogi patel on 3 Sep 2018
I am really really thankful to you for this help. But as I am out of institute for few days didn’t get chance to try that and work on it.But I am damn sure that I will make my logic from this code. Once again thank you so much..will get back to you for further assist.?

Sign in to comment.

Accepted Answer

jonas
jonas on 1 Sep 2018
Edited: Matt J on 11 Mar 2021
I'm not one hundred percent certain this is exactly what you are looking for, but this algorithm does the following:
  • Creates a hatched pattern on a surface with slope and distance between lines specified by k and m, respectively.
  • Finds the line-segments inside of a specified polygons and plots those
Polygons with holes are a bit problematic, but I'm sure you can adapt this code to include also those.
% Define hatched pattern
f = @(m,k,x) m+k*x
m=-2:0.1:2; %Vert. distance between lines = .1
k=2; % Slope
x=0:0.001:1;
L=cell(length(m),1);
for i=1:length(m)
L{i}=f(m(i),k,x);
end
% Define polygon
xp{1} = [.5 1 1 .5 .5]./2;
yp{1} = [.5 .5 1 1 .5]./2;
xp{2} = [.7 1 1 .7]-0.2;
yp{2} = [.7 .5 1 .7];
% Plot
ax = axes
hold on
ax.XLim=[0 1];
ax.YLim=[0 1];
% Draw polygon
cellfun(@(X,Y) plot(X,Y,'k'),xp,yp)
% Find points inside and draw those line segments
for i=1:length(xp)
in = cellfun(@(y)inpolygon(x,y,xp{i},yp{i}),L,'uniformoutput',false)
cellfun(@(Y,IN) plot(x(IN==true),Y(IN==true),'r'),L,in)
end
  8 Comments
chao ye
chao ye on 24 May 2020
it is great,but How to fill multi connected region?
“Polygons with holes are a bit problematic, but I'm sure you can adapt this code to include also those.”

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!