I am trying to draw an inscribed circle of a triangle in 3D. If the vertices lie on the plane Oxy, I tried
\documentclass[12pt, border = 1mm,tikz]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{123}
\begin{tikzpicture}[tdplot_main_coords,scale=1,tdplot_main_coords,declare function={xA = 8; yA=5;zA=0; xB=1;yB=2;zB=0; xC=5;yC=-5;zC=0 );%
}]
\path
(xA,yA,zA) coordinate (A)
(xB,yB,zB) coordinate (B)
(xC,yC,zC) coordinate (C) ;
\pgfmathsetmacro{\AB}{{sqrt((xB- xA)*(xB- xA) +(yB- yA)*(yB- yA) + (zB- zA)*(zB- zA))} };
\pgfmathsetmacro{\AC}{{sqrt((xC- xA)*(xC- xA) +(yC- yA)*(yC- yA) + (zC- zA)*(zC- zA))} };
\pgfmathsetmacro{\BC}{{sqrt((xC- xB)*(xC- xB) +(yC- yB)*(yC- yB) + (zC- zB)*(zC- zB))} };
\pgfmathsetmacro{\P}{{(\AB + \BC + \AC)/2} };
\pgfmathsetmacro{\myarea}{{sqrt(\P*(\P - \AB) *(\P - \AC)*(\P - \BC) )} };\pgfmathsetmacro{\r}{{\myarea/\P} };
\coordinate (I) at ({(xA*\BC + xB*\AC + xC*\AB)/(\AB + \BC + \AC)},{(yA*\BC + yB*\AC + yC*\AB)/(\AB + \BC + \AC)},{(zA*\BC + zB*\AC + zC*\AB)/(\AB + \BC + \AC)});
\foreach \p in {A,B,C,I}
\draw[fill=black] (\p) circle (1.5 pt);
\foreach \p/\g in {A/-90,B/-90,C/-90,I/0}
\path (\p)+(\g:3mm) node{$\p$};
\draw[blue] (A) -- (B) -- (C) -- cycle;
\draw[red,dashed] (I) circle[radius= \r];
\end{tikzpicture}
\end{document}
When I change, e.g, zA = 5, the result incorrect. How can I repair it?





