How do I use ‘intersection’ to get the overlapping line between two polyshapes?
Hi – how do I get the line intersection between two polyshapes that overlap along a line? A super-simplified example is below. For the real case, the shapes are more complicated, but I think the simplified case covers it. I’m maybe not understanding how the intersection function works! Thank you!
function main()
%clear all; % completely superfluous in function workspace
x1 = [1 4 4 1];
y1 = [1 1 4 4];
x2 = [4 6 6 4];
y2 = [2 2 3 3];
poly1 = polyshape(x1,y1);
% the poly2 ‘grows’ from poly1
poly2 = polyshape(x2,y2);
poly2 = union(poly1,poly2);
growthPoly = subtract(poly2,poly1,"KeepCollinearPoints",true);
close all;
hold on;
plot(poly1,’FaceColor’,’none’,’EdgeColor’,’k’,’LineWidth’,12);
plot(poly2,’FaceColor’,’none’,’EdgeColor’,’g’,’LineWidth’,8);
plot(growthPoly,’FaceColor’,’none’,’EdgeColor’,’r’,’LineWidth’,4);
% this comes back empty and nothing gets plotted
growthLine = intersect(poly1,growthPoly,"KeepCollinearPoints",true);
plot(growthLine,’FaceColor’,’none’,’EdgeColor’,’b’,’LineWidth’,2);
legend({‘The initial poly1’,…
‘poly2 grew from poly1’,…
‘The growth area is the difference between poly2 and poly1′},’Box’,’off’,’Location’,’south’,’FontSize’,18);
title({‘How do I get the ”growthLine” part that is red-on-black?’;’I thought it would be the intersection of the black and red, but no dice’;’I thought it would show up as a blue line’},’FontSize’,22);
endHi – how do I get the line intersection between two polyshapes that overlap along a line? A super-simplified example is below. For the real case, the shapes are more complicated, but I think the simplified case covers it. I’m maybe not understanding how the intersection function works! Thank you!
function main()
%clear all; % completely superfluous in function workspace
x1 = [1 4 4 1];
y1 = [1 1 4 4];
x2 = [4 6 6 4];
y2 = [2 2 3 3];
poly1 = polyshape(x1,y1);
% the poly2 ‘grows’ from poly1
poly2 = polyshape(x2,y2);
poly2 = union(poly1,poly2);
growthPoly = subtract(poly2,poly1,"KeepCollinearPoints",true);
close all;
hold on;
plot(poly1,’FaceColor’,’none’,’EdgeColor’,’k’,’LineWidth’,12);
plot(poly2,’FaceColor’,’none’,’EdgeColor’,’g’,’LineWidth’,8);
plot(growthPoly,’FaceColor’,’none’,’EdgeColor’,’r’,’LineWidth’,4);
% this comes back empty and nothing gets plotted
growthLine = intersect(poly1,growthPoly,"KeepCollinearPoints",true);
plot(growthLine,’FaceColor’,’none’,’EdgeColor’,’b’,’LineWidth’,2);
legend({‘The initial poly1’,…
‘poly2 grew from poly1’,…
‘The growth area is the difference between poly2 and poly1′},’Box’,’off’,’Location’,’south’,’FontSize’,18);
title({‘How do I get the ”growthLine” part that is red-on-black?’;’I thought it would be the intersection of the black and red, but no dice’;’I thought it would show up as a blue line’},’FontSize’,22);
end Hi – how do I get the line intersection between two polyshapes that overlap along a line? A super-simplified example is below. For the real case, the shapes are more complicated, but I think the simplified case covers it. I’m maybe not understanding how the intersection function works! Thank you!
function main()
%clear all; % completely superfluous in function workspace
x1 = [1 4 4 1];
y1 = [1 1 4 4];
x2 = [4 6 6 4];
y2 = [2 2 3 3];
poly1 = polyshape(x1,y1);
% the poly2 ‘grows’ from poly1
poly2 = polyshape(x2,y2);
poly2 = union(poly1,poly2);
growthPoly = subtract(poly2,poly1,"KeepCollinearPoints",true);
close all;
hold on;
plot(poly1,’FaceColor’,’none’,’EdgeColor’,’k’,’LineWidth’,12);
plot(poly2,’FaceColor’,’none’,’EdgeColor’,’g’,’LineWidth’,8);
plot(growthPoly,’FaceColor’,’none’,’EdgeColor’,’r’,’LineWidth’,4);
% this comes back empty and nothing gets plotted
growthLine = intersect(poly1,growthPoly,"KeepCollinearPoints",true);
plot(growthLine,’FaceColor’,’none’,’EdgeColor’,’b’,’LineWidth’,2);
legend({‘The initial poly1’,…
‘poly2 grew from poly1’,…
‘The growth area is the difference between poly2 and poly1′},’Box’,’off’,’Location’,’south’,’FontSize’,18);
title({‘How do I get the ”growthLine” part that is red-on-black?’;’I thought it would be the intersection of the black and red, but no dice’;’I thought it would show up as a blue line’},’FontSize’,22);
end polyshape, intersection, union, subtract MATLAB Answers — New Questions









