9

I want to draw a truncated pyramid that is suspended on a rope, and submersed inside water in a cylinder.

  \documentclass{standalone}
    \usepackage{tikz}
  \usetikzlibrary{patterns}
    \begin{document}
      \begin{tikzpicture}
        \draw[gray!66](0,1) ellipse (2cm and 1cm);
        \draw(0,2) ellipse (2cm and 1cm);
        \draw(0,-3) ellipse (2cm and 1cm);
        \draw(2,-3)--(2,2);
        \draw(-2,-3)--(-2,2);

        \fill[pattern=north west lines](-1,4.4) rectangle (1,4.75);
        \draw(-1,4.4)--(1,4.4);
        \draw(0,4.4)--(0,-1);
      \end{tikzpicture}
    \end{document}

Enter image description here

Enter image description here

Epa
  • 3,449

1 Answers1

14

I'd use 3d coordinates for that.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{patterns}
% https://tex.stackexchange.com/a/12033/121799
\tikzset{reverseclip/.style={insert path={(current bounding box.north
        east) rectangle (current bounding box.south west)}}}
\begin{document}
\tdplotsetmaincoords{70}{30}
\begin{tikzpicture}[tdplot_main_coords,font=\sffamily,line join=bevel]
  \pgfmathsetmacro{\rcyl}{2}
  \pgfmathsetmacro{\hcyl}{5}
  \pgfmathsetmacro{\hpyr}{2.5}
  \pgfmathsetmacro{\hremoved}{0.5}
  \pgfmathsetmacro{\zpyr}{3.5}
  \pgfmathsetmacro{\wpyr}{1.5}
  \pgfmathsetmacro{\wtop}{\hremoved*\wpyr/\hpyr}
  \pgfmathsetmacro{\hwater}{4}
  \pgfmathsetmacro{\whpyr}{\wpyr-(\hwater-\zpyr)*\wpyr/\hpyr}  % width of pyramid at water level
  \fill[tdplot_screen_coords,pattern=north west lines] (-1,7.4) rectangle (1,7.75);
  \draw[tdplot_screen_coords] (-1,7.4) -- (1,7.4) coordinate[midway] (hang); 
  %
  \draw[dashed] plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi+180] ({\rcyl*cos(\t)},{\rcyl*sin(\t)},0);
  \draw[dashed] (\wpyr/2,\wpyr/2,\zpyr)
    -- (-\wpyr/2,\wpyr/2,\zpyr) -- (-\wpyr/2,-\wpyr/2,\zpyr)
    (-\wpyr/2,\wpyr/2,\zpyr) -- (-\wtop/2,\wtop/2,\zpyr+\hpyr-\hremoved);
  \draw[fill=gray!30,fill opacity=0.5] 
  (-\wpyr/2,-\wpyr/2,\zpyr) -- (-\wtop/2,-\wtop/2,\zpyr+\hpyr-\hremoved) 
  -- (\wtop/2,-\wtop/2,\zpyr+\hpyr-\hremoved) -- (\wpyr/2,-\wpyr/2,\zpyr)  
  -- cycle;
  \draw[fill=gray!50,fill opacity=0.5] (\wpyr/2,-\wpyr/2,\zpyr) 
  -- (\wtop/2,-\wtop/2,\zpyr+\hpyr-\hremoved) 
  -- (\wtop/2,\wtop/2,\zpyr+\hpyr-\hremoved)
  -- (\wpyr/2,\wpyr/2,\zpyr)  
  -- cycle;
  \draw[fill=gray!20,fill opacity=0.5]  
  (\wtop/2,-\wtop/2,\zpyr+\hpyr-\hremoved) 
  -- (\wtop/2,\wtop/2,\zpyr+\hpyr-\hremoved)
  -- (-\wtop/2,\wtop/2,\zpyr+\hpyr-\hremoved) 
  -- (-\wtop/2,-\wtop/2,\zpyr+\hpyr-\hremoved) -- cycle;
  \begin{scope}
  \clip (-\whpyr/2,-\whpyr/2,\hwater)
   -- (\whpyr/2,-\whpyr/2,\hwater) -- (\whpyr/2,\whpyr/2,\hwater) 
   -- (\wtop/2,\wtop/2,\zpyr+\hpyr-\hremoved) 
  -- (-\wtop/2,\wtop/2,\zpyr+\hpyr-\hremoved)
  -- (-\wtop/2,-\wtop/2,\zpyr+\hpyr-\hremoved) -- (-\whpyr/2,-\whpyr/2,\hwater)
   [reverseclip];
   \fill[blue,opacity=0.2] 
   plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi+360] ({\rcyl*cos(\t)},{\rcyl*sin(\t)},\hwater);
  \end{scope} 
   \fill[blue,opacity=0.4] 
   plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi-180] 
   ({\rcyl*cos(\t)},{\rcyl*sin(\t)},\hwater)
   -- 
   plot[smooth,variable=\t,domain=\tdplotmainphi-180:\tdplotmainphi] 
   ({\rcyl*cos(\t)},{\rcyl*sin(\t)},0);
  \draw plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi-180] 
  ({\rcyl*cos(\t)},{\rcyl*sin(\t)},0)
   --  plot[smooth,variable=\t,domain=\tdplotmainphi-180:\tdplotmainphi+180] ({\rcyl*cos(\t)},{\rcyl*sin(\t)},\hcyl)
   ({\rcyl*cos(\tdplotmainphi)},{\rcyl*sin(\tdplotmainphi)},0) --
   ({\rcyl*cos(\tdplotmainphi)},{\rcyl*sin(\tdplotmainphi)},\hcyl);
  \draw (hang) --  (0,0,\zpyr+\hpyr-\hremoved);
