如何在 TikZ 中使用命令圆弧和直线来减小合成图形的宽度?

如何在 TikZ 中使用命令圆弧和直线来减小合成图形的宽度?

我有这个tikzpicture

\documentclass[10pt]{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
    \draw[line width=0.5cm] (10cm,1cm)--(12cm,1cm) arc(90:-90:1.3cm and 0.943cm) --(10cm,-0.885cm);
\end{tikzpicture}

\end{document}

未修改宽度的图形

有什么办法可以实现这个吗?:

修改宽度后的图形

也就是说,拱门的厚度随着向下而减小(即使下方水平线的厚度与拱门末端相同)。

谢谢!

答案1

在此处输入图片描述

\documentclass[10pt]{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
    \draw[fill] (10cm,1cm)--
(12cm,1cm) arc(90:-90:1.3cm and 0.943cm) --
(10cm,-0.885cm) --
(10cm,-1.1cm) --
(12cm,-1.1cm)  arc(-90:90:1.5cm and 1.3cm) --
(10cm, 1.5cm) 
;
\end{tikzpicture}

\end{document}

答案2

我忍不住复活了一个阿兰·马特斯的老把戏

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{decorations}
\begin{document}

\makeatletter
%from https://tex.stackexchange.com/a/14295/121799
\pgfkeys{/pgf/decoration/.cd,
         start color/.store in =\startcolor,
         end color/.store in   =\endcolor,
         vertical decrease slope/.store in = \DrasticY,
         color slope/.store in = \ColorSensitivity
}

\pgfdeclaredecoration{vertical width and color change}{initial}{
 \state{initial}[width=0pt, next state=line, persistent precomputation={%
   \pgfmathdivide{50}{\pgfdecoratedpathlength}%
   \let\increment=\pgfmathresult%
   \pgfmathsetmacro{\orilinewidth}{\pgflinewidth}%
   \pgfmathsetmacro{\ynod}{\pgf@y}%
   \def\x{0}%
 }]{}
 \state{line}[width=.5pt,   persistent postcomputation={%
     \pgfmathsetmacro{\x}{\the\pgf@y-\ynod}%
   }]{%
   \pgfmathsetmacro{\newlinewidth}{max(\DrasticY*\x*0.075pt+\orilinewidth,0)}%
   \pgfsetlinewidth{\newlinewidth}
   \pgfsetarrows{-}%
   \pgfpathmoveto{\pgfpointorigin}%
   \pgfpathlineto{\pgfqpoint{.75pt}{0pt}}%
    \pgfmathtruncatemacro{\absx}{round(100*(1-min(max(\ColorSensitivity*(\x+28),0),1)))}
   \pgfsetstrokecolor{\endcolor!\absx!\startcolor}%
   \pgfusepath{stroke}%
 }
 \state{final}{%
   \pgfsetlinewidth{\pgflinewidth}%
   \pgfpathmoveto{\pgfpointorigin}%
    \pgfmathtruncatemacro{\absx}{round(100*(1-min(max(\ColorSensitivity*(\x+28),0),1)))}
   \color{\endcolor!\absx!\startcolor}%
   \pgfusepath{stroke}% 
 }
}

\makeatother

\begin{tikzpicture}
  \begin{scope}
    \draw[ line width=0.5cm, decoration={vertical width and color change,   
start color=black, end color=black,vertical decrease slope=0.8,color slope=0.025}, decorate] (10cm,1cm) -- (12cm,1cm) 
     arc(90:-90:1.3cm and 0.943cm) 
    to (10cm,-0.885cm);
 \end{scope}
 \begin{scope}[xshift=5cm]
    \draw[ line width=0.5cm, decoration={vertical width and color change,   
start color=blue, end color=black,vertical decrease slope=3.8,color slope=0.02}, decorate] (10cm,1cm) -- (12cm,1cm) 
     arc(90:-90:1.3cm and 0.943cm) 
    to (10cm,-0.885cm);
 \end{scope}
\end{tikzpicture}
\end{document}

我们可以通过调整来控制线宽减少的量vertical decrease slope,甚至可以改变颜色。

在此处输入图片描述

相关内容