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?

  • 3
    Remove the ; at the end of the definition of \centerarc. It's closing the path prematurely. – Phelype Oleinik Mar 19 at 11:55
3

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) }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.