\end{tikzpicture}
\end{document}

enter image description here

And this is an animation for Christian Hupfer with corrections due to @circumscribe.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{patterns}
% https://tex.stackexchange.com/a/12033/121799
\tikzset{reverseclip/.style={insert path={(current bounding box.north
        east) rectangle (current bounding box.south west)}}}
\begin{document}
\foreach \Z in {0,10,...,350}
{\tdplotsetmaincoords{70}{30}
\begin{tikzpicture}[tdplot_main_coords,font=\sffamily,line join=bevel]
  \pgfmathsetmacro{\rcyl}{2}
  \pgfmathsetmacro{\hcyl}{5}
  \pgfmathsetmacro{\hpyr}{2.5}
  \pgfmathsetmacro{\hremoved}{1.2}
  \pgfmathsetmacro{\zpyr}{2.8+0.8*cos(\Z)}
  \pgfmathsetmacro{\wpyr}{1.5}
  \pgfmathsetmacro{\wtop}{\hremoved*\wpyr/\hpyr}
  \pgfmathsetmacro{\hwater}{4}
  \pgfmathsetmacro{\deltahmax}{(\wpyr^2/(pi*\rcyl^2))*(\hpyr-\hremoved^3/\hpyr^2)/3}
  \pgfmathsetmacro{\waterlevel}{\hwater+ifthenelse(\zpyr<\hwater,1,0)*\deltahmax*
        ifthenelse(\zpyr>\hwater-\hpyr+\hremoved,
        1-((\zpyr-\hwater+\hpyr-\hremoved)/(\hpyr-\hremoved))^3,1)}
  %\typeout{deltahmax=\deltahmax,waterlevel=\waterlevel,zpyr=\zpyr,hwater=\hwater}
  \fill[tdplot_screen_coords,pattern=north west lines] (-1,7.4) rectangle (1,7.75);
  \draw[tdplot_screen_coords] (-1,7.4) -- (1,7.4) coordinate[midway] (hang); 
  %
  \draw[dashed] plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi+180] ({\rcyl*cos(\t)},{\rcyl*sin(\t)},0);
  \draw[dashed] (\wpyr/2,\wpyr/2,\zpyr)
    -- (-\wpyr/2,\wpyr/2,\zpyr) -- (-\wpyr/2,-\wpyr/2,\zpyr)
    (-\wpyr/2,\wpyr/2,\zpyr) -- (-\wtop/2,\wtop/2,\zpyr+\hpyr-\hremoved);
  \draw[fill=gray!30,fill opacity=0.5] 
  (-\wpyr/2,-\wpyr/2,\zpyr) -- (-\wtop/2,-\wtop/2,\zpyr+\hpyr-\hremoved) 
  -- (\wtop/2,-\wtop/2,\zpyr+\hpyr-\hremoved) -- (\wpyr/2,-\wpyr/2,\zpyr)  
  -- cycle;
  \draw[fill=gray!50,fill opacity=0.5] (\wpyr/2,-\wpyr/2,\zpyr) 
  -- (\wtop/2,-\wtop/2,\zpyr+\hpyr-\hremoved) 
  -- (\wtop/2,\wtop/2,\zpyr+\hpyr-\hremoved)
  -- (\wpyr/2,\wpyr/2,\zpyr)  
  -- cycle;
  \draw[fill=gray!20,fill opacity=0.5]  
  (\wtop/2,-\wtop/2,\zpyr+\hpyr-\hremoved) 
  -- (\wtop/2,\wtop/2,\zpyr+\hpyr-\hremoved)
  -- (-\wtop/2,\wtop/2,\zpyr+\hpyr-\hremoved) 
  -- (-\wtop/2,-\wtop/2,\zpyr+\hpyr-\hremoved) -- cycle;
  \pgfmathsetmacro{\whpyr}{\wpyr-(\waterlevel-\zpyr)*\wpyr/\hpyr}  % width of pyramid at water level
  \begin{scope}
   \pgfmathtruncatemacro{\itest}{sign(-(\waterlevel-\zpyr)+(\hpyr-\hremoved))}
   \ifnum\itest=1
    \clip (-\whpyr/2,-\whpyr/2,\waterlevel)
     -- (\whpyr/2,-\whpyr/2,\waterlevel) -- (\whpyr/2,\whpyr/2,\waterlevel) 
     -- (\wtop/2,\wtop/2,\zpyr+\hpyr-\hremoved) 
     -- (-\wtop/2,\wtop/2,\zpyr+\hpyr-\hremoved)
     -- (-\wtop/2,-\wtop/2,\zpyr+\hpyr-\hremoved) -- (-\whpyr/2,-\whpyr/2,\waterlevel)
     [reverseclip];
    \fi
    \fill[blue,opacity=0.2] 
    plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi+360] ({\rcyl*cos(\t)},{\rcyl*sin(\t)},\waterlevel);
  \end{scope} 
   \fill[blue,opacity=0.4] 
   plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi-180] 
   ({\rcyl*cos(\t)},{\rcyl*sin(\t)},\waterlevel)
   -- 
   plot[smooth,variable=\t,domain=\tdplotmainphi-180:\tdplotmainphi] 
   ({\rcyl*cos(\t)},{\rcyl*sin(\t)},0);
  \draw plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi-180] 
  ({\rcyl*cos(\t)},{\rcyl*sin(\t)},0)
   --  plot[smooth,variable=\t,domain=\tdplotmainphi-180:\tdplotmainphi+180] ({\rcyl*cos(\t)},{\rcyl*sin(\t)},\hcyl)
   ({\rcyl*cos(\tdplotmainphi)},{\rcyl*sin(\tdplotmainphi)},0) --
   ({\rcyl*cos(\tdplotmainphi)},{\rcyl*sin(\tdplotmainphi)},\hcyl);
  \draw (hang) --  (0,0,\zpyr+\hpyr-\hremoved);
