How can I modify the code below to build a hexagon knowing the coordinates of the hexagon roofs?

1 次查看(过去 30 天)
Function []=polygon (sides)
sides=6;
radians=(2*pi)./sides;
r=ones(1,sides);
theta=1:radians:2*pi;
polar(theta,r)
end
I need to show the hexagon in the coordinate plane.The coordinates of each point should be the radius and angle from a specific point.

采纳的回答

Star Strider
Star Strider 2018-1-12
Try this:
function xy = polygon(sides)
radians=(2*pi)./sides;
r=ones(1,sides+1);
theta=0:radians:2*pi;
xy = [r(:).*cos(theta(:)) r(:).*sin(theta(:))];
end
then:
sides=6;
XY = polygon(sides) % Call ‘polygon’ Function
figure
plot(XY(:,1), XY(:,2))
axis([-1.1 1.1 -1.1 1.1])
axis equal
For best results, save the function to its own file as: polygon.m
  6 个评论

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by