# How to clip shapes within a double path

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?

\documentclass{book}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw [fill=red](0.05,5.09) circle(8pt) node {};
\path [
preaction={draw,double=black!10, double distance=45pt,color=white},
clip,
scale=1.8
] plot [smooth] coordinates {
(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)
};
\draw [fill=blue](-0.55,3.09) circle(8pt) node {};
\end{tikzpicture}
\end{document}


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:

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
% \DoubleDistance takes the distance of the double line of the question
\def\DoubleDistance{45pt}

% Macro \dsPrev returns the predecessor of the number given in #1
\newcommand*{\dsPrev}[1]{\the\numexpr(#1)-1\relax}

% Point definitions
\path
% Middle points get names: (dsM\i) with \i as number from 1, ..., \dsN
\foreach [
var=\point,
count=\i,
] 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
\pgfextra{\global\let\dsN\i}%
%
% 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}
in
($(\p1)!\dsRadius!-90-\n{a}:(\p2)$) coordinate (dsM\n1r)
($(\p1)!\dsRadius!90-\n{a}:(\p2)$) coordinate (dsM\n1l)
}
;

% Illustrate
\filldraw[
fill=black!10,
draw=black,
very thin,
variable=\i,
smooth,
mark=*,
mark size=.5pt,
]
% mark the middle points
plot[
samples at={1, ..., \dsN},
only marks,
mark options=black,
] (dsM\i)
% right points
plot[
samples at={1, ..., \dsN},
mark options=red,
] (dsM\i r)
--
% left points
plot[
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 {};

\end{tikzpicture}
\end{document}


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.

\documentclass{book}
\usepackage{tikz}
\usepackage[english]{babel}
\begin{document}
\begin{tikzpicture}

\clip plot[smooth cycle,clip]coordinates{
(0.91,7.04)(0.51,5.4)(1.57,4.6)(3.12,4.84)(6.36,6.39)(7.4,5.79)(6.87,4.84)(5.43,4.44)(3.15,4.24)(1.37,3.67)(0.4,2.38)(0.51,1)(1.9,0.27)(3.37,0.69)(6.23,2.07)(7.12,1.98)(6.98,1.31)(7.98,0.98)(8.09,2.22)(7.29,3.04)(6.14,3.13)(2.97,1.62)(1.31,1.69)(2.01,2.82)(5.83,3.44)(7.14,3.8)(8.38,5.15)(7.8,7.06)(5.87,7.33)(2.46,5.71)(1.57,5.71)(1.75,6.59)};
\draw [color=black!10, fill=black!10] plot[smooth cycle]coordinates{
(0.91,7.04)(0.51,5.4)(1.57,4.6)(3.12,4.84)(6.36,6.39)(7.4,5.79)(6.87,4.84)(5.43,4.44)(3.15,4.24)(1.37,3.67)(0.4,2.38)(0.51,1)(1.9,0.27)(3.37,0.69)(6.23,2.07)(7.12,1.98)(6.98,1.31)(7.98,0.98)(8.09,2.22)(7.29,3.04)(6.14,3.13)(2.97,1.62)(1.31,1.69)(2.01,2.82)(5.83,3.44)(7.14,3.8)(8.38,5.15)(7.8,7.06)(5.87,7.33)(2.46,5.71)(1.57,5.71)(1.75,6.59)};

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

\end{document}

• 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.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw [fill=red](0.05,5.09) circle(8pt);
\begin{scope}[]
\path [preaction={fill=yellow},clip,scale=1.8] plot [smooth,clip] coordinates
{
(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)
};
\end{scope}
\draw [fill=blue](-0.55,3.09) circle(8pt); %Outside yellow region gets clipped
\end{tikzpicture}
\end{document}


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