我怎样才能做一个桶

我怎样才能做一个桶

您好,亲爱的 PGFplots 用户,我需要制作这个图形,一个桶。如何使用 PGFplots 来做到这一点?

在此处输入图片描述

答案1

这里唯一稍微不平凡的任务是计算桶的(弯曲)垂直边界的临界角。这个答案试图做一些可能新的事情。据我所知,到目前为止,这些值都是以“基础相关”的方式计算的,并且表达式因是否使用而不同pgfplotstikz-3dplot或者像在这个答案中一样,使用perspective库来安装 3d 视图。在这里,这是以独立的方式计算的,这就是神秘函数的作用phicrit。其余都是标准的。

\documentclass[tikz,border=3mm]{standalone}
\definecolor{irk}{RGB}{138,204,183}
\usetikzlibrary{perspective}
\makeatletter
\pgfmathdeclarefunction{phicrit}{0}{%
\begingroup%
\pgfmathparse{atan2(\pgf@xx,\pgf@yx)}%
\pgfmathsmuggle\pgfmathresult\endgroup%
}%
\makeatother
\begin{document}
\begin{tikzpicture}[3d view={110}{15},declare function={rr(\x)=2.3*exp(-\x*\x/45);
    h=3;},>=stealth,semithick]
 \foreach \X [evaluate=\X as \Z using {-2*h+\X*h}] in {1,2,3}
 {\draw[irk,inner color=irk!20!white,outer color=irk!80!white]
  plot[smooth cycle,variable=\t,domain=0:360] 
  ({rr(\Z)*sin(\t)},{rr(\Z)*cos(\t)},\Z);
 \draw[magenta,ultra thick] (0,0,\Z) -- (0,{rr(\Z)},\Z);
 \ifcase\X
 \or
  \fill[magenta] (0,0,\Z) circle[radius=3pt];
  \path (0,0,\Z) node[left=1ex] {$-h$}  -- node[above] {$r$} (0,{rr(\Z)},\Z);
 \or
   \path (0,0,\Z) -- node[above] {$R$} (0,{rr(\Z)},\Z);
 \or
  \fill[magenta] (0,0,\Z) circle[radius=3pt];
  \path (0,0,\Z) node[left=1ex] {$h$} -- node[above] {$r$} (0,{rr(\Z)},\Z);
 \fi 
 \ifnum\X<3
  \draw[dashed,gray] (0,0,\Z) -- ++ (0,0,h);
 \else
  \draw[->] (0,0,\Z) -- ++ (0,0,1) node[pos=1.2] {$z$};
 \fi}
 \draw[irk] plot[variable=\t,smooth,domain=-h:h] 
  ({rr(\t)*sin(phicrit)},{rr(\t)*cos(phicrit)},\t); 
 \draw[irk] plot[variable=\t,smooth,domain=-h:h] 
  ({rr(\t)*sin(phicrit+180)},{rr(\t)*cos(phicrit+180)},\t); 
 \draw[dashed,gray] ({rr(0)},0,0) -- ({-rr(0)-1},0,0)
    (0,{rr(0)},0) -- (0,{-rr(0)-1},0);
 \draw[->] ({rr(0)},0,0) -- ++ (1,0,0) node[pos=1.2] {$x$};  
 \draw[->] (0,{rr(0)},0) -- ++ (0,1,0) node[pos=1.2] {$y$}; 
\end{tikzpicture}
\end{document}

在此处输入图片描述

有些桶里会栖息着土拨鼠,它们负责照料蜂蜜酒。

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikzlings}
\usetikzlibrary{perspective}
\makeatletter
\pgfmathdeclarefunction{phicrit}{0}{%
\begingroup%
\pgfmathparse{atan2(\pgf@xx,\pgf@yx)}%
\pgfmathsmuggle\pgfmathresult\endgroup%
}%
\makeatother
\begin{document}
\begin{tikzpicture}[declare function={rr(\x)=2.3*exp(-\x*\x/45);
    h=3;},>=stealth,semithick]
 \fill[3d view={110}{15}] plot[variable=\t,smooth cycle,domain=0:360,samples=37] 
  ({rr(h)*sin(\t)},{rr(h)*cos(\t)},h);  
 \marmot[3D,shift={(0,1.5)},scale=1.4,whiskers,teeth]
 \foreach \X [evaluate=\X as \CF using {int(70+20*cos(\X*30+80))}] in {1,...,12}    
 {\draw[3d view={110}{15},top color=brown!\CF!black!80!white,bottom color=brown!\CF!black!80!white] 
  plot[variable=\t,smooth,domain=-h:h] 
  ({rr(\t)*sin(phicrit+\X*15-15)},{rr(\t)*cos(phicrit+\X*15-15)},\t) -- 
  plot[variable=\t,smooth,domain=0:15] 
  ({rr(h)*sin(phicrit+\X*15-15+\t)},{rr(h)*cos(phicrit+\X*15-15+\t)},h) --
  plot[variable=\t,smooth,domain=h:-h] 
  ({rr(\t)*sin(phicrit+\X*15)},{rr(\t)*cos(phicrit+\X*15)},\t) --
  plot[variable=\t,smooth,domain=15:0] 
  ({rr(-h)*sin(phicrit+\X*15-15+\t)},{rr(-h)*cos(phicrit+\X*15-15+\t)},-h)
  -- cycle; }
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容