\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{enumerate}
\usepackage{ifthen}
\usepackage{ulem} % for strikethrough \sout{...} command
\usepackage{color}
\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{-0.5in}
\setlength{\topmargin}{-0.5in}
\setlength{\headheight}{0.0in}
\setlength{\headsep}{0.0in}
\setlength{\topskip}{0.0in}
\setlength{\textheight}{9.5in}
\setlength{\textwidth}{7.5in}

\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{tikz}
\usepgfplotslibrary{fillbetween}

%\newcommand{\bdot}{\, {\bf \cdot} \,}
\newcommand{\bdot}{\, {\scriptstyle{\bullet}} \,}
\newcommand{\B}[1]{{\bf {#1}}}
\newcommand{\la}{\langle}
\newcommand{\ra}{\rangle}

\newcommand{\force}{{$\mbox{\;}$}}

\begin{document}

%\pagestyle{empty}

\begin{center}
\huge Examples of {\sc Centroids}
\end{center}

\vspace{0.3in}

\noindent
Center of mass for a lamina in the plane ($\delta(x,y)$ is a density function -- mass per unit area):
$$\mbox{mass:} \quad m = \iint_R \delta\,dA \qquad \mbox{moments:} \quad M_y = \iint_R x\,\delta\,dA \qquad M_x = \iint_R y\,\delta\,dA \qquad \mbox{center of mass:} \quad (\bar{x},\bar{y}) = \left(\frac{M_y}{m},\frac{M_x}{m}\right)$$

\vspace{0.1in}

\noindent
Center of mass for a solid in 3-space ($\delta(x,y,z)$ is a density function -- mass per unit volume):
$$\mbox{mass:} \quad m = \iiint_E \delta\,dV \qquad \mbox{moments:} \quad M_{yz} = \iiint_E x\,\delta\,dV \qquad M_{xz} = \iiint_E y\,\delta\,dV \qquad M_{xy} = \iiint_E z\,\delta\,dV$$ $$\mbox{center of mass:} \quad (\bar{x},\bar{y},\bar{z}) = \left(\frac{M_{yz}}{m},\frac{M_{xz}}{m},\frac{M_{xy}}{m}\right)$$

\vspace{0.15in}

Here we present a few examples of centroids. Recall that a center of mass of a region with constant density (i.e. $\delta=1$) is called a {\it centroid}. In other words, the centroid of a region is its geometric center. First, we have two examples of centroids in $\mathbb{R}^2$. Then we  present two examples of centroids of solid regions in $\mathbb{R}^3$. 

\vspace{0.3in}

\noindent
\underline{\bf Example:} Find the centroid of $R = \{ (x,y) \mid x^2 + y^2 \leq 9 \mbox{ and } y \geq 0 \}$.

\noindent
\begin{minipage}{2.5in}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
  axis x line=middle, axis y line=middle,
  width=3in, height=2in,     % size of the image
  ymin=-0.5, ymax=3.75, ytick={0}, ylabel=${}$,
  xmin=-3.75, xmax=3.75, xtick={0}, xlabel=${}$,
]
\draw[name path=A] (axis cs:-3,0)--(axis cs:3,0);
\addplot[name path=B, domain=0:180] ({3*cos(x)},{3*sin(x)});
\addplot[blue!50] fill between[of=A and B];

\draw (axis cs:0,-0.25)--(axis cs:0,3.25);

\draw[ultra thick, red] (axis cs:0,0)--(axis cs:12/5,9/5);

\node at (axis cs:3.05,2.15) {$r=3$};

\node at (axis cs:-1,1.5) {$R$};

\node at (axis cs:3.25,-0.25) {$x$};
\node at (axis cs:-0.3,3.25) {$y$};
\end{axis}
\end{tikzpicture} 
\end{minipage}
\begin{minipage}{4.925in}
$$m = \iint\limits_R 1 \, dA = \frac12 \pi 3^2 = \frac{9\pi}{2}.$$

We see that, by symmetry, $\bar{x} = 0$. So we are left to compute $\bar{y}$. First, we find the moment about the $x$-axis:
$$\hspace{-0.35in} M_x = \iint\limits_R y \, dA = \int_0^\pi \int_0^3 r \sin(\theta)\cdot r \, dr\,d\theta = \int_0^\pi \sin(\theta) \, d\theta  \int_0^3 r^2 \, dr = 2\cdot\frac13\left[3^3 - 0 \right] = 18.$$
Hence $\bar{y} = \dfrac{18}{9\pi/2} = \dfrac4\pi$. We conclude that \fbox{$(\bar{x},\bar{y}) = \left(0, \dfrac4\pi\right)$ is the centroid of $R$.}
\end{minipage}

\vskip .3 in

\noindent
\underline{\bf Example:} Find the centroid of $R = \{(x,y) \mid x^2 + y^2 \leq 9 \mbox{ and } x,y \geq 0 \}$.

\noindent
\begin{minipage}{5.125in}
$$m = \iint\limits_R 1 \, dA = \frac14 \pi 3^2 = \frac94\pi.$$
$$M_y = \iint\limits_Rx \, dA = \int_0^{\pi/2} \!\! \int_0^3 r \cos(\theta)\cdot r \, dr\,d\theta = \int_0^{\pi/2} \!\!\!\cos(\theta) \, d\theta  \int_0^3 r^2 \, dr = 1\cdot\frac13\left[3^3 - 0 \right] = 9.$$
And so, we have that $\bar{x} = \dfrac{9}{9\pi/4} = \dfrac4\pi.$ Notice that, by symmetry, we have $\bar{x} = \bar{y}$ and hence we may conclude that \fbox{$(\bar{x},\bar{y}) = \left(\dfrac4\pi,\dfrac4\pi\right)$ is the centroid of $R$.}
\end{minipage}
\begin{minipage}{2.3in}
\force \hfill 
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
  axis x line=middle, axis y line=middle,
  width=3in, height=2.75in,     % size of the image
  ymin=-0.5, ymax=3.75, ytick={0}, ylabel=${}$,
  xmin=-0.75, xmax=3.75, xtick={0}, xlabel=${}$,
]
\draw[name path=A] (axis cs:0,0)--(axis cs:3,0);
\addplot[name path=B, domain=0:90] ({3*cos(x)},{3*sin(x)});
\addplot[blue!50] fill between[of=A and B];

\draw[ultra thick, red] (axis cs:0,0)--(axis cs:12/5,9/5);

\node at (axis cs:3.05,2.15) {$r=3$};

\node at (axis cs:1,2) {$R$};

\node at (axis cs:3.25,-0.25) {$x$};
\node at (axis cs:-0.3,3.25) {$y$};
\end{axis}
\end{tikzpicture} 
\end{minipage}

\vskip .2in

\newpage

\noindent
\underline{\bf Example:} Find the centroid of the solid cone $E = \{ (x,y,z) \mid \sqrt{x^2 + y^2} \leq z \leq 2 \}.$

\noindent
\begin{minipage}{2.5in}
\force

\vspace{0.8in}

\begin{tikzpicture}[scale=0.8]
\begin{axis}[
  axis x line=none, axis y line=none,
  width=3in, height=3.5in,     % size of the image
  ymin=-0.75, ymax=3, ytick={0}, ylabel=${}$,
  xmin=-1.25, xmax=1.25, xtick={0}, xlabel=${}$,
]

\addplot[name path=A1, domain=0:180] ({0.875*1*cos(x)},{0.875*0.5*sin(x)});
\addplot[name path=B1, domain=180:360] ({0.875*1*cos(x)},{0.875*0.5*sin(x)});
\addplot[gray!20] fill between[of=A1 and B1];

\draw[ultra thick,red] (axis cs:0,0)--(axis cs:{0.875*1*cos(215)},{0.875*0.5*sin(215)});

\node at (axis cs:-0.5,0.025) {$r=2$};

\addplot[domain=76:104,blue!75,ultra thick] ({0.875*1*cos(x)},{0.875*0.5*sin(x)});

\draw[thick,->] (axis cs:0,0)--(axis cs:{1.25*1*cos(255)},{1.25*0.5*sin(255)});
\draw[thick,->] (axis cs:0,0)--(axis cs:{1.15*1*cos(0)},{1.15*0.5*sin(0)});



\addplot[name path=A, domain=0:180] ({1*cos(x)},{0.5*sin(x)+2});
\addplot[name path=B, domain=180:360] ({1*cos(x)},{0.5*sin(x)+2});
\addplot[name path=C, domain=-1:1] ({x)},{1.95*abs(x)});
\addplot[blue!20] fill between[of=A and B];
\addplot[blue!75] fill between[of=B and C];

