我怎樣才能做一個桶

我怎樣才能做一個桶

你好,親愛的 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}

在此輸入影像描述

相關內容