![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189721/image.jpeg)
How to shift and re plot 4 rectangles ?
1 次查看(过去 30 天)
显示 更早的评论
I have a rectangle xrect = [x1 x2 x3 x4 x1]; yrect = [y1 y2 y3 y4 y1];
I have plotted the rectangle, but I need to shift it by 10, to make for different rectangle in different positions, so that each new rectangle centroid will be the corner of the xrect,yrect original rectangle.
Some code I have:
shift = 10;
xyrect = [xrect; yrect];
shiftsRec = [xyrect(1)-[shift,0]; xyrect(2) + [shift,0]; xyrect(3) - [0,shift]; xyrect(4) + [0,shift]];
for i=1:4
temp = shiftsRec(i,:);
newRect(i) = [xyrect * temp];
plot(newRectangles);
end
0 个评论
采纳的回答
Aquatris
2018-7-2
Is this what you are trying to achieve?
x1 = -10;x2 = 10;x3 = 10;x4 = -10; y1 = -15; y2 = -15;y3 = 15;y4 = 15;
xrect = [x1 x2 x3 x4 x1] ; yrect = [y1 y2 y3 y4 y1] ; % original rectangle centered at [0,0]
shift = 5;
scale2 = 0.5; % change the size of the additional rectangle, originals' size is 1
scale3 = 0.2; % change the size of the additional rectangle, originals' size is 1
scale4 = 0.8; % change the size of the additional rectangle, originals' size is 1
scale5 = 0.3; % change the size of the additional rectangle, originals' size is 1
xrect2 = x1 + xrect*scale2; yrect2 = y1 + yrect*scale2;
xrect3 = x2 + xrect*scale3; yrect3 = y2 + yrect*scale3;
xrect4 = x3 + xrect*scale4; yrect4 = y3 + yrect*scale4;
xrect5 = x4 + xrect*scale5; yrect5 = y4 + yrect*scale5;
plot(xrect,yrect,xrect2,yrect2,xrect3,yrect3,xrect4,yrect4,xrect5,yrect5),axis([-60 60 -60 60])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189721/image.jpeg)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!