# Water inside a hemispherical bowl

I am trying to draw the diagram below in latex I got this far with the following code: \documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyhdr}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{color,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{graphicx}
\usetikzlibrary{arrows}
\usepackage{polynom}
\usepackage{flexisym}
\usepackage{wallpaper}
\usepackage{blkarray}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations.markings}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
A hemispherical bowl of radius $5.1$ cm contains water of depth $3.5$ cm, as shown below.
\begin{center}
\begin{tikzpicture}[scale=0.75]
%\draw (-2.5,-1.65) arc (180:360:2.5 and 0.25);
%BIG CIRCLE
\draw[thick](-3.2,+0.04) arc (180:360:3.2 and 1.05);
\draw[thick](-3.2,+0.04) arc (3.2:180:-3.2 and 1.05);
%SMALL CIRLCE
\draw[dashed](-2.85,-1.34) arc (180:360:2.85 and 0.8);
\draw[dashed](-2.85,-1.34) arc (2.85:180:-2.85 and 1.05);
%triangle
%\draw[gray,dashed](0,0) -- (+2.84,-1.52);
%\draw[gray,dashed](0,0) -- (0,-1.52);
%\draw[gray,dashed](0,-1.52) --(+2.9,-1.52);
%
%\draw (0,0) ++(0:2.8) arc (0:-45:2.8);
\draw [thick,domain=-180:0] plot ({3.2*cos(\x)}, {3.2*sin(\x)}) ;
%\node[below] at (0,-1.52) {A};
%\node[right] at (2.84,-1.52) {B};
%
%\draw [thick,fill=black] (0,-1.52) circle (0.04);
\draw [thick,fill=black] (0,0) circle (0.04);
%\draw [thick,fill=black] (2.81,-1.52) circle (0.04);
\node[above] at (0,0.2) {O};
%
%\draw[gray,dashed] (0,-1.52) -- (3.8,-1.52);
%\draw[gray,dashed] (0,-3.22) -- (3.8,-3.22);
%\draw[thick,<->](3.4,-1.52) to node[fill=white] {$3.5$ cm} (3.4,-3.22);
\end{tikzpicture}
\end{center}
\end{document}


Can someone suggest how to do the shading so I can complete this diagram?

Thank you.

## 2 Answers

\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[>=latex']
\draw[xshift=1.9cm,densely dashed,<->] (1,-1) -- (1,-1.5) node[midway,right] {\tiny $2\,\mathrm{cm}$};
\draw[densely dashed] (2,-1) --+ (.9,0);
\draw[densely dashed] (1.5,-1.5) --+ (1.4,0);
\begin{scope}
\clip[draw] (0,0) arc(180:360:1.5) (1.5,0) circle(1.5 and .5);
\draw[fill=gray!40] (.4,-1) arc(180:360:{.73*1.5} and .2);
\draw[fill=gray!40,dashed] (2.59,-1) arc(0:180:{.73*1.5} and .2);
\draw[gray!40] (.4,-1) -- (2.589,-1);
\fill[gray!40] ({2.4*.73*1.5},-1) arc(0:-180:{.73*1.5} and .6);
\draw (0,0) arc(180:360:1.5);
\draw[densely dashed,<->] (1.5,0) -- (3,0) node[midway,above] {\tiny $10\,\mathrm{cm}$};
\end{scope}
\draw (2.6,-1) arc(0:-180:{.73*1.5} and .2);
\end{tikzpicture}
\end{document}


Here is the output: • @Harald_Hanche-Olsen: Thank you, I've got some bug, so that I can't format the code … – current_user Sep 10 '18 at 10:40
• In the preview it is alright, but in the answer it isn't anymore! – current_user Sep 10 '18 at 10:42
• @Harald_Hanche-Olsen: Sorry, didn't want that. I fixed my code, so could you please do it one more time for me? – current_user Sep 10 '18 at 10:45
• @Harald_Hanche-Olsen: imgur.com/a/YxcmzdZ – current_user Sep 10 '18 at 10:49
• That's odd. All I've done is add four spaces at the very beginning, before \documentclass. Is it possible that your browser, somehow, removes initial spaces? Anyhow, it seems okay now. PS: These comments aren't really useful for posterity, so I am removing mine (except this one). Suggest you do the same. – Harald Hanche-Olsen Sep 10 '18 at 10:51

I know I'm quite late to the party, but I took this question as an opportunity to learn some more on the projection of spheres, and to re-use my answer here. I created a partially filled sphere, with a predetermined level \waterlevel which should be between 0 and 1, which is projected with a certain elevation angle \el which should be between 0 and 90. The best results are obtained with 0.2 < \waterlevel < 1 and 10 < \el < 40. In the following example \el is set to 20 and the \waterlevel to 0.5. Of course, an animation can be made easily (with \el still set to 20): Disclaimer
The projection of the hemisphere is correct, as is the projection of the water surface. The shading of the water is not completely correct. The 'front view', the part of the water that is touching the sphere, is an approximation, but that is invisible with \waterlevel above approximately 0.35.

MWE:

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

\usetikzlibrary{3d}

% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
\def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
\def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
\def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
\tikz@canvas@is@plane}

