Sorry, I am fairly new to TikZ.
Is there a set-theory way of cutting, intersecting, unifying paths like in (proprietary) GUI applications? Or better asked, what is the tikz approach to to deal with that problem? Let's say I've built several paths, in GUI-land I would select two of them and do an operation resulting in a new path. But how do I define a reusable tikz-path in the first place without drawing it right away? (A link to a systematic macro-tutorial would be very much appreciated.)
There are a lot of snippets out there, but for a beginner it`s all quite confusing. There are pics and shapes and macros and so on, but in the end there are just paths. Do I really have to start studying the underlying layers?
Here is a real world problem:
\documentclass[tikz,border=0.2cm]{standalone}
\usetikzlibrary{scopes}
\begin{document}
\begin{tikzpicture}[scale=4]
%\draw [help lines,step=0.1] (-0.2,-0.8) grid (1,0.8);
\path [fill=gray!50] (-0.2,-0.8) rectangle (1,0.8);
\begin{scope} %[every path/.style={fill=white}]
\draw (0,-0.65) --
++(0 , 0.3) .. controls +( 0.25,0) and +(-0.5,0) ..
++(0.8, 0.7) --
++(0 ,-0.3) .. controls +(-0.25,0) and +( 0.5,0) ..
cycle;
\draw (0,-0.15) rectangle +(0.8,0.3);
\draw (0, 0.65) -- %%% Yes is is the path from above flipped over. I just couldn't figure out how to do it properly
++(0 ,-0.3) .. controls +( 0.25,0) and +(-0.5,0) ..
++(0.8,-0.7) --
++(0 , 0.3) .. controls +(-0.25,0) and +( 0.5,0) ..
cycle;
\end{scope}
\end{tikzpicture}
\end{document}
Step by step procedure:
- Create 3 paths: "rising bent rectange", "bar", "falling bent rectangle"
- Select "bar" and "rising" paths.
- Cut "bar" from "rising" path.
- Select resulting paths and "falling" path.
- Cut "falling" from other paths.
- Select "bar" and "falling" path.
- Cut "falling" from "bar".
- Select resulting paths and "falling". ("rising" and "bar" can be discarded now)
- Cut through the background (using the 3 original paths maybe)
- Final result:
and without the grid in the back












