Create Perfect Dashed-Line Circles in Adobe Illustrator
From time-to-time I need to create a circle with a dashed outline in my icon designs. The problem is that when I create the dashed line in Adobe Illustrator using the Stroke palette, the dashes do not work out evenly so I end up with partial dashes or overlapping dashes where the circle begins and terminates. In this short article I will show you how to calculate the dash and gap values to create perfect dashed lines every time.
For this short tutorial, let’s say we have a circle that is 24 pixels across with a 1 pixel thick stroke.
Perfect Dashed-Line Circles Basics
The basic concept is pretty simple. In order to create a dashed/dotted line that is perfectly divided by the dashes and gaps, we divide the line either by the desired length of the dashes and gaps, or by the number of dashes and gaps.
Creating a circle with perfectly sized and spaced dashes and gaps follows the same concept. We simply need to know the length of the outline or, in other words, the circumference of the circle. Most of us learned this at around age 10 to 12 in our first geometry class. To calculate the circumference of a circle, you multiply the diameter of the circle by pi 3.14 (roughly).
In our example, we have already stated that the diameter is 24 pixels so our calculation will be:
24 * 3.14 = 75.36
So we now know that the circumference of our circle is 75.36 pixels
Next, we can take one of two approaches to determining the values of the dashes and gaps. For purposes of this tutorial, we will assume that the dashes and gaps will be the same size, though it is fairly straightforward to calculate the necessary dash and gap values when the dashes and gaps are different sizes.
We can guess approximately how long we want the gaps and dashes to be, then calculate the closes values that divide evenly into the length of our line (the circumference) we can determine the number of dashes we want the circle to have, then divide the line length (the circumference) by that value. So, for instance, if we want the circle to have 48 dashes, we divide 75.36 by 96. Wait, what? Why 96 you rightly ask. We use a value that is double the number of dashes we want because half of the length of the line will be the gaps between the dashes (We can use different length dashes and gaps, more on this in a moment)
Calculating by Dash and Gap Size
Let’s say that we know we want our dashes to be approximately 2 pixels long. We can only say “approximately” because we know at a glance that 2 does not divide evenly into 75.36. So we will need to find a number that does divide evenly into the circumference.
To determine the exact value, we will need to do some trial-and-error. Start by dividing the circumference by the desired, approximate dash size:
75.36 / 2 = 37.68
We now know that we are going to end up with either 37 or 38 segments to our dashed line. But since half of those segments will be dashes and half will be gaps, we will want to go with 38 segments because it is an even number.
Now we divide 75.36 by the number of segments:
75.36 / 38 = 1.983
So our dash and gap values should be set to 1.983. It is important that you use this exact value and not round it up or down. Doing so, no matter how slight the value, will make the dashes and gaps unevenly distributed.
Calculating by Number of Dashes
In the previous section on Calculating by Approximate Dash size, we already covered the gist of this approach. We can skip the approximate dash/gap size, though, because we don’t have a preference for what the values are, we just need to calculate them so we end up with the desired number of sections.
Let’s say we know that we want the circle to have 24 evenly-spaced dashes. Before we do the math, there are two things to keep in mind. First, we should always work with even numbers since the circle outline will be one-half dashes and one-half gaps. Second, when we calculate the values, we need to double the desired number of dashes since there will be one gap for every dash.
Now we can do the math:
75.36 / (24 * 2) = 75.36 / 48 = 1.57
Our dash and gap values in Adobe Illustrator’s Stroke palette should be set to 1.57. Again, it is important that you use this exact value and not round it up or down.
[graphic of resulting circle from above calculations]
Calculating Differing Dash and Gap Values
So far in this tutorial we have assumed that the dash and gap values will be the same but we can set different values so that the dashes are shorter and gaps longer, or vice versa. There are several ways to do this, but I find the simplest approach is usually best. In this case, the simplest approach is to start with one of the approaches above, then determine the difference we want between the dashes and gaps. When we know what the difference between the gap value and dash value will be, we can do some simple math to determine each value.
Using the first example where our dash and gap values were 1.983, let’s say that we want the gaps to be 1–½ the size of the dashes. We are going to move one-half of the value of the dash to the gap.
1.983 / 2 = 0.9915
So we will subtract 0.9915 from the dash value and add the same number to the gap value.
Dash: 1.983–0.9915 = 0.9915
Gap: 1.983 + 0.9915 = 2.974
You can use the formulas in this article to calculate perfect dashes lines on a circle, even with different sized dashes and gaps. You can also carry these formulas a step further and calculate multiple dash sizes. Play around with the techniques and remember, that all you are doing is dividing a line. The only real “trick” in creating dashed lines on a circle are knowing the length of the line, which is calculated very simply by: