Based the answer at here, How can I draw a circle knowing center and radius lies on a plane? I am trying to draw the circle SAD.Where is wrong in my code when drawing circle SAD and how to draw dasded line this circle?
\documentclass[tikz,border=1mm, 12 pt]{standalone}
\usepackage{tikz-3dplot}
\usepackage{fouriernc}
\usetikzlibrary{backgrounds}
\makeatletter
% retrieves the 3D coordinates
\def\RawCoord(#1){\csname tikz@dcl@coord@#1\endcsname}%
\def\scalprod#1=#2.#3;{%
\edef\coordA{\RawCoord#2}%
\edef\coordB{\RawCoord#3}%
\pgfmathsetmacro\pgfutil@tmpa{scalarproduct({\coordA},{\coordB})}
\edef#1{\pgfutil@tmpa}}%
\makeatother
\newcommand{\spaux}[6]{(#1)*(#4)+(#2)*(#5)+(#3)*(#6)}
\pgfmathdeclarefunction{scalarproduct}{2}{% scalar product of two 3-vectors
\begingroup%
\pgfmathparse{\spaux#1#2}%
\pgfmathsmuggle\pgfmathresult\endgroup}
\usetikzlibrary{3d}
\usetikzlibrary{calc}
\makeatletter
\newcounter{smuggle}
\DeclareRobustCommand\smuggleone[1]{%
\stepcounter{smuggle}%
\expandafter\global\expandafter\let\csname smuggle@\arabic{smuggle}\endcsname#1%
\aftergroup\let\aftergroup#1\expandafter\aftergroup\csname smuggle@\arabic{smuggle}\endcsname
}
\DeclareRobustCommand\smuggle[2][1]{%
\smuggleone{#2}%
\ifnum#1>1
\aftergroup\smuggle\aftergroup[\expandafter\aftergroup\the\numexpr#1-1\aftergroup]\aftergroup#2%
\fi
}
\makeatother
\def\parsecoord(#1,#2,#3)>(#4,#5,#6){%
\def#4{#1}%
\def#5{#2}%
\def#6{#3}%
\smuggle{#4}%
\smuggle{#5}%
\smuggle{#6}%
}
\def\SPTD(#1,#2,#3).(#4,#5,#6){((#1)*(#4)+1*(#2)*(#5)+1*(#3)*(#6))}
\def\VPTD(#1,#2,#3)x(#4,#5,#6){((#2)*(#6)-1*(#3)*(#5),(#3)*(#4)-1*(#1)*(#6),(#1)*(#5)-1*(#2)*(#4))}
\def\VecMinus(#1,#2,#3)-(#4,#5,#6){(#1-1*(#4),#2-1*(#5),#3-1*(#6))}
\def\VecAdd(#1,#2,#3)+(#4,#5,#6){(#1+1*(#4),#2+1*(#5),#3+1*(#6))}
\newcommand{\RotationAnglesForPlaneWithNormal}[5]{%\typeout{N=(#1,#2,#3)}
\foreach \XS in {1,-1}
{\foreach \YS in {1,-1}
{\pgfmathsetmacro{\mybeta}{\XS*acos(#3)}
\pgfmathsetmacro{\myalpha}{\YS*acos(#1/sin(\mybeta))}
\pgfmathsetmacro{\ntest}{abs(cos(\myalpha)*sin(\mybeta)-#1)%
+abs(sin(\myalpha)*sin(\mybeta)-#2)+abs(cos(\mybeta)-#3)}
\ifdim\ntest pt<0.1pt
\xdef#4{\myalpha}
\xdef#5{\mybeta}
\fi
}}
}
\tikzset{circle in plane with normal/.style args={#1 with radius #2 around #3}{
/utils/exec={\edef\temp{\noexpand\parsecoord#1>(\noexpand\myNx,\noexpand\myNy,\noexpand\myNz)}
\temp
\pgfmathsetmacro{\myNx}{\myNx}
\pgfmathsetmacro{\myNy}{\myNy}
\pgfmathsetmacro{\myNz}{\myNz}
\pgfmathsetmacro{\myNormalization}{sqrt(pow(\myNx,2)+pow(\myNy,2)+pow(\myNz,2))}
\pgfmathsetmacro{\myNx}{\myNx/\myNormalization}
\pgfmathsetmacro{\myNy}{\myNy/\myNormalization}
\pgfmathsetmacro{\myNz}{\myNz/\myNormalization}
% compute the rotation angles that transform us in the corresponding plabe
\RotationAnglesForPlaneWithNormal{\myNx}{\myNy}{\myNz}{\tmpalpha}{\tmpbeta}
%\typeout{N=(\myNx,\myNy,\myNz),alpha=\tmpalpha,beta=\tmpbeta,r=#2,#3}
\tdplotsetrotatedcoords{\tmpalpha}{\tmpbeta}{0}},
insert path={[tdplot_rotated_coords,canvas is xy plane at z=0,transform shape]
#3 circle[radius=#2]}
}}
\begin{document}
\tdplotsetmaincoords{70}{70}
\begin{tikzpicture}[scale=2,tdplot_main_coords,declare function={R=2;r=sqrt(3);
alpha1(\th,\ph,\b)=\ph+asin(cot(\th)*tan(\b));%
alpha2(\th,\ph,\b)=-180+\ph-asin(cot(\th)*tan(\b));%
beta1(\th,\ph,\a)=90+atan(cot(\th)/sin(\a-\ph));%
beta2(\th,\ph,\a)=270+atan(cot(\th)/sin(\a-\ph));%
}]
\path (0,0,0) coordinate (O)
(-3/2, {-(1/2)*sqrt(3)}, 0) coordinate (A)
(3/2, {-(1/2)*sqrt(3)}, 0) coordinate (B)
(0, {sqrt(3)}, 0) coordinate (C)
(-3/2, {-(1/2)*sqrt(3)}, 2) coordinate (S)
(0,0,0) coordinate (I)
(0, 0,1) coordinate (T)
(0,0,1) coordinate(Z)
(3/2, {(1/2)*sqrt(3)}, 0) coordinate (D);
\begin{scope}[tdplot_screen_coords, on background layer]
\draw[thick] (T) circle (R);
\end{scope}
\begin{scope}[canvas is xy plane at z={0}]
\draw[dashed] (O) circle (r);
\scalprod\myz=(T).(Z); % z component of T
\pgfmathsetmacro{\myel}{atan(-1*\myz/r)}
\draw[thick] ({alpha1(\tdplotmaintheta,\tdplotmainphi,{\myel})}:r)
arc({alpha1(\tdplotmaintheta,\tdplotmainphi,{\myel})}:
{alpha2(\tdplotmaintheta,\tdplotmainphi,{\myel})}:r) ;
\end{scope}
\begin{scope}[on background layer]
\foreach \v/\position in {T/above,O/below,A/below,B/below,C/below,S/right,D/below} {
\draw[draw =black, fill=black] (\v) circle (1.2/2pt) node [\position=0.2mm] {$\v$};
}
\end{scope}
\foreach \X in {A,B,C,O} \draw[dashed] (\X) -- (S);
\draw[dashed] (A) -- (B) -- (C) -- cycle (A) -- (D) -- (S);
% % store the coordinates of S, A and D in marcros
\parsecoord(-3/2, {-1/2*sqrt(3)}, 2)>(\mySx,\mySy,\mySz)
\parsecoord(-3/2, {-1/2*sqrt(3)}, 0)>(\myAx,\myAy,\myAz)
\parsecoord(3/2, {(1/2)*sqrt(3)}, 0)>(\myDx,\myDy,\myDz)
\def\mynormal{\VPTD({\mySx-\myAx},{\mySy-\myAy},{\mySz-\myAz})x({\myDx-\myAx},{\myDy-\myAy},{\myDz-\myAz})}
\edef\temp{\noexpand\parsecoord\mynormal>(\noexpand\myNx,\noexpand\myNy,\noexpand\myNz)}
\draw[red,thick,circle in plane with normal={{\mynormal} with radius {R} around (T)}];
\end{tikzpicture}
\end{document}



\tempafter saying\edef\temp{...}. But really I strongly recommend switching to the less clumsy way of doing this, as in my answer below. – Sep 06 '19 at 12:35