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일

1 개 추천

*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

That does invert the image but i want all four mirrors of the shape to appear on the figure.
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
hold on;
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');
set(gca, 'ydir', 'reverse');
set(gca, 'xdir', 'reverse');
grid on;
Yao Li
Yao Li 2013년 4월 8일
I'm not sure what exactly the four mirrors are.
Matthew
Matthew 2013년 4월 8일
편집: Matthew 2013년 4월 8일
I want the polygon to form a symmetrical shape by being mirrored so it forms a shape made of four of itself but i cant figure out the last mirror.
Matthew
Matthew 2013년 4월 8일
Never mind i got it.
Siddharth Behal
Siddharth Behal 2021년 12월 17일
How you did it?

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Polygonal Shapes에 대해 자세히 알아보기

질문:

2013년 4월 8일

댓글:

2021년 12월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by