在这儿我怎样才能绘制一个外接金字塔的球体?我对此代码做了类似的事情。但我没有得到正确的结果。我的代码
\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}
我不明白为什么。
我进行了变换,使得球体的中心与原点重合。
\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}
答案1
我解决了我的问题。
\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}