I would like to construct a diagram of a cube sitting inside a sphere. I can draw them both separately, but need some idea of how to construct the diagram such that the cube sits exactly within the sphere, the relationship between the side of the cube and the radius of the sphere would then be r=sqrt(3)*s/2, where r is the radius of the sphere holding the cube of side length s.
@Torbjørn T. @hugovdberg - Thanks for your suggestion! I tried the following code, borrowing parts from segments available on the web. However, my sphere currently does not sit correctly at the same position of the cube. Also, I have the orientation of the sphere in error.
\documentclass[11pt]{scrartcl}
\PassOptionsToPackage{dvipsnames,svgnames}{xcolor}
\usepackage{xkeyval,tkz-base}
\usetikzlibrary{arrows,calc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
[cube/.style={very thick,black},
grid/.style={very thin,gray},
axis/.style={->,blue,thick}]
%draw a grid in the x-y plane
\foreach \x in {-0.5,0,...,2.5}
\foreach \y in {-0.5,0,...,2.5}
{
\draw[grid] (\x,-0.5) -- (\x,2.5);
\draw[grid] (-0.5,\y) -- (2.5,\y);
}
%draw the axes
\draw[axis] (0,0,0) -- (3,0,0) node[anchor=west]{$x$};
\draw[axis] (0,0,0) -- (0,3,0) node[anchor=west]{$y$};
\draw[axis] (0,0,0) -- (0,0,3) node[anchor=west]{$z$};
%draw the top and bottom of the cube
\draw[cube] (0,0,0) -- (0,2,0) -- (2,2,0) -- (2,0,0) -- cycle;
\draw[cube] (0,0,2) -- (0,2,2) -- (2,2,2) -- (2,0,2) -- cycle;
%draw the edges of the cube
\draw[cube] (0,0,0) -- (0,0,2);
\draw[cube] (0,2,0) -- (0,2,2);
\draw[cube] (2,0,0) -- (2,0,2);
\draw[cube] (2,2,0) -- (2,2,2);
\foreach \t in {0,10,...,180}
{\draw[gray] ({2*cos(\t)},{2*sin(\t)},0)
\foreach \rho in {5,10,...,360}
{--({2*cos(\t)*cos(\rho)},{2*sin(\t)*cos(\rho)},
{2*sin(\rho)})}--cycle;
}
\foreach \t in {-90,-85,...,90}% parallels
{\draw[gray] ({2*cos(\t)},0,{2*sin(\t)})
\foreach \rho in {5,10,...,360}
{--({2*cos(\t)*cos(\rho)},{2*cos(\t)*sin(\rho)},
{2*sin(\t)})}--cycle;
}
\end{tikzpicture}
\end{document}

I managed to eventually produce the figure that I was seeking. The cube now sits inside the sphere and each have a common centre at (1,1,1).

pgfplotsyou can easily draw a 3d axis system, take a look at the manual how to do that. Inside the axis you can just use TikZ as you can outside, and you can use theaxis cscoordinate system to position your cube and sphere inside the axis. If you need any help on the exact details, please post a minimal working example as suggested by Torbjørn. – hugovdberg Mar 13 '14 at 16:31