3

I have drawn two shapes in the code below, a red curve, and a black rectangle. I have labeled four points, A, B, C and D. I would like to know how to draw a path along the black rectangle from A to B, along the red curve from B to C, and then back along the black rectangle from C to D back to A. I should mention that I would ultimately like to fill the region enclosed by this shape ABCD.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}


\begin{document}

\begin{tikzpicture}

\draw[name path=p0] (0,.8) node[above left] {$D$} -- ++(3,0) |- (0,2) node[above left] {$A$} -- cycle;

\draw[red,name path=p2] (.2,3) .. controls (.5,3) and (3,.2) .. (3.5,.2);

\fill[name intersections={of=p0 and p2}] (intersection-1) circle (2pt) node[below left] {$C$} (intersection-2) circle (2pt) node[above left] {$B$};

\end{tikzpicture}

\end{document}
profj
  • 1,529
  • 1
    Something like this: http://tex.stackexchange.com/questions/119809/tikz-emphasizing-part-of-a-drawn-path – dustin Aug 08 '13 at 16:58
  • I should clarify that I would like to draw the shape, and also fill it with a color. So, I'm not sure that would allow me to do that. I have changed the question slightly to reflect that. – profj Aug 08 '13 at 17:02

1 Answers1

4

Standard solution would be using the let ... in syntax. But this is not suitable for the cases where the followed paths are more complicated. Then you need more esoteric options such decorating the path with nodes etc. that are not that simple to automate as the following.

\documentclass[tikz]{standalone}
\usetikzlibrary{intersections,calc}
\begin{document}

\begin{tikzpicture}
\draw[name path=p0] (0,.8) coordinate (D) node[above left] {$D$} -- ++(3,0)
     |- (0,2) coordinate (A) node[above left] {$A$} -- cycle;
\draw[red,name path=p2] (2.5,2) circle (1.5cm);
\fill[name intersections={of=p0 and p2}] (intersection-1) circle (2pt) coordinate (C) 
     node[below left] {$C$} (intersection-2) circle (2pt) coordinate (B)  node[above left] {$B$};


\draw[ultra thick,red,fill=yellow] (A) -- (B) let 
\p1 = ($(B)-(2.5,2)$),
\p2 = ($(C)-(2.5,2)$),
\n1 = {atan2(\x1,\y1)},
\n2 = {atan2(\x2,\y2)} in
arc (\n1:\n2:1.5cm) -- (D) -- cycle;
\end{tikzpicture}
\end{document}

enter image description here

percusse
  • 157,807