7

I'm struggling drawing this picture:

enter image description here

I used

\documentclass[10pt]{article}
\usepackage{ngerman, longtable}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{fancyhdr}
\usepackage{pdflscape}
\usepackage{wasysym}
\usepackage{color}
\usepackage{longtable}
\pagestyle{fancy}
\usepackage{multirow}
\usepackage[pdftex]{graphicx}
\usepackage{array}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=0.6,domain=-3:5]

\path[fill=black,opacity=0.2] (2,0) -- plot[domain=2:0] (0,0) circle (2cm) -- (0,-2) -- cycle;

%draw grid+axis afterwards
\draw[very thin, color=gray,opacity=0.2] (-5.0,-5.0) grid (5.0,5.0);
\draw[->,color=black] (-5.5,0) -- (5.5,0);
\foreach \x in {-5,-4,-3,-2,-1,1,2,3,4,5}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0,-5.5) -- (0,5.5);
\draw (5.7,0.2) node[anchor=north west] {$x_1$};
\draw (-0.3,6.2) node[anchor=north west] {$x_2$};
\foreach \y in {-5,-4,-3,-2,-1,1,2,3,4,5}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};

%draw cirle + graph
\draw[color=black] plot (\x,{(\x-2)}) node[right] {};
\draw (0,0) circle (2cm);

\end{tikzpicture}
\end{document}

I get a circle and a line, but the circle is completely filled and I thought

\path[fill=black,opacity=0.2] (2,0) -- plot[domain=2:0] (0,0) circle (2cm) -- (0,-2) -- cycle;

removes the intended area. Perhaps someone can help me out?

3 Answers 3

9

Another way, especially in more complex cases in which you are not sure about angles, is to just put \path [clip] (-3,-5)--(5,3)--(-3,3)--cycle; in a new scope together with your statement (without any change) \path[fill=black,opacity=0.2] (2,0) -- plot[domain=2:0] (0,0) circle (2cm) -- (0,-2) -- cycle; as follows:

\documentclass[10pt]{article}
\usepackage{ngerman, longtable}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{fancyhdr}
\usepackage{pdflscape}
\usepackage{wasysym}
\usepackage{color}
\usepackage{longtable}
\pagestyle{fancy}
\usepackage{multirow}
\usepackage[pdftex]{graphicx}
\usepackage{array}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=0.6,domain=-3:5]

\begin{scope}
\path [clip] (-3,-5)--(5,3)--(-3,3)--cycle;
\path[fill=black,opacity=0.2] (2,0) -- plot[domain=2:0] (0,0) circle (2cm) -- (0,-2) -- cycle;
\end{scope}

%draw grid+axis afterwards
\draw[very thin, color=gray,opacity=0.2] (-5.0,-5.0) grid (5.0,5.0);
\draw[->,color=black] (-5.5,0) -- (5.5,0);
\foreach \x in {-5,-4,-3,-2,-1,1,2,3,4,5}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0,-5.5) -- (0,5.5);
\draw (5.7,0.2) node[anchor=north west] {$x_1$};
\draw (-0.3,6.2) node[anchor=north west] {$x_2$};
\foreach \y in {-5,-4,-3,-2,-1,1,2,3,4,5}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};

%draw cirle + graph
\draw[color=black] plot (\x,{(\x-2)}) node[right] {};
\draw (0,0) circle (2cm);

\end{tikzpicture}
\end{document}

which gives the required picture:

enter image description here

9

Replace

\path[fill=black,opacity=0.2]
  (2,0) -- plot[domain=2:0] (0,0) circle (2cm) -- (0,-2) -- cycle;

by

\path[fill=black,opacity=0.2]
  (2,0) arc[start angle = 0, end angle = 270, radius = 2] -- cycle;
2
  • Can you provide a complete example with output?
    – cfr
    Sep 11, 2016 at 2:43
  • I did nothing more than copy the original poster's code and replaced the problematic line with the one I wrote above.
    – Derek
    Sep 11, 2016 at 23:16
5

Just 4 fun with PSTricks.

\documentclass[pstricks,border=15pt,12pt]{standalone}
\usepackage{pst-plot}
\psset{dimen=m}
\begin{document}
\begin{psgraph}[axespos=t](0,0)(-4,-4)(4,4){10cm}{!}
    \psclip{\pscircle{2}}
        \pspolygon*[linecolor=lightgray](0,-2)(2,0)(2,2)(-2,2)(-2,-2)
    \endpsclip
    \pscircle{2}
    \psplot[algebraic]{-1.5}{3.5}{x-2}
\end{psgraph}
\end{document}

enter image description here

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.