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)
Show older comments
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
Accepted Answer
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
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.”
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots 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!