[Tex/LaTex] Drawing lines within circle using TikZ

circlestikz-pgf

I'm trying to draw some lines within a circle of arbitrary size. I want to start with one vertical line through the centre of the circle and then add further lines like so:

enter image description here

I want to be able to control the spacing between the lines, L, and the number of lines plotted out from the centre (in the example there are two on either side of the centre line). The red markings are just for a guide I don't need that in the final version.

What is the best way to code this using TikZ?

MWE

\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) circle (1cm); % The choice of 1cm was arbitrary, what is the best way to scale this diagram?
\draw (0,-1) -- (0,1);
\draw (3,0) circle (1cm);
\draw (3,-1) -- (3,1);
\end{tikzpicture}
\end{document}

Best Answer

Using clipping? I am using a scope here to restrict the clipping to it.

\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \begin{scope} 
        \draw  [clip] (0,0) circle (1cm);
        \draw (0,-1) -- (0,1); % first (center) line 
            \foreach \x in {1,...,4} {% 4 lines per side 
                \draw (\x/10, -1) -- (\x/10,1); % positive x position 0.1, 0.2...
                \draw (-\x/10, -1) -- (-\x/10,1); % and negative ones 
        }
    \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

(Notice that the seemingly bigger line at the center is an aliasing problem of the PDF viewer).

Using scopes let you manipulate the thing quite easily:

\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \begin{scope}
        \draw  [clip] (0,0) circle (1cm);
        \draw (0,-1) -- (0,1); % first diagonal
            \foreach \x in {1,...,4} {% 4 lines 
                \draw (\x/10, -1) -- (\x/10,1);
                \draw (-\x/10, -1) -- (-\x/10,1);
        }
    \end{scope}
    \begin{scope}[xshift=2cm, scale=0.5, rotate=45]
        \draw  [clip] (0,0) circle (1cm);
        \draw (0,-1) -- (0,1); % first diagonal
            \foreach \x in {1,...,4} {% 4 lines 
                \draw (\x/10, -1) -- (\x/10,1);
                \draw (-\x/10, -1) -- (-\x/10,1);
        }
    \end{scope}
\end{tikzpicture}
\end{document}

enter image description here