我正在尝试在 3D 中绘制三角形的内切圆。如果顶点位于平面 Oxy 上,我尝试
\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}
当我更改时,例如zA = 5
,结果不正确。我该如何修复?
答案1
您提供的代码太棒了!您只需要在三角形的平面上绘制圆即可。
\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}
您可以根据需要选择坐标(多或少)
\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}
请注意,我已标准化各种向量以避免dimension too large
错误。
答案2
我尝试在 3D 中使用 tkz-euclide ...
\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}
答案3
对于二维和三维,incenter
三角形的ABC
,incenter3
四面体的都ABCD
可以通过重心坐标来计算。
circumcenter
对于和 也类似circumcenter3
。
该代码很容易解释。
unitsize(1cm);
import three;
import solids; // for 'sphere'
triple bary(triple A, triple B=O, triple C=O, triple D=O, real a, real b=0, real c=0,real d=0){
return (a*A+b*B+c*C+d*D) / (a+b+c+d);}
triple incenter(triple A, triple B, triple C){
return bary(A,B,C,abs(B-C),abs(C-A),abs(A-B));}
real area(triple A, triple B, triple C){
return .5*abs(cross(A-B,A-C));}
// r = 2 S/ (a+b+c)
real inradius(triple A, triple B, triple C){
return 2*area(A,B,C) / (abs(A-B)+abs(B-C)+abs(C-A));}
// https://en.wikipedia.org/wiki/Tetrahedron
real volume(triple A, triple B, triple C, triple D){
return (1/6)*abs(dot(cross(D-A,D-B),D-C));}
triple incenter3(triple A, triple B, triple C,triple D){
return bary(A,B,C,D,area(B,C,D),area(C,D,A),area(D,A,B),area(B,C,A));}
// rabcd = 3 volume(A,B,C,D)/ (Sa+Sb+Sc)
real inradius3(triple A, triple B, triple C, triple D){
return 3*volume(A,B,C,D) / (area(A,B,C)+area(A,B,D)+area(B,C,D)+area(C,A,D));}
currentprojection=orthographic((1,1,.8),center=true,zoom=.9);
// The incircle of ABC
triple A=(0,0,0),B=(3,-1,0),C=(2,7,1),D=(2,3,5);
triple Iabc=incenter(A,B,C);
real rabc=inradius(A,B,C);
path3 inABC=circle(Iabc,rabc,normal=cross(A-B,A-C));
draw(surface(inABC),yellow+opacity(.5));
draw(inABC);
dot(Iabc,yellow);
// The incircle of ACD
triple Iacd=incenter(A,C,D);
real racd=inradius(A,C,D);
path3 inACD=circle(Iacd,racd,normal=cross(A-C,A-D));
draw(surface(inACD),lightblue+opacity(.2));
draw(inACD);
dot(Iacd,blue);
// The incircle of ABD
triple Iabd=incenter(A,B,D);
real rabd=inradius(A,B,D);
path3 inABD=circle(Iabd,rabd,normal=cross(A-B,A-D));
//draw(surface(inABD),lightred,opacity(.2));
draw(inABD,red);
dot(Iabd,red);
// insphere
triple Iabcd = incenter3(A,B,C,D);
real rabcd = inradius3(A,B,C,D);
revolution inABCD=sphere(Iabcd,rabcd);
draw(surface(inABCD),green+opacity(.3));
draw(B--C--D--cycle);
draw(A--B^^A--C^^A--D,dashed);
label("$A$",A,NE);
label("$B$",B,W);
label("$C$",C,E);
label("$D$",D,N);