six pointed star

8 visualizaciones (últimos 30 días)
Kensey
Kensey el 20 de Mzo. de 2012
Respondida: Voss el 18 de Jun. de 2022
I need to know how to plot a six pointed star using polar coordinates. I know I need to use the hold on/hold off funcion but I'm not really sure what else?

Respuesta aceptada

Jan
Jan el 20 de Mzo. de 2012
No, you do not need hold. You can modify the example you find in help polar.

Más respuestas (3)

T
T el 14 de Sept. de 2013
I worked on this same problem for a while until I just figured it out.. Talk about a PAIN! There may be a better way of doing it but this worked for me:
theta = [pi/6:(2/3)*pi:4*pi] r= ones(1,6) polar(theta,r) hold on theta = [pi/6:(2/3)*pi:4*pi] r= ones(1,6) polar(-theta,r)

Voss
Voss el 18 de Jun. de 2022
th = 0:30:360;
r = [1/sqrt(3) 1];
r = r(1+mod(1:numel(th),2));
plot(r.*cosd(th),r.*sind(th))
axis square

Thomas Wellington
Thomas Wellington el 18 de Jun. de 2022
I worte a function that returns the coordinates of a six coordinates of a six pointed star. (See the code below.) You can call this function and then plot the coordinates (e.g. [x,y] = Six_Pointed_Star(2), press enter and type plot(x,y) on the next line.
Hope this helps. Any comments are welcome especially because I am a MATLAB newbie.
  • Tom
function [xcoords, ycoords] = Six_Pointed_Star(side_length)
%returns the x and y coordinates of a six pointed star
%whose sides are of length side length
xcoords = zeros(1,13);
ycoords = zeros(1,13);
if (~ isa(side_length, 'double')) || side_length <= 0
disp('Function argument is invalid type or less than zero.')
disp('Try again') %checks for invalid input
else %get coordinates
j = 0;
for degrees = 0:30:360
radians = degrees*pi/180;
j = j + 1;
if rem(degrees,60) == 0
xcoords(j) = side_length * cos(radians);
ycoords(j) = side_length * sin(radians);
else
xcoords(j) = sqrt(3) * side_length * cos(radians);
ycoords(j) = sqrt(3) * side_length * sin(radians);
end % of inner if
end % of for loop
end % of outer if
end % of function

Community Treasure Hunt

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

Start Hunting!

Translated by