7

Using Tikz, I want to paint the circular sector (with RADIUS 2), but he paints only a triangle:

\documentclass[fullpage, 12pt]{ article}
\usepackage{tikz}
\usepackage{color}
\begin{center}
\begin{tikzpicture 
\draw[fill=gray!40] (0,0) to (1.41,-1.41) to (1.41,1.41) to (0,0) arc;
\draw[ultra thick] 
    (0,0) circle [radius=2];
\draw[thick] 
  (0,-2)--(0,2)
    (-2,0)--(2,0)
    (-1.41,-1.41)--(1.41,1.41)
    (-1.41,1.41)--(1.41,-1.41);
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

1
  • Your document contains some errors
    – user31729
    Mar 21, 2015 at 16:06

2 Answers 2

12

If you change your first line to

\draw[fill=gray!40] (0,0) -- +(45:2) arc (45:-45:2);

it works. And you don't need color package because TikZ inherently uses xcolor anyways.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[fill=gray!40] (0,0) -- +(45:2) arc (45:-45:2);
\draw[ultra thick] 
    (0,0) circle [radius=2];
\draw[thick] 
  (0,-2)--(0,2) (-2,0)--(2,0)
    (-135:2)--(45:2)
    (135:2)--(-45:2);
\end{tikzpicture}
\end{document}

enter image description here

3

As a complementary information, here is a way it can be done with MetaPost (code inserted in a LuaLaTeX program for typesetting convenience):

\documentclass[border=2mm]{standalone}
\usepackage{luamplib}
\begin{document}
    \begin{mplibcode}
        u := 2cm; 
        path horizontal, bisector[]; 
        horizontal = (left -- right) scaled u;
        bisector1 = horizontal rotated 45;
        bisector2 = bisector1 rotated (-90);
        beginfig(1);
            fill buildcycle(bisector1, halfcircle scaled (2u) rotated -90, bisector2)
                withcolor .8white;
            draw fullcircle scaled (2u) withpen pencircle scaled 1.25; 
            draw bisector1; draw bisector2;
            draw horizontal; draw (down--up) scaled u;
        endfig;
    \end{mplibcode}
\end{document}

To fill the circular sector, the buildcycle macro of MetaPost has been used here. It takes two or more paths as arguments and tries to return the path bordering the area they delimit together (if it exists).

It works best when each path has only one intersection point with the following in the list, though. This is the reason I chose the right half of the given circle (halfcircle scaled (2u) rotated -90) to be given as argument to buildcyclebesides the two bisectors, and not the full circle: buildcycle could have been utterly confused by the two intersection points the full circle has with each bisector.

It would have also worked if I had given fullcircle scaled (2u) rotated 180 as argument, but to understand why, it is necessary to read this discussion and/or the manual, p. 30-32.

Output:

enter image description here

2
  • If you define path c;c=fullcircle scaled 4cm; then all you need for the grey sector is the path origin -- subpath(-1,1) of c -- cycle
    – Thruston
    Mar 21, 2015 at 20:29
  • @Thruston Yes, provided that one knows that point 1 of fullcircle is the same as .5dir 45, point -1 of fullcircle the same as .5dir -45, etc. Maybe I should have chosen that way. A more geometrical way of doing that kind of things is more attractive to me though, even when it is longer. Mar 21, 2015 at 20:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .