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.
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!