Use similar method to draw a sphere but didn't get correct result

At here How can I draw a sphere circumsribed a pyramid? I did similarly with this code. But I didn't get the correct result. My code

\documentclass[12pt,border=3mm]{standalone}
\usepackage{fouriernc}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc,backgrounds}
\usetikzlibrary{arrows,calc,backgrounds}
\tikzset{hidden/.style = {thick, dashed}}
\tikzset{line/.style = {ultra thick}}
\begin{document}
\tdplotsetmaincoords{60}{120}
\begin{tikzpicture}
[scale=2,tdplot_main_coords]
\path
coordinate (A) at (0, 0, 0)
coordinate (B) at (4, 0, 0)
coordinate (C) at (0, 6, 0)
coordinate (S) at (2,0 {2*sqrt(3)})
coordinate (O) at (2,3 {2/3*sqrt(3)})

($(B)!0.5!(A)$)                     coordinate (H)
($(B)!0.5!(C)$) coordinate (M)
($(S)!2/3!(H)$) coordinate (G)
;
\draw[line]
(A)--(S) (S)--(B)
(S)--(C) (A)--(B) (A)--(C) (B)--(C) (S)--(H) (G) -- (H) (H) -- (M);
\foreach \v/\position in {A/above,B/below,C/right,S/above,O/right,H/below,M/below,G/left} {
\draw[fill=black] (\v) circle (1.25pt) node [\position=0.2mm] {$\v$};
}
\draw[dashed] (M) circle[radius={sqrt(13)}];
\begin{scope}[tdplot_screen_coords, on background layer]
\pgfmathsetmacro{\R}{sqrt(129)/3}%
\fill[ball color=cyan!10, opacity=1.0] (O) circle (\R); % 3D lighting effect
\end{scope}
\end{tikzpicture}
\end{document}


I don't understand why.

I transformed so that center of the sphere coincidented origion.

\documentclass[12pt,border=3mm]{standalone}
\usepackage{fouriernc}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc,backgrounds}
\tikzset{hidden/.style = {thick, dashed}}
\tikzset{line/.style = {ultra thick}}
\newcommand{\RightAngle}[4][5pt]{%
\draw ($#3!#1!#2$)--($#3!2!($($#3!#1!#2$)!.5!($#3!#1!#4$)$)$)--($#3!#1!#4$);}
\begin{document}
\tdplotsetmaincoords{60}{135}
\begin{tikzpicture}
\def\R{(1/3)*sqrt(129)}
\coordinate (O) at (0,0,0);
\fill[ball color=cyan!80, opacity=1.0] (O) circle (\R); % 3D lighting effect
\begin{scope}[tdplot_main_coords, shift={(0,0,0)}, rotate=0]
\path
coordinate (A) at (-2, -3, {-(2/3)*sqrt(3)})
coordinate (B) at (2, -3, {-(2/3)*sqrt(3)})
coordinate (C) at (-2, 3, {-(2/3)*sqrt(3)})
coordinate (S) at (0, -3, {(4/3)*sqrt(3)})
coordinate (O) at (0,0,0)

($(B)!0.5!(A)$)                     coordinate (H)
($(B)!0.5!(C)$) coordinate (M)
($(S)!2/3!(H)$) coordinate (G)
;
\draw[line]
(A)--(S) (S)--(B)
(S)--(C) (A)--(B) (A)--(C) (B)--(C);
\draw[hidden] (G)--(H)--(M)--(O)-- cycle;
\draw[hidden] (G)--(S);
\draw [fill opacity=0.4,fill=blue!80!blue] (S) -- (A) -- (B) -- cycle;
\draw [fill opacity=0.4,fill=green!80!blue] (S) -- (A) -- (C) -- cycle;

\foreach \v/\position in {A/above,B/below,C/right,S/above,O/right,H/below,M/below,G/left} {
\draw[fill=black] (\v) circle (1.25pt) node [\position=0.2mm] {$\v$};
}
\draw[dashed] (M) circle[radius={sqrt(13)}];% circle ABCD
\RightAngle{(H)}{(M)}{(O)};
\RightAngle{(G)}{(H)}{(M)};
\RightAngle{(H)}{(G)}{(O)};
\RightAngle{(G)}{(O)}{(M)};
\RightAngle{(B)}{(A)}{(C)};
\end{scope}
\end{tikzpicture}
\end{document}


• You are missing some commas in your coordinates, mainly coordinate (S) at (2,0, {2*sqrt(3)}) coordinate (O) at (2,3, {2/3*sqrt(3)}) Commented Jun 9, 2017 at 17:04
• I draw arc \draw[thick] (B) arc [start angle=-45, end angle=135, radius=sqrt(13)]; but didn't get correct result. Commented Jun 11, 2017 at 1:26
• BCA isn't a square. Did you try using \tdplotsetmaincoords{0}{0} to get the correct angles? B appears to be at -60 and C at 120, but atan{6/4) = 56.31 so that isn't quite right. Commented Jun 11, 2017 at 15:25

1 Answer

I solved my problem.

\documentclass[12pt,border=3mm]{standalone}
\usepackage{fouriernc}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc,backgrounds}
\tikzset{hidden/.style = {thick, dashed}}
\tikzset{line/.style = {ultra thick}}
\begin{document}
\tdplotsetmaincoords{60}{120}
\pgfmathsetmacro{\radius}{sqrt(13)} % radius of the circle

\begin{tikzpicture}
[scale=1.3,tdplot_main_coords]
\path
coordinate (A) at (0, 0, 0)
coordinate (B) at (4, 0, 0)
coordinate (C) at (0, 6, 0)
coordinate (S) at (2,0 ,{2*sqrt(3)})
coordinate (O) at (2,3 ,{2/3*sqrt(3)})

($(B)!0.5!(A)$)                     coordinate (H)
($(B)!0.5!(C)$) coordinate (M)
($(S)!2/3!(H)$) coordinate (G)
;
\draw[line]
(A)--(S) (S)--(B)
(S)--(C) (A)--(B) (A)--(C) (B)--(C) ;
\draw[hidden] (G)--(H) (H)--(M) (M)--(O) (S)--(H) (O)--(G) (O)--(S);
\foreach \v/\position in {A/above,B/below,C/right,S/above,O/right,H/below,M/below,G/left} {
\draw[fill=black] (\v) circle (1.25pt) node [\position=0.2mm] {$\v$};
}
%\draw[dashed] (M) circle[radius={sqrt(13)}]; \RightAngle{(H)}{(M)}{(O)};
\tkzMarkRightAngle[size = 0.2](G,H,M)
\tkzMarkRightAngle[size = 0.2](H,M,O)
\tkzMarkRightAngle[size = 0.2](G,O,M)
\tkzMarkRightAngle[size = 0.2](B,A,C)
\tkzMarkRightAngle[size = 0.2](H,G,O)
\begin{scope}[tdplot_screen_coords, on background layer]
\pgfmathsetmacro{\R}{sqrt(129)/3}%
\fill[ball color=orange!80, opacity=1.0] (O) circle (\R); % 3D lighting effect
\end{scope}
\draw [thick] (B) arc (303.69006752597:483.69006752597:{sqrt(13)});
\draw [thick,dashed] (C) arc (123.69006752597:303.69006752597:{sqrt(13)});

\end{tikzpicture}
\end{document}