\draw[thick,->] (axis cs:0,2)--(axis cs:0,2.9);

\node at (axis cs:0,1.1) {\Large $E$};

\node at (axis cs:{1.25*1*cos(255)+0.15},{1.25*0.5*sin(255)}) {$x$};
\node at (axis cs:{1.15*1*cos(0)},{1.15*0.5*sin(0)+0.15}) {$y$};
\node at (axis cs:0.15,2.9) {$z$};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{4.925in}
$$\hspace{-0.6in} m = \iiint\limits_E 1 \, dV = \int_0^{2\pi} \int_0^2 \int_r^2 r \, dz\, dr\, d\theta = \int_0^{2\pi} d\theta \cdot \int_0^2\int_r^2\,dz\,dr = 2\pi \int_0^2 rz \bigg|_r^2 \, dr $$
$$= 2\pi \int_0^2 2r - r^2 \, dr  = 2\pi \left[ r^2 - \frac13r^3\right]\bigg|_0^2 = 2\pi\left[4 - \frac83\right] = \frac83\pi.$$

$$\hspace{-0.475in} M_{z=0} = M_{xy} =  \iiint\limits_E z \, dV =  \int_0^{2\pi} \int_0^2 \int_r^2 zr \, dz\, dr\, d\theta = \int_0^{2\pi} d\theta \cdot \int_0^2 \frac12 z^2r \bigg|_r^2 \, dr$$
$$ = 2\pi \int_0^2 2r - \frac12 r^3 dr = 2\pi \left[r^2 - \frac18 r^4 \right] \bigg|_0^2 = 2\pi [4-2] = 4\pi.$$
\end{minipage}
$$\bar{z} = \frac{4\pi}{8\pi/3} = \frac32 \mbox{and notice that $\bar{x} = \bar{y} = 0$ by symmetry so \fbox{$(\bar{x},\bar{y},\bar{z}) = \left(0,0,\dfrac32\right)$ is the centroid of $E$.}}$$

