How can I modify the code below to build a hexagon knowing the coordinates of the hexagon roofs?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Jenny
el 12 de En. de 2018
Comentada: Star Strider
el 12 de En. de 2018
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 comentarios
Respuesta aceptada
Star Strider
el 12 de En. de 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 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!