0

The hydrostatic paradox, states that the height of the water in any container is independent of the shape of the container. The picture is like this.

hydrostatic paradox

I could define every corner to draw the black lines, and then use some of them to define the blue zone. But I don't think it is the correct way to do it.

So I don't have a MWE because, the approach of the answer is presumably totally different than my idea. (drawing is just as illustration)

Any suggestions?

  • You could at least draw the black lines shape as a MWE. That way those trying to help can focus on the solution as opposed to setting up the problem test case. My suggestion would be to draw the water as a rectangle and then clip it. – Peter Grill Sep 18 '16 at 11:52
  • 1
    Fill the background with blue rectangle clipped with your lines – percusse Sep 18 '16 at 11:53
  • @PeterGrill Ok I will look for 'clip it'. The drawing is just an illustration, I only wanted the principe of the answer... – Arne Timperman Sep 18 '16 at 12:04
  • 1
    BTW, a refinement of the model would have to take the capillary action into account. – Heiko Oberdiek Sep 18 '16 at 13:42
6

The code defines the connected line paths as macros \PathA to \PathE.

The paths are combined to a closed path for filling. The height setting is achieved by using a rectangle as clip path with the desired fill height.

Finally the line paths are drawn.

\documentclass{article}
\usepackage{tikz}

\begin{document}
  \newcommand*{\Drawing}[1]{%    
    \begin{tikzpicture}
      \def\unit{5mm}
      \tikzset{
        x=\unit,
        y=\unit,
      }

      \def\PathA{% from right to left
        (17, 5) -- (18, 4) -- (18, 3.5)
        -- (17, 2.5) -- (17, 0) -- (0, 0) -- (0, 5)
      }
      \def\PathB{
        (1, 5) -- (1, 1)
        -- (3, 1) -- (3, 3) -- (2, 5)
      }
      \def\PathC{
        (5, 5) -- (4, 3) -- (4, 1)
        -- (6, 1) -- (8, 5)
      }
      \def\PathD{
        (9, 5) -- (11, 1)
        -- (12, 1) -- (12, 2) -- (13, 3) -- (11, 5)
      }
      \def\PathE{
        (12, 5) -- (14, 3) -- (13, 2) -- (13, 1)
        -- (16, 1) -- (16, 2.5) -- (15, 3.5) -- (15, 4) -- (16, 5)
      }
      \begin{scope}
        \clip (0, 0) rectangle (18, #1);
        \fill[blue]
          \PathA -- \PathB -- \PathC -- \PathD -- \PathE -- cycle
        ;
      \end{scope}
      \draw[very thick, line cap=round]
        \PathA
        \PathB
        \PathC
        \PathD
        \PathE
      ;
    \end{tikzpicture}%
    \newpage
  }
  \foreach \h in {0, .25, ..., 5} {
    \Drawing\h
  }
\end{document}

The image of the question is available as \Drawing{4}. The animated version:

Animation

A version without clipping:

  • Explanation off your solution made an other 'learn something LaTeX every day"-day – Arne Timperman Sep 18 '16 at 14:21
  • 1
    To avoid the line at the top for the full fill height, I have simplified the algorithm. – Heiko Oberdiek Sep 18 '16 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.