find the area of the join of 2 polygons

use intersect function and polyshape function to find the area of the join of 2 polygons
Updated 5 Apr 2022
MAX_LEN=100000;
poly = polyshape([-1 0.5 1 1 0 -1],[0.5 1 0.5 -0.5 -1 -0.5]);
poly1 = polyshape([0 0 MAX_LEN MAX_LEN],[0 MAX_LEN MAX_LEN 0]);
poly2=polyshape([0 0 -MAX_LEN -MAX_LEN],[0 MAX_LEN MAX_LEN 0]);
poly3=polyshape([0 0 -MAX_LEN -MAX_LEN],[0 -MAX_LEN -MAX_LEN 0]);
poly4=polyshape([0 0 MAX_LEN MAX_LEN],[0 -MAX_LEN -MAX_LEN 0]);
polyout = intersect(poly,poly2);
subplot(221);
plot(poly);hold on;
plot(polyout);
xlim([-2 2]);
ylim([-2 2]);
display(['A2=',num2str(polyout.area)]);
title(['A2=',num2str(polyout.area)]);
polyout = intersect(poly,poly3);
subplot(222);
plot(poly);hold on;
plot(polyout);
xlim([-2 2]);
ylim([-2 2]);
display(['A3=',num2str(polyout.area)]);
title(['A3=',num2str(polyout.area)]);
polyout = intersect(poly,poly4);
subplot(223);
plot(poly);hold on;
plot(polyout);
xlim([-2 2]);
ylim([-2 2]);
display(['A4=',num2str(polyout.area)]);
title(['A4=',num2str(polyout.area)]);
polyout = intersect(poly,poly1);
subplot(224);
plot(poly);hold on;
plot(polyout);
xlim([-2 2]);
ylim([-2 2]);
display(['A1=',num2str(polyout.area)]);
title(['A1=',num2str(polyout.area)]);
display(['OveallArea=',num2str(poly.area)]);
suptitle(['OveallArea=',num2str(poly.area)]);
MATLAB Release Compatibility
Created with R2022a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!