I need to clip the circle so only the part of the circle within the path is visible (my output is the reverse).

This is the code I have tried. What am I doing wrong?


  \draw [fill=red](0.05,5.09) circle(8pt) node {};
  \path [
    preaction={draw,double=black!10, double distance=45pt,color=white},
  ] plot [smooth] coordinates {
  \draw [fill=blue](-0.55,3.09) circle(8pt) node {};

enter image description here


The following example calculates the points of the outer shape in order to make a proper clipping. For illustration, the middle and calculated points are shown:


  % \DoubleDistance takes the distance of the double line of the question

  % \DoubleDistance is converted to a radius and stored in \dsRadius

  % Macro \dsPrev returns the predecessor of the number given in #1

  % Point definitions
    % Middle points get names: (dsM\i) with \i as number from 1, ..., \dsN
    \foreach [
    ] in {%
      (0.53,4.31), (0.46,4.16), (0.39,4.01), (0.32,3.82),
      (0.27,3.66), (0.23,3.45), (0.23,3.29), (0.31,3.14),
      (0.47,3.01), (0.63,2.93), (0.79,2.88), (1.02,2.86),
      (1.24,2.87), (1.5,2.94), (1.72,3.02),  (1.86,3.08),
      (2.01,3.14), (2.18,3.23), (2.34,3.32), (2.49,3.39),
      (2.65,3.47), (2.83,3.58), (3.05,3.7),  (3.24,3.81),
      (3.46,3.93), (3.66,4.03), (3.89,4.13), (4.1,4.22),
      (4.32,4.32), (4.53,4.36), (4.75,4.39), (4.97,4.4),
      (5.19,4.36), (5.36,4.3),  (5.54,4.19), (5.7,4.02),
      (5.79,3.81), (5.85,3.58), (5.83,3.4),  (5.73,3.21),
      (5.58,2.89), (5.45,2.71), (5.31,2.57), (5.16,2.44),
      (4.99,2.33), (4.84,2.26), (4.62,2.16), (4.33,2.08), (4,2)%
    } {
      \point coordinate (dsM\i)
    % Remember number of points in \dsN
    % Define points of the end lines
    ($(dsM1)!\dsRadius!-90:(dsM2)$) coordinate (dsM1r)
    ($(dsM1)!\dsRadius!90:(dsM2)$) coordinate (dsM1l)
    ($(dsM\dsN)!\dsRadius!90:(dsM\dsPrev\dsN)$) coordinate (dsM\dsN r)
    ($(dsM\dsN)!\dsRadius!-90:(dsM\dsPrev\dsN)$) coordinate (dsM\dsN l)
    % Define other points of the outer shape
    \foreach \i in {3, ..., \dsN} {
      let \n2 = {\i},
          \n1 = {\dsPrev\i},
          \n0 = {\dsPrev{\dsPrev\i}},
          \p0 = (dsM\n0),
          \p1 = (dsM\n1),
          \p2 = (dsM\n2),
          \n{a} = {(atan2(\y2-\y1, \x2-\x1) - atan2(\y1-\y0, \x1-\x0))/2}
        ($(\p1)!\dsRadius!-90-\n{a}:(\p2)$) coordinate (dsM\n1r)
        ($(\p1)!\dsRadius!90-\n{a}:(\p2)$) coordinate (dsM\n1l)

  % Illustrate
    very thin,
    mark size=.5pt,
    % mark the middle points
      samples at={1, ..., \dsN},
      only marks,
      mark options=black,
    ] (dsM\i)
    % right points
      samples at={1, ..., \dsN},
      mark options=red,
    ] (dsM\i r)
    % left points
      samples at={\dsN, \dsPrev\dsN, ..., 1},
      mark options=blue,
    ] (dsM\i l)
    -- cycle

  % clip path
  \clip[variable=\i, smooth]
    plot[samples at={1, ..., \dsN}] (dsM\i r)
    -- plot[samples at={\dsN, \dsPrev\dsN, ..., 1}] (dsM\i l)
    -- cycle

  % clipped large red point
  \draw [fill=red](0,2.5) circle(8pt) node {};




This is crude, but works: I like percusse's comment and Heiko Oberdiek's code that works for me. I do not have a reputation to upvote. Please accept the answer, it fulfils my problem criteria.


\clip plot[smooth cycle,clip]coordinates{
\draw [color=black!10, fill=black!10] plot[smooth cycle]coordinates{ 

\draw [fill=blue](0.75,3.09) circle(8pt);
\draw [fill=red](0.6,5.6) circle(8pt);

  • You are the only person who can accept an answer. You do this by clicking on the greyed-out tick by the up/down voting arrows at the top left of the relevant answer. You can accept your own answer, though there might be some sort of waiting period before the system allows you to do that. (I'm not sure.) EDIT: Did you mean to accept HO's answer rather than posting a new one of your own? – cfr May 13 '15 at 2:32
  • Yes! I need a reputation of 15 before I can accept or vote, So I posted the basic workaround as an interim measure. Thank you, all. – Ashley May 15 '15 at 20:45

The yellow part shown below is the part you are clipping, the preaction is not relevant for the clip since it is how the path is represented. The clipping uses the internal area hence your blue dot is out but red one came before the clip action hence survives but overpainted by the preaction.

\draw [fill=red](0.05,5.09) circle(8pt);
\path [preaction={fill=yellow},clip,scale=1.8] plot [smooth,clip] coordinates
\draw [fill=blue](-0.55,3.09) circle(8pt); %Outside yellow region gets clipped

enter image description here

If you wish to clip then you need to explicitly construct the closed S curve via arcs and corners.

  • Thanks. Any way to draw a smooth S curve through these coordinates? – Ashley May 12 '15 at 13:13

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.