How to shift and re plot 4 rectangles ?

조회 수: 8 (최근 30일)
Luis Garcia
Luis Garcia 2018년 7월 2일
댓글: Luis Garcia 2018년 7월 2일
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

채택된 답변

Aquatris
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])
  댓글 수: 1
Luis Garcia
Luis Garcia 2018년 7월 2일
Very Similar, Thank you for the help. I really appreciate it.
Luis.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by