How to mirror a plot in x and y axis.

조회 수: 19 (최근 30일)
Matthew
Matthew 2013년 4월 8일
댓글: Siddharth Behal 2021년 12월 17일
I want to mirror a plot in x and y axis so i forms a symmetrical shape made of four of the same randomly generated polygon.
prompt = {'Enter Number of vertices:',}
numberOfVertices = str2num(cell2mat(inputdlg(prompt, 'enter a number', 5)))
%numberOfVertices = 7; % Fixed at 7 for this demo.
coordinates = rand(numberOfVertices, 2);
coordinates(1,:) = [0, 0]; % Force first coord to 0,0
coordinates(end+1,:) = [0, 0]; % Force last coord to 0,0
plot(coordinates(:,1), coordinates(:,2));
grid on;
randomColor = rand(1,3);
patch(coordinates(:,1), coordinates(:,2), randomColor); % Can use fill() also.
set(gca, 'xdir', 'reverse');
grid on;

채택된 답변

Yao Li
Yao Li 2013년 4월 8일
편집: Yao Li 2013년 4월 8일
*mirror both in x axis and y axis
hold on
plot(-coordinates(:,1), -coordinates(:,2));
mirror only in x axis
hold on
plot(coordinates(:,1), -coordinates(:,2));
mirror only in y axis
hold on
plot(-coordinates(:,1), coordinates(:,2));
*
  댓글 수: 5
Matthew
Matthew 2013년 4월 8일
Never mind i got it.
Siddharth Behal
Siddharth Behal 2021년 12월 17일
How you did it?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Elementary Polygons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by