\vskip .3in

\noindent
\underline{\bf Example:} Centroid of the upper hemisphere $E = \{ (x,y,z) \mid 0 \leq z \leq \sqrt{4 - x^2 - y^2}\}$.

\vspace{0.1in}

\noindent
\begin{minipage}{5.125in}
$$m = \iiint\limits_E 1 \, dV = \frac12 \left[\frac43 \pi \cdot 2^3 \right] = \frac{16}{3}\pi.$$
Again, $\bar{x} = \bar{y} = 0$ by symmetry.
$$\hspace{-1.45in} M_{xy} =  \iiint\limits_E z \, dV =  \int_0^{2\pi} \int_0^{\pi/2}\int_0^2 \rho\cos(\varphi)\rho^2\sin(\varphi) \, d\rho\, d\varphi\, d\theta$$
$$\qquad = \int_0^{2\pi} d\theta \int_0^{\pi/2} \sin(\varphi)\cos(\varphi) \, d\varphi \int_0^2 \rho^3 \, d\rho
= 2\pi \cdot \frac12 \sin^2(\varphi) \bigg|_0^{\pi/2} \cdot \frac14 [2^4 - 0^4] = 4\pi$$
So, we have that $\bar{z} = \dfrac{4\pi}{16\pi/3}=\dfrac34$ and as a result\\ \force\hfill we conclude that the centroid of $E$ is \fbox{$(\bar{x},\bar{y},\bar{z}) = \left(0,0,\dfrac34\right).$}
\end{minipage}
\begin{minipage}{2.3in}
\force\qquad
\pgfplotsset{
  /pgfplots/colormap={mypink}{%
    color(0cm) = (purple);
    color(1cm) = (pink!80!purple);
    color(2cm) = (pink!90);
    color(3cm) = (pink) }
}
\pgfplotsset{
  /pgfplots/colormap={myblue}{%
    color(0cm) = (blue!55);
    color(1cm) = (blue!60);
    color(2cm) = (blue!65);
    color(3cm) = (blue!70) }
}
\pgfplotsset{
  /pgfplots/colormap={mygreen}{%
    color(0cm) = (green!40);
    color(1cm) = (green!60);
    color(2cm) = (green!80);
    color(3cm) = (green) }
}
\begin{tikzpicture}[scale=1.1]
    \begin{axis}[%
        axis equal,
        width=7cm,
        height=7cm,
        axis lines = none,
%        xlabel = {$x$},
%        ylabel = {$y$},
%        zlabel = {$z$},
        ticks=none,
%        enlargelimits=0.3,
%        view/h=15,
         view={35}{15},
%        colormap = {whiteblack}{color(0cm)  = (white);color(1cm) = (black)},
        scale uniformly strategy=units only,
    ]
   \addplot3[%
        opacity = 0.5,
        surf,
        z buffer = sort,
        samples = 20,
        colormap name=mygreen,
        variable = \u,
        variable y = \v,
        domain = 0:360,
        y domain = 0:90,
    ]
    ({cos(u)*sin(v)}, {sin(u)*sin(v)}, {0});
 
    \addplot3[%
        opacity = 0.5,
        surf,
        z buffer = sort,
        samples = 20,
        colormap name=myblue,
        variable = \u,
        variable y = \v,
        domain = 0:360,
        y domain = 0:90,
    ]
    ({cos(u)*sin(v)}, {sin(u)*sin(v)}, {cos(v)});

    \addplot3[->,thick,domain = 1:1.2] ({x},{0},{0});
    \addplot3[->,thick,domain = -1:-1.35] ({0},{x},{0});
    \addplot3[->,thick,domain = 1:1.35] ({0},{0},{x});

 
\end{axis}
\end{tikzpicture}
\end{minipage}

\end{document}