我希望“矩形”的其中一条边是圆弧。我希望 可以arc
像 一样使用--
,这样就cycle
可以闭合所有的路径,但显然它只会关闭弧线。我该如何摆脱中间的线?这是我的代码:
\documentclass[11pt, border=1pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\chamberheight}{4}
\pgfmathsetmacro{\chamberwidth}{5}
\pgfmathsetmacro{\curverad}{4}
\pgfmathsetmacro{\phibase}{asin(\chamberheight/2/\curverad)}
\pgfmathsetmacro{\phif}{180+\phibase}
\pgfmathsetmacro{\phii}{180-\phibase}
\pgfmathsetmacro{\xin}{\curverad*cos(\phibase)}
\pgfmathsetmacro{\cellwidth}{0.4}
\pgfmathsetmacro{\cellheight}{1}
\pgfmathsetmacro{\initialx}{\xin-\curverad+0.05}
\draw[smooth,thick,line join=round] (0,-\chamberheight/2) --
++(\chamberwidth,0) -- ++(0,\chamberheight) -- ++(-\chamberwidth,0)
++(\xin,-2) ++(\phii:\curverad) arc (\phii:\phif:\curverad) --
cycle;
\foreach \x in {-18,-6,6,18}{
\draw[smooth, line join=round, thick, fill=white,
rotate around={\x:(\xin,0)}]
(\initialx,-\cellwidth/2) -- ++(-\cellheight,0) --
++(0,\cellwidth) -- ++(\cellheight,0);}
\end{tikzpicture}
\end{document}
答案1
您只需绘制矩形,然后绘制带有圆弧的版本。如果您剪掉相关的线条,它就可以正常工作。
\documentclass[border=10pt,multi,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\chamberheight}{4}
\pgfmathsetmacro{\chamberwidth}{5}
\pgfmathsetmacro{\curverad}{4}
\pgfmathsetmacro{\phibase}{asin(\chamberheight/2/\curverad)}
\pgfmathsetmacro{\phif}{180+\phibase}
\pgfmathsetmacro{\phii}{180-\phibase}
\pgfmathsetmacro{\xin}{\curverad*cos(\phibase)}
\pgfmathsetmacro{\cellwidth}{0.4}
\pgfmathsetmacro{\cellheight}{1}
\pgfmathsetmacro{\initialx}{\xin-\curverad+0.05}
\draw [smooth,thick,line join=round]
(0,-\chamberheight/2) --
++(\chamberwidth,0) --
++(0,\chamberheight) --
++(-\chamberwidth,0)
arc (\phii:\phif:\curverad) --
cycle;
\foreach \x in {-18,-6,6,18}{
\draw[smooth, line join=round, thick, fill=white,
rotate around={\x:(\xin,0)}]
(\initialx,-\cellwidth/2) -- ++(-\cellheight,0) --
++(0,\cellwidth) -- ++(\cellheight,0);}
\end{tikzpicture}
\end{document}
请注意,如果这对您有用的话,rounded rectangle
可以将初始轮廓绘制为单一操作。\node