% view={<azimuth>,<elevation>} key https://tex.stackexchange.com/a/447401/74459
\tikzset{
view/.code args={#1,#2}{%
% Set elevation and azimuth angles
\pgfmathsetmacro\view@az{#1}
\pgfmathsetmacro\view@el{#2}
% Calculate projections of rotation matrix
\pgfmathsetmacro\xvec@x{cos(\view@az)}
\pgfmathsetmacro\xvec@y{-sin(\view@az)*sin(\view@el)}
\pgfmathsetmacro\yvec@x{sin(\view@az)}
\pgfmathsetmacro\yvec@y{cos(\view@az)*sin(\view@el)}
\pgfmathsetmacro\zvec@x{0}
\pgfmathsetmacro\zvec@y{cos(\view@el)}
% Set base vectors
\pgfsetxvec{\pgfpoint{\xvec@x cm}{\xvec@y cm}}
\pgfsetyvec{\pgfpoint{\yvec@x cm}{\yvec@y cm}}
\pgfsetzvec{\pgfpoint{\zvec@x cm}{\zvec@y cm}}
},
}
\makeatother

\begin{document}

\begin{tikzpicture}[scale=0.75,water shading/.style={ball color=cyan!50!white,fill opacity=0.5}]

% PRE-CALCULATIONS
\pgfmathsetmacro\el{20}
\pgfmathsetmacro\radius{3.2}
\pgfmathsetmacro\smallradius{sin(\el)*\radius}
\pgfmathsetmacro\waterlevel{0.5} % between 0 and 1
\pgfmathsetmacro\waterradius{sin(acos(-1+\waterlevel))*\radius}
\pgfmathsetmacro\watersmallradius{sin(\el)*\waterradius}

%SHADING
% Two shading paths to mimic the different light refraction of the front and the surface
\path[water shading] ({-asin(1-\waterlevel)}:\radius)
arc ({-asin(1-\waterlevel)}:{-180+asin(1-\waterlevel)}:\radius)
-- (-\waterradius,{-(1-\waterlevel)*\radius*cos{\el}})
arc (180:0:{\waterradius} and {\watersmallradius}) -- cycle;
\path[water shading] ({-asin(1-\waterlevel)}:\radius)
arc ({-asin(1-\waterlevel)}:{-180+asin(1-\waterlevel)}:\radius)
-- (-\waterradius,{-(1-\waterlevel)*\radius*cos{\el}})
arc (-180:0:{\waterradius} and {\watersmallradius}) -- cycle;

%BIG CIRCLE
% Due to the 'view' key, a circle with a fixed radius becomes an ellipse
\draw[thick,view={0,\el},canvas is xy plane at z=0] (0,0) circle (\radius);
% No matter what the elevation of the view is, a (half-)sphere is always projected as a (half-)circle.
\draw[thick] (0,0) ++(0:\radius) arc (0:-180:\radius);
%SMALL CIRLCE
% Again using the 'view' key, the small circle can be drawn as two seperate arcs with fixed radius.
\draw[dashed,view={0,\el},canvas is xy plane at z={-(1-\waterlevel)*\radius}]
(0,0) ++(0:\waterradius) arc (0:180:\waterradius);
\draw[view={0,\el},canvas is xy plane at z={-(1-\waterlevel)*\radius}]
(0,0) ++(0:\waterradius) arc (0:-180:\waterradius);

%triangle
%\draw[gray,dashed](0,0) -- (+2.84,-1.52);
%\draw[gray,dashed](0,0) -- (0,-1.52);
%\draw[gray,dashed](0,-1.52) --(+2.9,-1.52);
%
%\node[below] at (0,-1.52) {A};
%\node[right] at (2.84,-1.52) {B};
%
%\draw [thick,fill=black] (0,-1.52) circle (0.04);
\draw [thick,fill=black] (0,0) circle (0.04);
%\draw [thick,fill=black] (2.81,-1.52) circle (0.04);
\node[above] at (0,0.2) {O};
%
%\draw[gray,dashed] (0,-1.52) -- (3.8,-1.52);
%\draw[gray,dashed] (0,-3.22) -- (3.8,-3.22);
%\draw[thick,<->](3.4,-1.52) to node[fill=white] {$3.5$ cm} (3.4,-3.22);
\end{tikzpicture}

\end{document}


MWE animation:

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

\usetikzlibrary{3d}

% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
\def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
\def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
\def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
\tikz@canvas@is@plane}

% view={<azimuth>,<elevation>} key https://tex.stackexchange.com/a/447401/74459
\tikzset{
view/.code args={#1,#2}{%
% Set elevation and azimuth angles
\pgfmathsetmacro\view@az{#1}
\pgfmathsetmacro\view@el{#2}
% Calculate projections of rotation matrix
\pgfmathsetmacro\xvec@x{cos(\view@az)}
\pgfmathsetmacro\xvec@y{-sin(\view@az)*sin(\view@el)}
\pgfmathsetmacro\yvec@x{sin(\view@az)}
\pgfmathsetmacro\yvec@y{cos(\view@az)*sin(\view@el)}
\pgfmathsetmacro\zvec@x{0}
\pgfmathsetmacro\zvec@y{cos(\view@el)}
% Set base vectors
\pgfsetxvec{\pgfpoint{\xvec@x cm}{\xvec@y cm}}
\pgfsetyvec{\pgfpoint{\yvec@x cm}{\yvec@y cm}}
\pgfsetzvec{\pgfpoint{\zvec@x cm}{\zvec@y cm}}
},
}
\makeatother

\begin{document}

\pgfmathsetmacro\el{20}

\foreach \fr [evaluate=\fr as \wl using {\fr/100}] in {0,5,...,100}{
\begin{tikzpicture}[scale=0.75,water shading/.style={ball color=cyan!50!white,fill opacity=0.5}]

% PRE-CALCULATIONS
\pgfmathsetmacro\radius{3.2}
\pgfmathsetmacro\smallradius{sin(\el)*\radius}
\pgfmathsetmacro\waterlevel{\wl} % between 0 and 1
\pgfmathsetmacro\waterradius{sin(acos(-1+\waterlevel))*\radius}
\pgfmathsetmacro\watersmallradius{sin(\el)*\waterradius}

%CLIPPING
% For the animation only (I think this is required because arcs are drawn as Bezier curves with control points that contribute to the bounding box)
\clip ({-1.2*\radius},{-1.2*\radius}) rectangle ({1.2*\radius},{1.5*\smallradius});

%SHADING
% Two shading paths to mimic the different light refraction of the front and the surface
\path[water shading] ({-asin(1-\waterlevel)}:\radius)
arc ({-asin(1-\waterlevel)}:{-180+asin(1-\waterlevel)}:\radius)
-- (-\waterradius,{-(1-\waterlevel)*\radius*cos{\el}})
arc (180:0:{\waterradius} and {\watersmallradius}) -- cycle;
\path[water shading] ({-asin(1-\waterlevel)}:\radius)
arc ({-asin(1-\waterlevel)}:{-180+asin(1-\waterlevel)}:\radius)
-- (-\waterradius,{-(1-\waterlevel)*\radius*cos{\el}})
arc (-180:0:{\waterradius} and {\watersmallradius}) -- cycle;

%BIG CIRCLE
% Due to the 'view' key, a circle with a fixed radius becomes an ellipse
\draw[thick,view={0,\el},canvas is xy plane at z=0] (0,0) circle (\radius);
% No matter what the elevation of the view is, a (half-)sphere is always projected as a (half-)circle.
\draw[thick] (0,0) ++(0:\radius) arc (0:-180:\radius);
%SMALL CIRLCE
% Again using the 'view' key, the small circle can be drawn as two seperate arcs with fixed radius.
\draw[dashed,view={0,\el},canvas is xy plane at z={-(1-\waterlevel)*\radius}]
(0,0) ++(0:\waterradius) arc (0:180:\waterradius);
\draw[view={0,\el},canvas is xy plane at z={-(1-\waterlevel)*\radius}]
(0,0) ++(0:\waterradius) arc (0:-180:\waterradius);

%triangle
%\draw[gray,dashed](0,0) -- (+2.84,-1.52);
%\draw[gray,dashed](0,0) -- (0,-1.52);
%\draw[gray,dashed](0,-1.52) --(+2.9,-1.52);
%
%\node[below] at (0,-1.52) {A};
%\node[right] at (2.84,-1.52) {B};
%
%\draw [thick,fill=black] (0,-1.52) circle (0.04);
\draw [thick,fill=black] (0,0) circle (0.04);
%\draw [thick,fill=black] (2.81,-1.52) circle (0.04);
\node[above] at (0,0.2) {O};
%
%\draw[gray,dashed] (0,-1.52) -- (3.8,-1.52);
%\draw[gray,dashed] (0,-3.22) -- (3.8,-3.22);
%\draw[thick,<->](3.4,-1.52) to node[fill=white] {$3.5$ cm} (3.4,-3.22);
\end{tikzpicture}
}
\end{document}