divide the rectangle into the strip in matlab

2 ビュー (過去 30 日間)
ha ha
ha ha 2018 年 4 月 26 日
回答済み: Viswadeep Lebakula 2021 年 7 月 20 日

Let' say I have the matrix P contain 2D point data(20 points):

1	2	
1.5	2	
2	2	
2.5	2	
3	2	
3.5	2	
4	2	
4.5	2	
5	2	
5.5	2	
1	4	
1.5	4	
2.5	4	
3.5	4	
4	4	
4.5	4	
5	4	
5.5	4	
4.5	3	
1.5	3

And, from that data, I can draw the boundary of data. The result is rectangular shape as bellow image:

And then, I want to divide the rectangle into the strip with user-defined width as follow:

回答 (1 件)

Viswadeep Lebakula
Viswadeep Lebakula 2021 年 7 月 20 日
Filename ='P.csv';
data = csvread(Filename);
xmin = min(data(:, 1));
xmax = max(data(:, 1));
ymin = min(data(:, 2));
ymax = max(data(:, 2));
figure;
scatter(data(:, 1),data(:, 2),15,"filled");
xlabel('X - Axis')
ylabel('Y - Axis')
hold on;
rectangle('Position',[xmin ymin xmax-xmin ymax-ymin],'EdgeColor','r',...
'LineWidth',1.2)
% Calculating length and strips
Polygon_Length = max(xmax-xmin,ymax-ymin);
Userdefined_Strip_Width = 1;
strips = Polygon_Length/Userdefined_Strip_Width;
% Dividing rectangle into multiple strips
for i = 1:strips
x1= xmin + (i*Userdefined_Strip_Width);
y1= ymax;
x2= xmin + (i*Userdefined_Strip_Width);
y2= ymin;
plot([x1 x2], [y1 y2])
end

カテゴリ

Help Center および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by