2

I used the \centerarc command provided in this answer to fill a region enclosed by arcs. I have made a slight modification. I have removed the \draw inside the definition and the first parameter.

MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

    \centering
    \begin{tikzpicture}
    \def\centerarc(#1)(#2:#3:#4){ ($(#1)+({#4*cos(#2)},{#4*sin(#2)})$) arc (#2:#3:#4); }
    \coordinate (A) at (0,0);
    \coordinate (B) at (1.6,0);
    \coordinate (C) at (4,-2.5);

    \draw \centerarc(0,0)(48.23:60:1.6);
    \draw \centerarc(1.6,0)(120:180:1.6);   
    \draw \centerarc(4,-2.5)(128.47:147.99:4.72);
    \fill[red]\centerarc(0,0)(48.23:60:1.6) -- \centerarc(1.6,0)(120:180:1.6) -- \centerarc(4,-2.5)(128.47:147.99:4.72);


    \end{tikzpicture}

\end{document}

The command \centerarc works perfectly when I use \draw. But when I try to use \fill, it just prints the command as text.

Why is this happening and is there a workaround?

padawan
  • 1,532

1 Answers1

2

The \draw commands work because this:

\draw \centerarc(0,0)(48.23:60:1.6);

expands to this:

\draw ($(0,0)+({1.6*cos(48.23)},{1.6*sin(48.23)})$) arc (48.23:60:1.6);;

(with a duplicated ; at the end, which won't harm).

But this (replacing the first command only):

\fill[red] \centerarc(0,0)(48.23:60:1.6) -- \centerarc(1.6,0)(120:180:1.6) -- \centerarc(4,-2.5)(128.47:147.99:4.72);

becomes (line break added for clarity):

\fill[red] ($(#1)+({#4*cos(#2)},{#4*sin(#2)})$) arc (#2:#3:#4);
  -- \centerarc(1.6,0)(120:180:1.6) -- \centerarc(4,-2.5)(128.47:147.99:4.72);

which ends the \fill instruction at the ;.

The remaining -- \centerarc\ETC. shouldn't cause any trouble (except not working as one would expect), except that TikZ ignores stray text in a tikzpicture environment, but not math. So everything between $...$ in the definition of \centerarc is written to the PDF.

Solution: remove the ; in the definition :)

\def\centerarc(#1)(#2:#3:#4){ ($(#1)+({#4*cos(#2)},{#4*sin(#2)})$) arc (#2:#3:#4) }