0

I am new to LaTex, and I'm creating some math problems for my students. I know how to draw a circle using tikz, but is there an easy way to draw the x-y co-ordinate system circumscribed by a circle? I want to use help lines, but I don't want them to extend outside of the circle that I'm drawing. An alternative might be to have the usual square co-ordinate plane equal in width to the circle's diameter but gray out the area outside the circle if that's easier to do (although I'd prefer the first method because the second would waste ink).

1
  • can show, what you try so far? can you show a sketch (drawn by hand) , what you like to obtain?
    – Zarko
    Sep 2, 2017 at 21:44

1 Answer 1

2

Try to use clip. Example for ellipse:

\documentclass{article}
\usepackage{tikz}



\begin{document}

\begin{tikzpicture}
\begin{scope}
    \clip (0,0) ellipse (3cm and 4cm);
    \foreach \x in {-3,...,3} {
      \foreach \y in {-4,...,4}{
      \draw[-] (\x,\y)--(\x,-\y);
      \draw[-] (-\x,\y)--(\x,\y);
      }
   }
  \end{scope}
  \draw (0,0) ellipse (3cm and 4cm);
\end{tikzpicture}

\end{document}

Output:

enter image description here

Clip is working inside a scope but you can have as many scopes as you want. To add numbers, you can do it outside of the scope, so they can all be seen and will not be cut by the clip command.

If you need more explanations just ask.

Edit with Torbjørn T. suggestion:

\documentclass{article}
\usepackage{tikz}



\begin{document}

\begin{tikzpicture}
\begin{scope} 
   \clip [preaction={draw}] (0,0) ellipse (3cm and 4cm);
   \draw [help lines] (-3,-5) grid (3,5); 
\end{scope}
\end{tikzpicture}

\end{document}

I do not add a result because the answer will get too long [I had to make an horizontal ellipse:P ]. (It is the same with thiner lines inside -for this reason called helplines too-)

11
  • 1
    No need for a second answer for this, but a small variation: \begin{scope} \clip [preaction={draw}] (0,0) ellipse (3cm and 4cm); \draw [help lines] (-3,-5) grid (3,5); \end{scope} Sep 2, 2017 at 22:08
  • @TorbjørnT. Added in the answer.
    – koleygr
    Sep 2, 2017 at 22:21
  • @koleygr What was your first solution? What does the Torbjorn modification do?
    – AndréC
    Sep 3, 2017 at 5:16
  • 1
    @AndréC: My first solution is above the bold: (edit). In my original solution just dont use help lines` like Torbjorn but using foreach loop and draw for drawing the lines inside the loop. There would be no difference in the output If I had use thin option inside the draw of my first code.
    – koleygr
    Sep 3, 2017 at 7:27
  • The point of the preaction in my case is that you don't need to draw the ellipse afterward. Sep 3, 2017 at 8:37

You must log in to answer this question.

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