2

Yo

\begin{tikzpicture}
\draw (0,0) -- (0,3cm); 
\draw (0.5cm,0) -- (0.5cm,3cm);
\draw (3cm,0) -- (3cm,3cm);
\draw (3.5cm,0) -- (3.5cm,3cm);
\draw (0,0) arc (0:180:-1.75cm);
\draw (0.5cm,0) arc (0:180:-1.25cm);


\draw [fill=blue,blue] (0,0) rectangle (0.5cm,1cm);
\draw [fill=blue,blue] (3cm,0) rectangle (3.5cm,2.5cm);
\draw[dashed] (0.5cm,1cm) -- (4.5cm,1cm);
\draw[dashed] (3.5cm,2.5cm) -- (4.5cm,2.5cm);
\draw[<->] (4.5cm,1cm) -- (4.5cm,2.5cm) node[midway,right] {$\Delta h$};

\def\Radius{1.75cm}
\def\radius{1.25cm}
 \begin{scope}[even odd rule]
 \clip circle[radius=\Radius];
  \clip[rotate=0] (0,0) -- (0:\Radius) arc (0:-180:\Radius)--cycle;
 \fill[blue] 
  circle[radius=\Radius]
  circle[radius=\radius]
    ;
  \end{scope}
\end{tikzpicture}

For some reason, the scope isn't on top of my other lines although I have set them all up to start at (0,0). Any suggestions on how I make this work? Tikz-Drawing

  • Welcome to TeX.SX! Please always provide a full MWE that also comprises your documentclass etc. – Jasper Habicht Aug 6 '18 at 17:19
6

This is not an answer but just a comment. You can do that much easier. (EDIT: fixed the water level on the left, sorry, did not pay enough attention.)

\documentclass[border=3.14mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw [double distance=0.5cm] (0.25,3) -- (0.25,0) arc(0:180:-1.5cm)
-- (3.25,3);
\draw [blue,line width=0.5cm] (0.25,1) -- (0.25,0) arc(0:180:-1.5cm)
-- (3.25,2.5);
\draw[dashed] (0.5cm,1cm) -- (4.5cm,1cm);
\draw[dashed] (3.5cm,2.5cm) -- (4.5cm,2.5cm);
\draw[<->] (4.5cm,1cm) -- (4.5cm,2.5cm) node[midway,right] {$\Delta h$};
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    Neat and simple solution. – Diaa Aug 6 '18 at 21:09
  • 1
    @Diaa Thanks for pinging me, this made me spot a(nother) bug, and thanks for your nice comment! ;-) – marmot Aug 6 '18 at 21:24
5

This is because you draw the first shape using arc and the second by drawing a circle. A circle is drawn around its center which you defined implicitly as (0,0), and hence the shift. You can shift the scope by 1.75cm to fit it to the other shapes.

\documentclass[border=5pt,tikz]{standalone}
\begin{document}

\begin{tikzpicture}

\fill[blue] (0,0) rectangle (0.5cm,1cm); 
\fill[blue] (3cm,0) rectangle (3.5cm,2.5cm); 

\def\Radius{1.75cm} 
\def\radius{1.25cm} 
\begin{scope}[xshift=1.75cm,even odd rule] 
  \clip (0,0) -- (0:\Radius) arc (0:-180:\Radius) -- cycle; 
  \fill[blue] circle[radius=\Radius] circle[radius=\radius]; 
\end{scope} 

\draw (0,0) -- (0,3cm); 
\draw (0.5cm,0) -- (0.5cm,3cm); 
\draw (3cm,0) -- (3cm,3cm); 
\draw (3.5cm,0) -- (3.5cm,3cm); 
\draw (0,0) arc (0:180:-1.75cm); 
\draw (0.5cm,0) arc (0:180:-1.25cm);

\draw[dashed] (0.5cm,1cm) -- (4.5cm,1cm); 
\draw[dashed] (3.5cm,2.5cm) -- (4.5cm,2.5cm); 
\draw[<->] (4.5cm,1cm) -- (4.5cm,2.5cm) node[midway,right] {$\Delta h$};

\end{tikzpicture}

\end{document}

Edit: I rearranged the shapes so that the blue shape is behind the lines. This way, the lines will be visible.

Here is the output:

enter image description here

  • I am sorry for asking this simple question, but could you refer me the section in the TikZ manual where I can understand what the scope environment does here in your code? – Diaa Aug 6 '18 at 17:32
  • 1
    I just used this approach because the the OP also used it. The scope is mainly used to make clipping possible (2.11 „Clipping a Path“ on page 35 of the current manual). If you only want to clip a certain part of your drawing you have to use such a scope. Everything in this scope will then be clipped, but the rest of the picture will not be affected by the clipping (see: tex.stackexchange.com/questions/330882/…). – Jasper Habicht Aug 6 '18 at 17:49
  • I highly appreciate your consideration to respond to my inquiry. I will certainly look at what you referred to. Thanks! – Diaa Aug 6 '18 at 18:04
5

slightly modified code of the interesting marmot's "comment" (+1). it exploit more possibilities of double path option . for exercise :-)

\documentclass[tikz, margin=3mm]{standalone}

\begin{document}
\begin{tikzpicture}[DS/.style={double distance=5mm, semithick, double=#1}]
\draw [DS=white]    (0,3) -- (0,0)
                    (3,2.5) -- (3,3);
\draw [DS=blue!50]  (0,0) arc(0:180:-1.5cm) -- (3,2.5);
%
\draw[densely dashed]   (0.25,0.0) -- (4.45,0.0)
                        (3.25,2.5) -- (4.45,2.5);
\draw[<->] (4.35,0) -- node[right] {$\Delta h$} (4.35,2.5) ;
\end{tikzpicture}
\end{document}

enter image description here

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.