I wish to draw triangular pyramids of oranges. The kth layer has k(k + 1)/2 oranges, the kth triangular number. The number of oranges in the nth stack is n(n + 1)(n + 2)/6, the nth tetrahedral number. My code and the output it produces are shown below.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{3d}
\usetikzlibrary{shadings}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=0.5]
\shade[ball color = orange] (0, 0) circle (0.866 cm);
\node at (0, -4) {\(n = 1\)};
\begin{scope}[xshift = 6 cm]
\shade[ball color = orange] (0.866, 1/2, 0) circle (0.866 cm);
\shade[ball color = orange] (-0.866, 1/2, 0) circle (0.866 cm);
\shade[ball color = orange] (0, -1, 0) circle (0.866 cm);
\shade[ball color = orange] (0, 0, 1.414) circle (0.866 cm);
\node at (0, -4) {\(n = 2\)};
\end{scope}
\begin{scope}[xshift = 15 cm]
\shade[ball color = orange] (0, 1, 0) circle (0.866 cm);
\shade[ball color = orange] (-1.732, 1, 0) circle (0.866 cm);
\shade[ball color = orange] (1.732, 1, 0) circle (0.866 cm);
\shade[ball color = orange] (-0.866, -1/2, 0) circle (0.866 cm);
\shade[ball color = orange] (0.866, -1/2, 0) circle (0.866 cm);
\shade[ball color = orange] (0, -2, 0) circle (0.866 cm);
\shade[ball color = orange] (-0.866, 1/2, 1.414) circle (0.866 cm);
\shade[ball color = orange] (0.866, 1/2, 1.414) circle (0.866 cm);
\shade[ball color = orange] (0, -1, 1.414) circle (0.866 cm);
\shade[ball color = orange] (0, 0, 2.828) circle (0.866 cm);
\node at (0, -4) {\(n = 3\)};
\end{scope}
\end{tikzpicture}
\caption{Triangular pyramids of oranges.}
\label{figure:triangular_pyramids_of_oranges}
\end{figure}
How can I rotate the stacks so that it looks like they are growing upwards rather than out of the page?
Also, I worked out the coordinates by hand using coordinate geometry and trigonometry. Is there a more efficient method for generating these pyramids?