I have a half rectangle and a circle that may intersect with each other. The circle is first at a location far above the rectangle and it moves down till it intersects with the rectangle and even passes through. I'm interested in finding the path that is created from the intersection between the two paths. So far thanks to Heiko Oberiek I know how to produce the new path for a special case. I want to be able to use conditional statements to figure out if the two shapes are intersecting and if they are where is the location of the intersection and finally produce the new path from subtracting the two shapes. Here is the code that I have for creating the two shapes:
\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro\minX{2}
\pgfmathsetmacro\maxX{10}
\pgfmathsetmacro\minY{4}
\pgfmathsetmacro\maxY{10}
\pgfmathsetmacro\CX{11}
\pgfmathsetmacro\CY{12}
\pgfmathsetmacro\CR{2}
\pgfmathsetmacro\Roundness{0.2}
\begin{scope} [local bounding box=BoxWest]
\def\pathone{(.5*\maxX + .5*\minX,\maxY)
-- (-\Roundness + \maxX,\maxY)
arc (90:0:\Roundness)
-- (\maxX,\minY +\Roundness)
arc (360:270:\Roundness)
-- (.5*\maxX+ .5*\minX,\minY )}
\path [name path=pathone, draw=green] \pathone;
\path [name path=pathtwo, draw=blue](\CX,\CY)
circle (\CR);
\end{scope}
\end{tikzpicture}
\end{document}
changing the \CY from 12 to 10 produces:

and so on. This is the code that I have which only works when the circle has intersections with half-rectangle at the vertical line (Subtracting two TikZ paths at their intersection):
\begin{tikzpicture}[x=10pt, y=10pt]
\pgfmathsetmacro\minX{2}
\pgfmathsetmacro\maxX{10}
\pgfmathsetmacro\minY{4}
\pgfmathsetmacro\maxY{10}
\pgfmathsetmacro\CX{11}
\pgfmathsetmacro\CY{7}
\pgfmathsetmacro\CR{3}
\pgfmathsetmacro\Roundness{0.2}
\pgfmathsetmacro\OneWestX{.5*\maxX + .5*\minX}
\pgfmathsetmacro\OneEastX{\maxX}
\pgfmathsetmacro\OneNorthY{\maxY}
\pgfmathsetmacro\OneSouthY{\minY}
\pgfmathsetmacro\DiffX{\CX-\OneEastX}
\pgfmathsetmacro\DiffY{sqrt(\CR * \CR - \DiffX * \DiffX)}
\pgfmathsetmacro\DiffAngle{acos(\DiffX/\CR)}
\def\paththree{
(\OneWestX, \OneNorthY)
-- (\OneEastX, \OneNorthY)
-- (\OneEastX, \CY + \DiffY) % North intersection point
arc (180 - \DiffAngle:180 + \DiffAngle: \CR)
-- (\OneEastX, \OneSouthY)
-- (\OneWestX, \OneSouthY)}
\draw \paththree;
\end{tikzpicture}
can anyone help me generalize this solution for any location of the circle with respect to the half-rectangle and any radius of it?





\shapeparnodemacro in such a way that it reuses existing paths. And you may also want to tell people what you really intend to do with these code pieces. – Mar 26 '18 at 15:21\newcommand\shapeuse[2]{ \begin{scope}[local bounding box=leftbb, shift={(#2,0)}] \draw[use path=#1, yellow]; \end{scope} } \shapeuse{leftpath}{12}
– M.M. Mar 26 '18 at 16:16