%   \node[anchor=north west,tdplot_screen_coords,align=right] 
%   at (1,7.75){\waterlevel\\ \zpyr};
\end{tikzpicture}}
\end{document}

enter image description here

  • The top of the pyramid should be removed so that the resulting cross-section is a square. The rope is attached to the center of that square. – Epa Feb 04 '19 at 06:28
  • One more photo has been added marmot. – Epa Feb 04 '19 at 06:32
  • 3
    Well, the pyramid is apparently full of holes -- the water level does not rise during the lowering of the pyramid. ;-) –  Feb 04 '19 at 09:28
  • 1
    @ChristianHupfer Perhaps the dotted line at the bottom suggests an infinitely long cilinder? –  Feb 04 '19 at 12:09
  • 2
    @ChristianHupfer That's a so-called well-tempered pyramid, which changes the water temperature in such a way that the water level remains constant. ;-) –  Feb 04 '19 at 15:31
  • @marmot: Seems to be a pyramid that has much knowledge about the laws of thermodynamics then ;-) –  Feb 04 '19 at 15:35
  • @ChristianHupfer Better now? –  Feb 06 '19 at 06:04
  • Wow, I'm amazed that you actually calculated the displacement! – Circumscribe Feb 06 '19 at 10:40
  • @Circumscribe Thanks a lot! Yes, you are right. Both about the factor 1/3 and the fact that this is not the full result. I added the factor 1/3. The full formula is really lengthy, so I let it be. –  Feb 06 '19 at 15:24
  • 1
    @marmot: Yeah, that's probably wise, since it'd be hard to notice the difference. The change in water level looks more realistic now, but also less impressive somehow :). – Circumscribe Feb 06 '19 at 15:31