overall area of intersecting rectangles

Hi all, I have multiple rectangles defined by the rectangle() function, as seen in picture 1. The Hight and Width of the rectangles are variables. The positions of the rectangles are affected by each other, so if if the red rectangle gets bigger, the other rectangles will shift along the x- and y- axes.
I want to calculate the overall Area, so basically as shown in picture 2, the area between the axes and the outermost rectangle boundaries.
Any help is appreciated, thanks!

 採用された回答

Matt J
Matt J 2021 年 3 月 6 日
編集済み: Matt J 2021 年 3 月 6 日

0 投票

If you put the rectangles in the form of a polyshape vector, poly, then it is quite easy:
Area= area(union(poly));

7 件のコメント

Tobias Eißler
Tobias Eißler 2021 年 3 月 6 日
So you mean, building 1 polyshape vector from outermost points of the rectangles (from points on the drawn red line)?
Matt J
Matt J 2021 年 3 月 6 日
編集済み: Matt J 2021 年 3 月 6 日
No, a vector of polyshape rectangles. E.g.,
poly(1)=polyshape([0,0; 0 1; 1 1 ; 1 0 ]); %first rectangle
poly(2)=polyshape([0.5,0.5; 0.5 2; 2 2 ; 2 0.5 ]); %second rectangle
plot(poly)
Area = area(union(poly))
Area = 3
Tobias Eißler
Tobias Eißler 2021 年 3 月 6 日
I didn't know it was possible like that, thanks a lot!
Tobias Eißler
Tobias Eißler 2021 年 3 月 6 日
Do you know if there is a simple replacement for polyshape ? MATLAB R2016b doesnt have the function
Matt J
Matt J 2021 年 3 月 6 日
No, not unless you can find something on the File Exchange. You can't upgrade?
Tobias Eißler
Tobias Eißler 2021 年 3 月 6 日
sadly not, it is not my personal version but the one at the institute im working at.
but thanks again for your help! much appreciated!
Matt J
Matt J 2021 年 3 月 7 日
Ask them to upgrade...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangePolygonal Shapes についてさらに検索

製品

質問済み:

2021 年 3 月 6 日

コメント済み:

2021 年 3 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by