tikz add tag
MinhKhai
I am trying to draw a sphere and a rectangular box like this here. I tried
![hinhcau.PNG](/image?hash=574a452d045eaba751bbcaa8d321b764fdb0c5a349af64d68fc3975e1ea13e7c)

```
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot-circleofsphere}
\begin{document}
 \tdplotsetmaincoords{80}{110}
 \begin{tikzpicture}[tdplot_main_coords,ultra thin,declare function={r=3;}]
 \draw[ball color=gray,opacity=.5,tdplot_screen_coords] (0,0,0) circle (r);
 \draw[densely dotted,thin](-r,0,0)circle(.6pt)node[scale=.5,above]{$A$}
 --(0,r,0)circle(.6pt)node[scale=.5,above]{$B$}
 --(r,0,0)circle(.6pt)node[scale=.5,above]{$C$}
 --(0,-r,0)circle(.6pt)node[scale=.5,above]{$D$}--(-r,0,0)--(r,0,0) (0,r,0)--(0,-r,0)
 (0,r,-r/sqrt 2)--(-r,0,-r/sqrt 2)circle(.6pt)node[scale=.5,below]{$A'$}
 --(0,-r,-r/sqrt 2)circle(.6pt)node[scale=.5,below]{$D'$}
 (-r,0,-r/sqrt 2)--(r,0,-r/sqrt 2) (0,r,-r/sqrt 2)--(0,-r,-r/sqrt 2)
 (-r,0,0)--(-r,0,-r/sqrt 2) (0,-r,0)--(0,-r,-.6*r/sqrt 2)  ;
\draw  (0,r,-r/sqrt 2)circle(.6pt)node[scale=.5,below]{$B'$}--(r,0,-r/sqrt 2)circle(.6pt)node[scale=.5,below]{$C'$}--(0,-r,-r/sqrt 2)
(r,0,0)--(r,0,-r/sqrt 2) (0,r,0)--(0,r,-r/sqrt 2)
(0,-r,-r/sqrt 2)--(0,-r,-.6*r/sqrt 2)
 ;
 \tdplotCsDrawLatCircle{r}{0}
 \tdplotCsDrawLatCircle{r}{-45}
 \end{tikzpicture}
 \end{document}
```
How to draw like above?
Top Answer
Anonymous 1123
You can try this code
```
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools
\usepackage{tikz-3dplot-circleofsphere}
\begin{document}
	\pgfdeclarelayer{background} 
	\pgfdeclarelayer{foreground}
	\pgfsetlayers{background,main,foreground}  
	\tikzset{reverseclip/.style={overlay,insert path={(-12383.99999pt,-12383.99999pt) rectangle (12383.99999pt,12383.99999pt)}}}
	\begin{tikzpicture}[3d/install view={phi=70,theta=80},scale=1,line cap=butt,
		line join=round,visible/.style={draw,solid},
		hidden/.style={draw,very thin,cheating dash},declare function={r = 3; h = -r/sqrt(2);}] 
		\path
		(0,0,0) coordinate (O)
		(-r,0,0) coordinate (A)
		(0,r,0)  coordinate (B)
		(r,0,0) coordinate (C)
		(0,-r,0) coordinate (D)
		(-r,0,h) coordinate (A')
		(0,r,h)  coordinate (B')
		(r,0,h) coordinate (C')
		(0,-r,h) coordinate (D')
		;
		\path[3d coordinate ={(O')=0.5*(A') + 0.5*(C')}];
		\path[3d/circumcircle center={A={(A)},B={(B)},C={(C)}}] coordinate (T); 
		\pgfmathsetmacro{\myR}{sqrt(TD("(A)-(B)o(A)-(B)"))/2} ;
		\draw[hidden]  (O') circle[radius=\myR];
		\path  pic{3d/circle on sphere={R=r,C={(O)}, P={(T)}}};
		\draw[3d/screen coords,hidden] (O) circle[radius=r];
		\begin{scope}
			\clip (D) -- (D') -- (C')  -- (C) --cycle [reverseclip];
			\draw[3d/screen coords] (O) circle[radius=r];
		\end{scope}
	
	\begin{scope}[tdplot_screen_coords]
	\clip  (O) circle[radius=r][reverseclip];
	\draw[visible] (B) -- (B');
\end{scope}

\begin{scope}[tdplot_screen_coords]
\clip  (O) circle[radius=r];
	\draw[hidden] (B) -- (B');
\end{scope}
	
	\foreach \p in {A,B,C,D,A',B',C',D',O,O'}
		{\draw[fill=black] (\p) circle (1.2 pt);}
		\foreach \p/\g in {A/90,B/120,C/60,D/60,A'/150,B'/-90,C'/-90,D'/-90,O/60,O'/210}
		{\path (\p)+(\g:3mm) node{$\p$};}
		\draw[hidden] 
		(A) -- (B) -- (C) -- (D) -- cycle
		(D') -- (A') -- (B') (A) -- (A') (A) -- (C) (B) -- (D) (A') -- (C') (B') -- (D');
		\draw[visible]  (C) -- (C') (D) -- (D') (D') -- (C') -- (B');
	\end{tikzpicture}
\end{document} 
```
![ScreenHunter 1105.png](/image?hash=84fd4f0ee43990e8a27726aea5ff18304ce09d856708e4313ef4096cb9402d3d)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.