Plotting zigzag in a 2D contour

9 次查看(过去 30 天)
Gary
Gary 2014-10-16
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
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
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 个评论
Jayaprakash P
Jayaprakash P 2020-11-20
Could you please share your Matlab code.
Kelly Kearney
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
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.

Gary
Gary 2014-10-16
编辑:Gary 2014-10-16
More like this.
  1 个评论
Adhirath Naruka
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 CenterFile Exchange 中查找有关 Green 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by