How to shift and re plot 4 rectangles ?

8 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Aquatris
Aquatris il 2 Lug 2018
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])
  1 Commento
Luis Garcia
Luis Garcia il 2 Lug 2018
Very Similar, Thank you for the help. I really appreciate it.
Luis.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by