How to mirror a plot in x and y axis.

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;

 Accepted Answer

Yao Li
Yao Li on 8 Apr 2013
Edited: Yao Li on 8 Apr 2013
*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 Comments

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;
I'm not sure what exactly the four mirrors are.
Matthew
Matthew on 8 Apr 2013
Edited: Matthew on 8 Apr 2013
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.
Never mind i got it.
How you did it?

Sign in to comment.

More Answers (0)

Categories

Asked:

on 8 Apr 2013

Commented:

on 17 Dec 2021

Community Treasure Hunt

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

Start Hunting!