Programming the Internet since 2004

Main navigation

How to Draw a Star

How do you draw a star?

We'll place a star in the center of a circle that has a radius of 200.
Our star has 5 outer points and 5 inner points. Each of these points can be calculated from a
line segment that extends from the center of the star to the point.

This line segment has a length and an angle and we use this to calculate the X and Y values of the
points.

The line segments to the outer points are all 200 in length and the angles are 72° (or 360°/5)
apart.

First find the top point

We start with the top point at 90° and use polar to rectangular conversion to calculate X and Y.

Finding the length of the inner segment

We start with the right triangle whose hypotenuse is the segment from the last outer spoke. We know that
this segment is at an angle of 18°. Therefore, angle α is 72° (90° - 18°).

This means that angle β is 18°.

How does that help, you ask? Read on...

Find the coordinates of the inner point

We then use the right triangle formed by bisecting the isosceles triangle that is one of the "arms" of the
star. We know from before that angle β is 18°. Therefore angle θ is our old friend,
72°.

We also know that the Y coordinate of the point we seek is the same as the Y coordinate of the outer point
at the tip of the red triangle.

If we can find the length of the base of the red triangle, we can calculate the X coordinate by means to be
revealed later.

Find the length of segment A

The length of the segment A found by multiplying the length of the opposite side by the ratio of the
adjacent side to the opposite side.

In other words:
A = O * (A/O)

Using trigonometry, we know that:
A = O * cot(72°)

But how do we get the value for O?

Find the length of segment O

Now we apply what we learned to the top arm of the triangle.
Here, it's easy to see that the length of segment O is simply the length of an outer spoke (we know this to
be 200) minus the Y value we arrived at earlier.

In other words:
O = 200-Y

Now we substitute this into the previous equation:
A = (200-Y) * cot(72°)

Find the length of the inner spoke

Now we know that:
X = 200 - A

We also know from before that Y is found by:
Y = 200 - (200 * sin(18°))

And finally, by using the distance formula, we can convert back to polar to get the long sought-after length
of the inner spoke.