six pointed star

13 次查看(过去 30 天)
Kensey
Kensey 2012-3-20
回答: Voss 2022-6-18
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?

采纳的回答

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

更多回答(3 个)

T
T 2013-9-14
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 2022-6-18
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 2022-6-18
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