divide the rectangle into the strip in matlab
2 次查看(过去 30 天)
显示 更早的评论
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:
0 个评论
回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!