six pointed star

조회 수: 26 (최근 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