不要在 TikZ 中绘制路径的一部分

不要在 TikZ 中绘制路径的一部分

我希望玻璃水瓶的顶部不要像图片那样。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[x=0.25cm,y=0.25cm, >=stealth]
    \draw[blue,fill=blue,opacity=0.1] (0,0)-- ++(16,0)-- ++(0,4)-- ++(-6,0)-- ++(0,6)-- ++(-4,0)-- ++(0,-6)-- ++(-6,0)--cycle ;
    \draw[thick,blue,rounded corners=3pt] (0,0)-- ++(16,0)-- ++(0,4)-- ++(-6,0)-- ++(0,12)-- ++(-4,0)-- ++(0,-12)-- ++(-6,0)--cycle ;
    \draw[thick,blue,dash pattern=on 3mm off 1mm](8,0)--(8,16) ;
    \draw[thick,<->](8,-1)--node[below]{8 cm} (16,-1) ;
    \draw[thick,<->](17,0)-- node[right]{4 cm} (17,4) ;
    \draw[thick,<->](12,4)-- node[right]{12 cm} (12,16) ;
    \draw[thick,->](0,10)-- node[above]{2 cm}(6,10) ;
    \draw[thick](6,10)--(8,10) ;
    \draw[thick,<-](8,10)--(8.8,10) ; 
\end{tikzpicture}
\end{document} 

在此处输入图片描述

在此处输入图片描述

答案1

解决方案很简单:不画出这部分曲线!实现起来更困难:首先你应该找到这一段的起点和终点,然后重新绘制它:

编辑:通过形状边框的新定义,您也可以以类似的方式定义其填充区域并使用此命令\fill

\documentclass[ tikz,
                border=3mm]{standalone}
\usetikzlibrary{calc}

\begin{document}
    \begin{tikzpicture}[x=0.25cm,y=0.25cm, >=stealth]
\fill[blue,rounded corners=3pt,opacity=0.1]
    (6,10)|- ++(-6,-6) |- ++(16,-4) 
          |- ++(-6,4) -- ++ (0,6);
\draw[very thick,red,rounded corners=3pt]
    (6,16)|- ++(-6,-12) |- ++(16,-4) 
          |- ++(-6,4) -- ++ (0,12);
\draw[thick,blue,dash pattern=on 3mm off 1mm](8,0)--(8,16) ;
\draw[thick,<->](8,-1)--node[below]{8 cm} (16,-1) ;
\draw[thick,<->](17,0) -- node[below,sloped]{4 cm} (17,4) ;
\draw[thick,<->](12,4) -- node[below,sloped]{12 cm} (12,16) ;
\draw[thick,->](0,10)-- node[above]{2cm}(6,10) ;
\draw[thick](6,10)--(8,10) ;
\draw[thick,<-](8,10)--(8.8,10) ;
    \end{tikzpicture}
\end{document} 

在此处输入图片描述

答案2

最简单的方法可能是剪切绘制轮廓的路径。

\documentclass[border=10pt,multi,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[x=0.25cm,y=0.25cm, >=stealth]
    \draw[blue,fill=blue,opacity=0.1] (0,0)-- ++(16,0)-- ++(0,4)-- ++(-6,0)-- ++(0,6)-- ++(-4,0)-- ++(0,-6)-- ++(-6,0)--cycle ;
    \begin{scope}
      \clip ([xshift=-2pt,yshift=-2pt]0,0) |- (6,16) -| ++(2pt,-1) -| ([xshift=-2pt]10,16) -| ([yshift=-2pt]17,0) -- cycle;
      \draw[thick,blue,rounded corners=3pt] (0,0)-- ++(16,0)-- ++(0,4)-- ++(-6,0)-- ++(0,12)-- ++(-4,0)-- ++(0,-12)-- ++(-6,0)--cycle ;
    \end{scope}
    \draw[thick,blue,dash pattern=on 3mm off 1mm](8,0)--(8,16) ;
    \draw[thick,<->](8,-1)--node[below]{8 cm} (16,-1) ;
    \draw[thick,<->](17,0)-- node[right]{4 cm} (17,4) ;
    \draw[thick,<->](12,4)-- node[right]{12 cm} (12,16) ;
    \draw[thick,->](0,10)-- node[above]{2cm}(6,10) ;
    \draw[thick](6,10)--(8,10) ;
    \draw[thick,<-](8,10)--(8.8,10) ;
\end{tikzpicture}
\end{document}

敞口烧瓶

如果你不想让顶部有圆角,你可以在路径中留出空隙。例如,

\documentclass[border=10pt,multi,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[x=0.25cm,y=0.25cm, >=stealth]
    \draw[blue,fill=blue,opacity=0.1] (0,0)-- ++(16,0)-- ++(0,4)-- ++(-6,0)-- ++(0,6)-- ++(-4,0)-- ++(0,-6)-- ++(-6,0)--cycle ;
    \draw[thick,blue,rounded corners=3pt] (10,16) |- ++(6,-12) |- (0,0) |- ++(6,4)--  ++(0,12);
    \draw[thick,blue,dash pattern=on 3mm off 1mm](8,0)--(8,16) ;
    \draw[thick,<->](8,-1)--node[below]{8 cm} (16,-1) ;
    \draw[thick,<->](17,0)-- node[right]{4 cm} (17,4) ;
    \draw[thick,<->](12,4)-- node[right]{12 cm} (12,16) ;
    \draw[thick,->](0,10)-- node[above]{2cm}(6,10) ;
    \draw[thick](6,10)--(8,10) ;
    \draw[thick,<-](8,10)--(8.8,10) ;
\end{tikzpicture}
\end{document}

直边开口

相关内容