# TikZ - How can I filldraw areas spanned over an arc?

I'd like to draw an angle transmitter:

The following code shows what I have come up with so far, which is basically nothing. I can't figure out how to fill up for cells per quadrant... in a radial fashion. I've succeeded with rectangles and circles of some sort, but not this one.

Starting at 12 o'clock and going counter-clockwise, the pattern is 8f(ull)-8e(mpty) cells on the outer ring, then the same on the 2nd outer ring with an offset of 4 cells, then 4f-4e with an offset of 2 cells and the inner ring has a 2f-2e pattern with an offset of one.

\documentclass[
a4paper
]{scrartcl}

\usepackage{
newtxtext,
amsmath,
}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{
external,
}

\listfiles

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]
%   \foreach \a in {2,2.5,...,4}
%       \foreach \w in {0,22.5,45,...,337.5} {
tex.sprint(angle)
tex.sprint([[:]])
tex.sprint(offset)
tex.sprint([[cm)$) arc (]]) tex.sprint(angle) tex.sprint([[:]]) tex.sprint(22.5 + angle) tex.sprint([[:]]) tex.sprint(offset) tex.sprint([[cm) -- ($(0, 0) + (]])
tex.sprint(22.5 + angle)
tex.sprint([[:]])
tex.sprint(offset + 0.5)
tex.sprint([[cm)$) arc (]]) tex.sprint(22.5 + angle) tex.sprint([[:]]) tex.sprint(angle) tex.sprint([[:]]) tex.sprint(offset + 0.5) tex.sprint([[cm) -- cycle;]]) end angle = angle + 22.5 end offset = offset + 0.5 end -- naive filling solution: -- for angle = 0, 359, 90 do -- tex.sprint([[\fill[rotate=]]) -- tex.sprint(angle) -- tex.sprint([[] ($(0, 0) + (22.5:2.5cm)$) arc (22.5:67.5:2.5cm) -- ($(0, 0) + (67.5:3.0cm)$) arc (67.5:22.5:3.0cm) -- cycle;]]) -- end -- for angle = 0, 359, 180 do -- tex.sprint([[\fill[rotate=]]) -- tex.sprint(angle) -- tex.sprint([[] ($(0, 0) + (135:3.0cm)$) arc (135:225:3.0cm) -- ($(0, 0) + (225:3.5cm)$) arc (225:135:3.5cm) -- cycle;]]) -- end -- tex.sprint([[\fill ($(0, 0) + (180:3.5cm)$) arc (180:360:3.5cm) -- ($(0, 0) + (360:4.0cm)$) arc (360:180:4.0cm) -- cycle;]]) -- tex.sprint([[\fill ($(0, 0) + (90:4.0cm)$) arc (90:270:4.0cm) -- ($(0, 0) + (270:4.5cm)$) arc (270:90:4.5cm) -- cycle;]]) tex.sprint([[\end{tikzpicture}]]) end \end{luacode*} \begin{document} \luadirect{draw_figure()} \end{document}  I've made this into a parametrized function where you can set the values of the chart's inner radius, outer radius (measured in centimeters), and set the position of the ruler. The following code has some examples included, however I show some of them here also. \documentclass[a4paper]{article} \usepackage{luacode} \usepackage{tikz} \usetikzlibrary{calc} % inverse clipping from: http://tex.stackexchange.com/a/59168/8844 \tikzset{ invclip/.style={clip,% insert path={{[reset cm] % (-16383.99999pt,-16383.99999pt) rectangle (16383.99999pt,16383.99999pt)% }} } } \begin{luacode*} function draw_chart(fillmatrix, inner_radius, outer_radius, ruler_step) cols = #fillmatrix[1] rows = #fillmatrix angle_offset = 360 / cols radius_offset = (outer_radius - inner_radius) / rows tex.sprint([[\begin{tikzpicture}]]) if ruler_step >= 1 and ruler_step <= cols then tex.sprint([[\begin{scope}[rotate=]]) tex.sprint(angle_offset * ruler_step - angle_offset / 2) tex.sprint([[] ]]) tex.sprint([[\draw (]]) tex.sprint(inner_radius - radius_offset * 0.5) tex.sprint([[cm, ]]) tex.sprint(radius_offset * 0.5) tex.sprint([[cm) rectangle (]]) tex.sprint(outer_radius + radius_offset * 0.5) tex.sprint([[cm, ]]) tex.sprint(radius_offset * -0.5) tex.sprint([[cm)]]) for i = inner_radius, (outer_radius - radius_offset), radius_offset do tex.sprint([[(]]) tex.sprint(i + radius_offset * 0.5) tex.sprint([[cm, 0) circle [radius=]]) tex.sprint(radius_offset * 0.5 * 0.6) tex.sprint([[cm] ]]) end tex.sprint([[;]]) tex.sprint([[\end{scope}]]) -- inverse clipping from: http://tex.stackexchange.com/a/59168/8844 tex.sprint([[\begin{pgfinterruptboundingbox}]]) tex.sprint([[\path[invclip, rotate=]]) tex.sprint(angle_offset * ruler_step - angle_offset / 2) tex.sprint([[] (]]) tex.sprint(inner_radius - radius_offset * 0.5) tex.sprint([[cm, ]]) tex.sprint(radius_offset * 0.5) tex.sprint([[cm) rectangle (]]) tex.sprint(outer_radius + radius_offset * 0.5) tex.sprint([[cm, ]]) tex.sprint(radius_offset * -0.5) tex.sprint([[cm)]]) for i = inner_radius, (outer_radius - radius_offset), radius_offset do tex.sprint([[(]]) tex.sprint(i + radius_offset * 0.5) tex.sprint([[cm, 0) circle [radius=]]) tex.sprint(radius_offset * 0.5 * 0.6) tex.sprint([[cm] ]]) end tex.sprint([[;]]) tex.sprint([[\end{pgfinterruptboundingbox}]]) end for radius = inner_radius, outer_radius, radius_offset do tex.sprint([[\draw (0,0) circle [radius=]]) tex.sprint(radius) tex.sprint([[cm];]]) end for angle = 0, 359, angle_offset do tex.sprint([[\draw[rotate=]]) tex.sprint(angle) tex.sprint([[] (]]) tex.sprint(inner_radius) tex.sprint([[cm, 0) -- (]]) tex.sprint(outer_radius) tex.sprint([[cm, 0);]]) end radius = inner_radius for i = 1, rows do angle = 0 for j = 1, cols do if fillmatrix[i][j] == 1 then tex.sprint([[\fill ($(0, 0) + (]])
tex.sprint(angle)
tex.sprint([[:]])
tex.sprint([[cm)$) arc (]]) tex.sprint(angle) tex.sprint([[:]]) tex.sprint(angle + angle_offset) tex.sprint([[:]]) tex.sprint(radius) tex.sprint([[cm) -- ($(0, 0) + (]])
tex.sprint(angle + angle_offset)
tex.sprint([[:]])
tex.sprint([[cm)\$) arc (]])
tex.sprint(angle + angle_offset)
tex.sprint([[:]])
tex.sprint(angle)
tex.sprint([[:]])
tex.sprint([[cm) -- cycle;]])
end

