필터 지우기
필터 지우기

Creating a ring of stars like a flag

조회 수: 4 (최근 30일)
James Connor
James Connor 2015년 10월 19일
댓글: James Connor 2015년 10월 19일
Hi,
I have these codes for a star and a circle.
% Create a light blue star
xc = 1.0;
yc = 3.0;
t = (-1/4:1/10:3/4)*2*pi;
r1 = 0.5;
r2 = 0.2;
r = (r1+r2)/2 + (r1-r2)/2*(-1).^[0:10];
x = r.*cos(t) + xc;
y = r2 - r.*sin(t) + yc;
c = [0.6 0.8 1.0];
fill(x, y, c)
function h = circle(x,y,r)
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h = plot(xunit, yunit);
hold off
How would I go about creating a a circle but instead of a circumference I have exactly 12 stars around the circumference and the radius from the centre would be 6. I am trying to create the EU flag. which has 12 stars and a radius of 6 according to wikipedia. Thanks for the help.

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 10월 19일
James - this seems like a homework question, so I will just give you a hint. You want twelve equally spaced stars around a circle with a radius of six. So start with the first star that is directly north of the origin. You can calculate the position to draw the star using standard trig equations as
x = sin(0)*radius;
y = cos(0)*radius;
where
radius = 6;
You can then pass the x and y into a function that draws the star so you should get one star that is north of the origin (at the twelve o'clock position on a clock). Now we have to draw the next star at the one o'clock position. You can do as before, but you will need an angle. Since there are 360 degrees in a circle and you want 12 equally spaced stars around the circle, then your angle would be (once converted to radians)
theta = 2*pi/12;
So you have your angle and your radius so you should be able to draw the second star. Now do the same for the third (what would its angle be), etc.
The above should make the start roughly equally spaced along the circumference of a circle. I say roughly because the xc and yc aren't (I don't think) the centre of the star but rather a point where we begin drawing (intersection of two star edges).
Try the above and see what happens!
  댓글 수: 1
James Connor
James Connor 2015년 10월 19일
Thanks, yes it is a homework question. Thanks for the hint.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axes Transformations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by