divide the rectangle into the strip in matlab

4 visualizaciones (últimos 30 días)
ha ha
ha ha el 26 de Abr. de 2018
Respondida: Viswadeep Lebakula el 20 de Jul. de 2021

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:

Respuestas (1)

Viswadeep Lebakula
Viswadeep Lebakula el 20 de Jul. de 2021
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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by