19

I am trying to draw the area formed by an arc of a circle (specifially 3/4 of a circle, that is 0 <= \theta <= 3\pi/2) with a radius of 4 using TikZ. I also need the interior of that arc filled in. here is what I have thus far, but 'too' much is filled in, and that may be a result of the manner I have use to draw the arc:

\begin{tikzpicture}
\draw [->] (-5.0,0)--(5.0,0);
\draw [->] (0,-5.0)--(0,5.0);
\filldraw[fill opacity=0.5,fill=blue] (4,0) arc (-0.05:275:4.0cm);
    \foreach \x in {-4,4}
    \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
    \foreach \y in {-4,4}
    \draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
\end{tikzpicture}

Any help will be appreciated.

23

I add some complements and some explanations to the fine answer from Peter.

Firstly, you can solve your problem with the pgfmanual Filling and Drawing in A Picture for Karl’s Students.

Some explanations about the code given by T.Tantau. When you need to fill an area, like Peter wrote, you need to give a closed path but it's possible to give any path ( see the examples below). If the path is not closed, then Tikz closes the path automatically with -- (origin of the path). In your code the most important part is (0,0) --.

-- cycle is important for drawing the path because in some case you need to join correctly the curves I put two red circles around the problem if you draw with or without cycle. You can see in the third picture that it's not necessary to use cycle with fill. In the first and second example, I show two different results with and without cycle .

Some examples with some variants from the example given in Karl's tutorial :

enter image description here

\documentclass{article}
\usepackage{tikz}

\begin{document} 
\begin{tikzpicture}[scale=6]
  \filldraw[fill=green!20!white, draw=green!50!black]
    (90:3mm) arc (90:0:3mm) arc (180:90:3mm) ;
\end{tikzpicture} 

\begin{tikzpicture}[scale=6]
  \filldraw[fill=green!20!white, draw=green!50!black]
    (90:3mm) arc (90:0:3mm) arc (180:90:3mm) -- (0:6mm) -- (0,0) -- cycle;
\end{tikzpicture}  

\begin{tikzpicture}[scale=6]
  \fill[fill=green!20!white]
    (0,0) -- (3mm,0mm) arc (0:30:3mm);
\end{tikzpicture}  
\begin{tikzpicture}[scale=6]
  \filldraw[fill=green!20!white, draw=green!50!black]
    (0,0) -- (3mm,0mm) arc (0:30:3mm) -- cycle;
\end{tikzpicture} 
\begin{tikzpicture}[scale=6]
  \filldraw[fill=green!20!white, draw=green!50!black]
    (0,0) -- (3mm,0mm) arc (0:30:3mm) -- (0,0);
\end{tikzpicture}   
\end{document} 

In your case :

\begin{tikzpicture}
\draw[->] (-5.0,0) -- (5.0,0) node[right] {$x$} coordinate(x axis);
\draw[->] (0,-5.0) -- (0,5.0) node[above] {$y$} coordinate(y axis);

\filldraw[fill opacity=0.5,fill=blue] (0,0) -- (4,0) arc (0:270:4.0cm) -- cycle;

\foreach \x in {-4,4}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {-4,4}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
\node at ( 45:2){\Huge \textbf{R}} ;
\node at ( 45:5){\Huge or  \textbf{R}} ; 
\end{tikzpicture}  

enter image description here

  • Thanks to both Peter and Altermundus for your help and solutions. Just one more question-how can I add the x and y labels for each coordinate axis -- I am going to try and find the line I need from the example code in the manual, but the question is in case I cannot. Thanks a bunch! – Michael Dykes Jul 4 '12 at 13:13
  • @MichaelDykes I updated my answer – Alain Matthes Jul 4 '12 at 14:29
16

You simply need to start and end at the origin:

(0,0) -- (4,0) arc (0:270:4.0cm) -- cycle

to obtain the region you desire:

enter image description here

Note:

  • Not sure why you had -0.05:275 degrees in your MWE. I have corrected that to be 0:270 to correspond to 0:3\pi/2.

Code:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=0.5]
    \draw [->] (-5.0,0)--(5.0,0);
    \draw [->] (0,-5.0)--(0,5.0);

    \filldraw[fill opacity=0.5,fill=blue] (0,0) -- (4,0) arc (0:270:4.0cm) -- cycle;

    \foreach \x in {-4,4} {\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};}
    \foreach \y in {-4,4} {\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east ] {$\y$};}
\end{tikzpicture}
\end{document}

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.