six pointed star

22 visualizzazioni (ultimi 30 giorni)
Kensey
Kensey il 20 Mar 2012
Risposto: Voss il 18 Giu 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?

Risposta accettata

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

Più risposte (3)

T
T il 14 Set 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 il 18 Giu 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 il 18 Giu 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