angle = angle + angle_offset
end

end

tex.sprint([[\end{tikzpicture}]])
end
\end{luacode*}

\begin{document}

\setlength{\parindent}{0pt}

With this code you can set the inner and outer radius of the chart, and also set the position of the ruler.

ruler position = 1

fillmatrix = {{0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0},
{1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0}}

draw_chart(fillmatrix, 2.5, 4.5, 1)
}

ruler position = 10

You can disable the ruler, by setting its position to zero.

ruler position = 0

fillmatrix = {{0, 0, 0, 0, 1, 1, 1, 1},
{0, 0, 1, 1, 0, 0, 1, 1},
{0, 1, 0, 1, 0, 1, 0, 1}}

draw_chart(fillmatrix, 0, 2, 0)
}

You can also use this chart to visualize binary numbers. The third 3 bit binary number (binary 010 = octal 2 = decimal 2 = hexadecimal 2):

The sixteenth 4 bit binary number (binary 1111 = octal 17 = decimal 15 = hexadecimal F):

fillmatrix = {{0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1},
{0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1},
{0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}}

draw_chart(fillmatrix, 2, 3, 16)
}

The sixth 5 bit binary number (00101):

fillmatrix = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1},
{0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1},
{0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}}

draw_chart(fillmatrix, 3, 6, 6)
}

\end{document}


left

• inner radius = 1cm, outer radius = 3cm, ruler position= 10

right

• inner radius = 2.5cm, outer radius = 4.5cm, ruler position = 1

You can also use this chart to visualize binary numbers.

left:

• the third 3 bit binary number (binary 010 = octal 2 = decimal 2 = hexadecimal 2)
• inner radius = 1cm, outer radius = 2cm, ruler position = 3

right:

• the sixteenth 4 bit binary number (binary 1111 = octal 17 = decimal 15 = hexadecimal F)
• inner radius = 2cm, outer radius = 3cm , ruler position = 16
-

To observe how arcs and filling work you can add inside your tikzpicture :

%How arc works
\draw[blue,->] (0,3.5) arc [radius=3.5, start angle=90, delta angle=90];
%Now filling
\filldraw[fill=gray] (3.5,0) arc [radius=3.5, start angle=0, delta angle=90]
-- (0,4) arc [radius=4, start angle=90, delta angle=-90]
-- cycle;
\filldraw[fill=red] (0,-3.5) arc [radius=3.5, start angle=270, delta angle=90]
-- (4,0) arc [radius=4, start angle=0, delta angle=-90]
-- cycle;


And here is an example within a loop, where a bit of trigonometry gives you the formula:

\foreach \a in {0,1} {
% filling in the loop
\filldraw[fill=green!50!black] ({3.5*cos((-\a*(pi/8)+(pi/2)) r)},{3.5*sin((-\a*(pi/8)+(pi/2)) r)})
arc [radius=3.5, start angle={((pi/2)+(-pi/8)*\a) r}, delta angle={(-pi/8) r}]
-- ({4*cos((-(\a+1)*(pi/8)+(pi/2)) r)},{4*sin((-(\a+1)*(pi/8)+(pi/2)) r)})
arc [radius=4, start angle={((pi/2)+(-pi/8)*(\a+1)) r}, delta angle={pi/8 r}]
-- cycle;
% corresponding arcs
\draw[thick,blue,->] ({3.5*cos((-\a*(pi/8)+(pi/2)) r)},{3.5*sin((-\a*(pi/8)+(pi/2)) r)})
arc [radius=3.5, start angle={((pi/2)+(-pi/8)*\a) r}, delta angle={(-pi/8) r}];
\draw[thick,red,->] ({4*cos((-(\a+1)*(pi/8)+(pi/2)) r)},{4*sin((-(\a+1)*(pi/8)+(pi/2)) r)})
arc [radius=4, start angle={((pi/2)+(-pi/8)*(\a+1)) r}, delta angle={pi/8 r}];
}

-