Plotting zigzag in a 2D contour

조회 수: 21 (최근 30일)
Gary
Gary 2014년 10월 16일
댓글: Kelly Kearney 2020년 12월 15일
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