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

2 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Star Strider
Star Strider am 12 Jan. 2018
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 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by