function Polygon(a0,b0,radius,n_sides) % % displaying a Polygon with n_sides. % A circle is treated as a single case of a polygon, % it is a polygon with 360 sides. % % a0, b0 - its center, % radius - the radius enclosing the polygon, % n_sides - the number of sides. % % (x_first,y_first) - the starting vertex of a polygon. % x_first=a0+radius; y_first=b0; for j=1:n_sides % (x_next,y_next) - the next vertex of a polygon. x_next=a0+radius*cos(2*j*pi/n_sides); y_next=b0+radius*sin(2*j*pi/n_sides); line([x_first x_next], [y_first y_next]); % if n_sides<6 % displaying the vertice number. text(x_first,y_first,num2str(j)) end x_first=x_next; y_first=y_next; end % j