any idea how I could draw an even grid inside a circle in TikZ? I could manually add invisible nodes on the circumferences and connect these with lines but there is probably a more sophisticated way to do this?

grid inside a circle


Use the TikZ macro \clip to 'cut' out everything outside of a given path, which is the circle here, later on, draw the grid as 'usual' with draw ... grid ...




\clip[draw] circle (5cm);
\draw (-5,-5) grid (5,5);


enter image description here

  • I managed to draw the four circles as in my example picture by separating each \clip and \draw combo with \begin{scope}. – trikki Oct 31 '17 at 13:46
  • @trikki: I didn't know you wanted to use all 4 circles. Of course, \begin{scope}...\end{scope} is a possible way then – user31729 Oct 31 '17 at 22:45

How to do this with MetaPost, for whom it may interest. The clip <picture> to <path> primitive command is the key here.

    path circle; circle = fullcircle scaled 6cm; u = cm; N := 4;
    picture grid;
        grid = image(%
            for i = -N upto N:
                draw ((i, -N) -- (i, N)) scaled u;
            for j = -N upto N:
                draw ((-N, j) -- (N, j)) scaled u;
        clip grid to circle; draw grid; draw circle;

enter image description here

  • In this case, you should explain the difference between the tikz and metapost clip. They have the same name but do not work at all the same. With tikz clip cut the canvas and the following constructions are therefore located in this cut. With Metapost, clip cuts out the current figure, i. e. constructions that have already been built. The following constructions are not cut out. – AndréC Oct 31 '17 at 9:11
  • 1
    @AndréC More precisely, the MetaPost clip command applies to the picture given in first argument. In this case, the grid alone. Only if this argument is currentpicture, it means all the already built constructions. I didn't know precisely how the tikz \clip command works, so your comment explains it much better than I would have done it. – Franck Pastor Oct 31 '17 at 9:47

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.