How to plot points from a geometric transformation matrix?

In the following code I need to change the plot function code every time the number of vertices change. Is there a function which can plot any number of vertices?
clc
clear
n=input('Enter the number of vertices')
for i=1:n
x(i)=input('Enter the x coordinate');
y(i)=input('Enter the y coordinate');
end
a=[x;y;ones(1,n)]
ro=[-1 0 0;0 -1 0;0 0 1];
disp('The final Matrix is')
c=ro*a
grid on
hold on
X1=[a(1,1),a(1,2),a(1,3),a(1,4),a(1,1)];
Y1=[a(2,1),a(2,2),a(2,3),a(2,4),a(2,1)];
plot(X1,Y1,'g')
fill(X1,Y1,'g')
X2=[c(1,1),c(1,2),c(1,3),c(1,4),c(1,1)];
Y2=[c(2,1),c(2,2),c(2,3),c(2,4),c(2,1)];
plot(X2,Y2,'r')
fill(X2,Y2,'r')
hold off

 采纳的回答

clc
clear
n=input('Enter the number of vertices')
for i=1:n
x(i)=input('Enter the x coordinate');
y(i)=input('Enter the y coordinate');
end
a=[x;y;ones(1,n)]
ro=[-1 0 0;0 -1 0;0 0 1];
disp('The final Matrix is')
c=ro*a
grid on
hold on
X1=[a(1,:) a(1,1)] ;
Y1=[a(2,:) a(2,1)] ;
plot(X1,Y1,'g')
fill(X1,Y1,'g')
X2=[c(1,:) c(1,1)] ;
Y2=[a(2,:) a(2,1)] ;
plot(X2,Y2,'r')
fill(X2,Y2,'r')
hold off

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Aerospace Blockset 的更多信息

产品

版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by