从这里使用 Tikz,可以在球体内绘制立方体吗?我想画一个外接球,中心在 O(1,1,1),半径为 R = sqrt(3)。我试过
\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc}
\begin{document}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=1]
\def\R{sqrt(3)}
\coordinate (O) at (1,1,1);
\fill[ball color=cyan!10, opacity=1.0] (O) circle (\R); % 3D lighting effect
\begin{scope}[tdplot_main_coords, shift={(1,1,1)}, rotate=0]
\path
coordinate (A) at (0,0,0)
coordinate (B) at (2,0,0)
coordinate (C) at (2,2,0)
coordinate (D) at (0,2,0)
coordinate (S) at (0,0,2)
coordinate (O) at (1,1,1);
\draw[ dashed]
(A)--(S) (A)--(B)
(A)--(D)
;
\draw [fill opacity=0.4,fill=green!80!blue] (S) -- (B) -- (C) -- cycle;
\draw [fill opacity=0.4,fill=orange!80!blue] (S) -- (C) -- (D) -- cycle;
\foreach \v/\position in {A/below,B/below,C/below,D/right,S/above,O/below} {
\draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$};
}
\end{scope}
\end{tikzpicture}
\end{document}
我的结果不正确。我该如何修复?
答案1
也可以使用tdplot_screen-coords
和on background layer
。如果您打算使用多个球体,这可能会更有用。
\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc,backgrounds}
\begin{document}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[tdplot_main_coords]
\path
coordinate (A) at (0,0,0)
coordinate (B) at (2,0,0)
coordinate (C) at (2,2,0)
coordinate (D) at (0,2,0)
coordinate (S) at (0,0,2)
coordinate (O) at (1,1,1);
\draw[ dashed] (A)--(S) (A)--(B) (A)--(D);
\draw [fill opacity=0.4,fill=green!80!blue] (S) -- (B) -- (C) -- cycle;
\draw [fill opacity=0.4,fill=orange!80!blue] (S) -- (C) -- (D) -- cycle;
\foreach \v/\position in {A/below,B/below,C/below,D/right,S/above,O/below} {
\draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$};
}
\draw[dashed] (1,1,0) circle[radius={sqrt(2)}];% circle ABCD
\begin{scope}[tdplot_screen_coords, on background layer]
\pgfmathsetmacro{\R}{sqrt(3)}%
\fill[ball color=cyan!10, opacity=1.0] (O) circle (\R); % 3D lighting effect
\end{scope}
\end{tikzpicture}
\end{document}
答案2
我照做了。
\documentclass[border=2mm12pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc}
\begin{document}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=2]
\def\R{sqrt(3)}
\coordinate (O) at (0,0,0);
\fill[ball color=cyan!10, opacity=1.0] (O) circle (\R); % 3D lighting effect
\begin{scope}[tdplot_main_coords, shift={(0,0)}, rotate=0]
\path
coordinate (A) at (-1,-1,-1)
coordinate (B) at (1,-1,-1)
coordinate (C) at (1,1,-1)
coordinate (D) at (-1,1,-1)
coordinate (S) at (-1,-1,1);
\draw[ dashed]
(A)--(S) (A)--(B)
(A)--(D)
;
\draw [fill opacity=0.4,fill=green!80!blue] (S) -- (B) -- (C) -- cycle;
\draw [fill opacity=0.4,fill=orange!80!blue] (S) -- (C) -- (D) -- cycle;
\foreach \v/\position in {A/below,B/below,C/below,D/right,S/above,O/right} {
\draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$};
}
\end{scope}
\end{tikzpicture}
\end{document}