8

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}

enter image description here

When I change, e.g, zA = 5, the result incorrect. How can I repair it?

enter image description here

10

You provide some wonderful code! You only need to draw the circle in the plane of the triangle.

\documentclass[12pt, border = 1mm,tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools}
\def\pgfmathsetmacroFPU#1#2{\begingroup% 
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}% 
\pgfmathsetmacro{#1}{#2}% 
\pgfmathsmuggle#1\endgroup}% 
\begin{document}
    \tdplotsetmaincoords{70}{123}
    \begin{tikzpicture}[tdplot_main_coords,scale=1,tdplot_main_coords,
    declare function={xA = 8; yA=5;zA=5; 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; 
 \path[overlay] [3d coordinate={(mya)=(C)-(B)},
    3d coordinate={(myb)=(C)-(A)},3d coordinate={(myc)=(B)-(A)}];
 \pgfmathsetmacroFPU{\tmpa}{1/sqrt(TD("(mya)o(mya)"))}   
 \pgfmathsetmacroFPU{\tmpb}{1/sqrt(TD("(myb)o(myb)"))}   
 \pgfmathsetmacroFPU{\tmpc}{1/sqrt(TD("(myc)o(myc)"))}   
 \path[overlay] [3d coordinate={(mya)=\tmpa*(mya)},
   3d coordinate={(myb)=\tmpb*(myb)},3d coordinate={(myc)=\tmpc*(myc)},
    3d coordinate={(myn)=(myc)x(mya)},
    3d coordinate={(mym)=(myn)x(B)-(A)}]; 
 \pgfmathsetmacroFPU{\tmpm}{1/sqrt(TD("(mym)o(mym)"))}   
 \path[overlay] [3d coordinate={(mym)=\tmpm*(mym)}]; 
 \begin{scope}[x={(myc)},y={(mym)}]
 \draw[red,dashed] (I) circle[radius= \r];
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

You can choose the coordinates (more or less) as you wish

\documentclass[12pt, border = 1mm,tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools}
\def\pgfmathsetmacroFPU#1#2{\begingroup% 
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}% 
\pgfmathsetmacro{#1}{#2}% 
\pgfmathsmuggle#1\endgroup}% 
\begin{document}
\tdplotsetmaincoords{70}{123}
\foreach \X in {-6,-5.8,...,6}
{\begin{tikzpicture}[tdplot_main_coords,scale=1,tdplot_main_coords,
    declare function={xA = 8; yA=5;zA=\X; xB=1;yB=2;zB=0; xC=5;yC=-5;zC=0 );%
    }]
 \draw[tdplot_screen_coords] (-8,-11) rectangle (3,3);
 \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; 
 \path[overlay] [3d coordinate={(mya)=(C)-(B)},
    3d coordinate={(myb)=(C)-(A)},3d coordinate={(myc)=(B)-(A)}];
 \pgfmathsetmacroFPU{\tmpa}{1/sqrt(TD("(mya)o(mya)"))}   
 \pgfmathsetmacroFPU{\tmpb}{1/sqrt(TD("(myb)o(myb)"))}   
 \pgfmathsetmacroFPU{\tmpc}{1/sqrt(TD("(myc)o(myc)"))}   
 \path[overlay] [3d coordinate={(mya)=\tmpa*(mya)},
   3d coordinate={(myb)=\tmpb*(myb)},3d coordinate={(myc)=\tmpc*(myc)},
    3d coordinate={(myn)=(myc)x(mya)},
    3d coordinate={(mym)=(myn)x(B)-(A)}]; 
 \pgfmathsetmacroFPU{\tmpm}{1/sqrt(TD("(mym)o(mym)"))}   
 \path[overlay] [3d coordinate={(mym)=\tmpm*(mym)}]; 
 \begin{scope}[x={(myc)},y={(mym)}]
 \draw[red,dashed] (I) circle[radius= \r];
 \end{scope}
\end{tikzpicture}}
\end{document}

enter image description here

Note that I normalized various vectors to avoid dimension too large errors.

| improve this answer | |
  • Can you add it into 3dtools? – minhthien_2016 Jan 10 at 12:24
  • @minhthien_2016 I will be very happy to do that (in a few weeks). – user194703 Jan 10 at 12:24
1

I try tkz-euclide in 3D and ...

\documentclass[]{standalone}
\usepackage{tkz-euclide}
\usetikzlibrary{3d}

\begin{document}
\thispagestyle{empty} 

\begin{tikzpicture}[x  = {(-0.5cm,-0.5cm)},
                    y  = {(0.9659cm,-0.25882cm)},
                    z  = {(0cm,1cm)},
                    scale = .5,
                    color = {lightgray}]
\tikzset{facestyle/.style={fill=lightgray,draw=red,very thin,line join=round}}
% face "back" 
\begin{scope}[canvas is zy plane at x=0]
\tkzDefPoints{0/0/A,6/0/B,4/6/C}
\tkzDrawPolygon[fill=blue!20](A,B,C)
\tkzDrawLines[add=1 and 1,dashed](A,B B,C C,A)
\tkzDrawCircle[in,fill=blue!50](A,B,C)
\end{scope}
% face  "left"
\begin{scope}[canvas is zx plane at y=0]
\tkzDefPoints{0/0/A,6/0/B,4/6/C}
\tkzDrawPolygon[fill=red!20](A,B,C)
\tkzDrawLines[add=1 and 1,dashed](A,B B,C C,A)
\tkzDrawCircle[in,fill=red!50](A,B,C)
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • I hope You will write tkz-euclide - 3D. – minhthien_2016 Feb 2 at 14:12
  • There is ´tikz-3dplot’ and I have enough work to finish the english doc for euclide – Alain Matthes Feb 2 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.