Plotting zigzag in a 2D contour

7 vues (au cours des 30 derniers jours)
Gary
Gary le 16 Oct 2014
Commenté : Kelly Kearney le 15 Déc 2020
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 commentaire
Jayaprakash P
Jayaprakash P le 20 Nov 2020
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.

Connectez-vous pour commenter.

Réponses (3)

Kelly Kearney
Kelly Kearney le 17 Oct 2014
Modifié(e) : Kelly Kearney le 17 Oct 2014
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 commentaires
Jayaprakash P
Jayaprakash P le 20 Nov 2020
Could you please share your Matlab code.
Kelly Kearney
Kelly Kearney le 15 Déc 2020
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.

Connectez-vous pour commenter.


Kelly Kearney
Kelly Kearney le 16 Oct 2014
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 le 16 Oct 2014
Modifié(e) : Gary le 16 Oct 2014
More like this.
  1 commentaire
Adhirath Naruka
Adhirath Naruka le 26 Nov 2020
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Green dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by