MATLAB: Creating a ring of stars like a flag

circles shapes star merging flags geometryhomework

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.

Best Answer

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!