Plotting zigzag in a 2D contour
16 ビュー (過去 30 日間)
古いコメントを表示
Hello,as title, I have a 2D contour. Now I want to plot a zigzag geometry to infill the contour.But I have no idea how to do it. Can anyone give a hint? Thanks.
1 件のコメント
Jayaprakash P
2020 年 11 月 20 日
Hi Kelly,
I am also working on the same problem for additive manufacturing applications. I have used the lineinpolygon.m, inpolygons.m, bufferm2, contourcs funtions. But could not succeed. Could you please help me for the same.
回答 (3 件)
Kelly Kearney
2014 年 10 月 17 日
編集済み: Kelly Kearney
2014 年 10 月 17 日
Hmm, more fun.
Not exactly an out-of-the-box solution... I dug into my own toolbox of polygon stuff for this one, and that in turn uses a bunch of Mapping Toolbox polygon functions. But if you go fetch all of that ( lineinpolygon.m, inpolygons.m, bufferm2, contourcs ), this should work:
% Create a contour
[x,y,z] = peaks(100);
C = contourcs(x(1,:),y(:,1),z, [2 2]);
xc = C(1).X;
yc = C(1).Y;
% Diagonal lines
dx = 0.1;
dy = 0.1;
nl = 60; % Could probably calculate this, but I'm lazy
xe = floor(min(xc)./dx)*dx + (0:(nl-1))*dx;
ye = sort(ceil(max(yc)./dy)*dy - (0:(nl-1))*dy);
x1 = xe;
y1 = ones(1,nl).*ye(end);
x2 = ones(1,nl).*xe(1);
y2 = ye(end:-1:1);
xl = [x1; x2];
yl = [y1; y2];
% Zigzag the lines
[xc, yc] = poly2cw(xc, yc);
[xb, yb] = bufferm2('xy', xc, yc, 0.1, 'in'); % If you want some space between zigzag and edge
seg = zeros(0,2);
dirr = true;
for ii = 1:nl
[isin, inseg] = lineinpolygon(xl(1,ii), yl(1,ii), ...
xl(2,ii), yl(2,ii), xb, yb);
if isin
if dirr
seg = [seg; inseg(1:end-1,:)];
else
seg = [seg; inseg(end-1:-1:1,:)];
end
dirr = ~dirr;
end
end
plot(xc, yc, 'r', seg(:,1), seg(:,2), 'b');

3 件のコメント
Kelly Kearney
2020 年 12 月 15 日
Those subfunctions can now be found under my GitHub: lineinpolygon, inpolygons, bufferm2 (and contourcs, by Kesh Ikuma, is on the FEX). This answer is a bit outdated now -- the newer polyshape objects might be a better way to go -- but this example will probably still run.
Kelly Kearney
2014 年 10 月 16 日
You mean hatching, or similar? If so, there are several entries on the FEX that do that. An overview of a few of them can be found in this blog entry.
0 件のコメント
Gary
2014 年 10 月 16 日
編集済み: Gary
2014 年 10 月 16 日
1 件のコメント
Adhirath Naruka
2020 年 11 月 26 日
Evening mam, I am a college student and me and my group have been working on a similar problem however we are not able to integrate the given code with our contour plotting. Any help on the matter will be greatly appreciated.
参考
カテゴリ
Help Center および File Exchange で Green についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
