我正在尝试绘制一条连接 tikz 节点的北侧和南侧的曲线。目前,下面的代码片段显示了我相当简单的尝试,其中三条路径之间不连续。有没有一种方法可以轻松地从节点的北侧rectangle
到南侧绘制线,给定一个x
坐标(此处x=-1.0
)?
\documentclass[tikz,border=1mm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[minimum width=5cm, minimum height=0.5cm, draw] (rectangle) at (0,0) {};
\path[line width=1mm] (-1.0, 0.25) edge [bend left] (-0.8, 0.35);
\path[line width=1mm] (-0.8, 0.35) edge[bend left] (-0.8, -0.35);
\path[line width=1mm] (-0.8, -0.35) edge[bend left] (-1.0, -0.25);
\end{tikzpicture}
\end{document}
答案1
您可以使用invclip
样式来定义绘制椭圆的未绘制区域。定义从西上角到东南角的区域非常重要。
\documentclass[tikz,border=1mm]{standalone}
\tikzset{invclip/.style={clip,insert path={{[reset cm]
(-\maxdimen,-\maxdimen) rectangle (\maxdimen,\maxdimen)}}}}
\begin{document}
\begin{tikzpicture}[scale=1.0]
\node[minimum width=5cm, minimum height=0.5cm, draw] (rectangle) at (0,0) {};
\pgfmathsetmacro{\angle}{asin(0.25/0.35)}%
\draw (-1, 0.25) arc[start angle={180-\angle}, end angle={-180+\angle}, y radius=0.35, x radius=0.2];
\begin{scope}
\begin{pgfinterruptboundingbox}
\path[invclip] (0.6,0|-rectangle.north) rectangle (1,0|-rectangle.south);
\end{pgfinterruptboundingbox}
\draw[blue] (1,0) circle[x radius=0.2, y radius= 0.35];
\end{scope}
\end{tikzpicture}
\end{document}
答案2
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[minimum width=5cm, minimum height=0.5cm, draw] (rectangle) at (0,0) {};
\draw[line width=1mm, looseness=2] ([xshift=-1 cm] rectangle.north) to[out=90, in=90] ([xshift=-0.8 cm] rectangle.center) to[out=-90, in=-90] ([xshift=-1 cm] rectangle.south);
\end{tikzpicture}
\end{document}
答案3
这就是你想要画的吗?
\documentclass[tikz,border=1mm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[minimum width=5cm, minimum height=0.5cm, draw] (rectangle) at (0,0) {};
\pgfmathsetmacro{\angle}{asin(0.25/0.35)}%
\draw (-1, 0.25) arc[start angle={180-\angle}, end angle={-180+\angle}, y radius=0.35, x radius=0.2];
\end{tikzpicture}
\end{document}