TikZ:包含一些点的球体

TikZ:包含一些点的球体

应该有一个包含点 A、B、C、D 和 S 的球体。

有人知道如何正确绘制球体的图画吗?

在此处输入图片描述

\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{angles, quotes, babel}
\usepackage{amsmath, amssymb}
\begin{document}

\begin{tikzpicture}[x=1cm, y=1cm, z={(4mm,3mm)}, scale=1.5, font=\small]
\pgfmathsetmacro\a{2}
\pgfmathsetmacro\b{2.5}
\pgfmathsetmacro\c{3}

\pgfmathsetmacro{\r}{0.5*sqrt(\a^2+\b^2+\c^2)} %  

\pgfmathsetmacro{\AC}{sqrt(\a^2+\b^2)} %  
\pgfmathsetmacro{\PA}{0.5*\AC} %  

\pgfmathsetmacro{\h}{sqrt(\r^2-\PA^2)} %  

% Pyramid
\draw (0,0,0) coordinate[label=below:$A$] (A)
--(\a,0,0) node[midway, below]{$a$} coordinate[label=below:$B$] (B)
--(\a,0,\b) node[midway,right=2mm]{$b$} coordinate[label=$C$] (C);

\draw[densely dashed] (C)--(0,0,\b) coordinate[label=left:$D$] (D)--(A);
\draw (A)--(0,\c,0) node[midway, left]{$c$} coordinate[label=$S$] (S);

 % Diagonals
\draw (A)--(C); 
 \draw ($(A)!0.5!(C)$) coordinate coordinate[label=below:$P$]  (P) -- ($(S)!0.5!(C)$) node[midway, left]{$h$} coordinate[label=$M$] (M); 
\draw (D)--(B);

 % Point M
\draw (S)--(M) node[midway, above]{$r$} -- (C) node[midway, above]{$r$};

\draw[densely dashed] (D) -- (M);
\foreach \P in {A,B,C} \draw (M) -- (\P);

\node[anchor=north west, align=left, yshift=-7mm] at (A){$\begin{array}{l}
a = \a ,~  b = \b,~  c = \c \\
|AC| =  \sqrt{a^2+b^2} = \AC \\
|PA| = 0.5 |AC| = \PA \\
h = \sqrt{r^2- |PA|^2} = \h  \\
r = 0.5 \sqrt{a^2+b^2+c^2} = \r
\end{array}$
};

\shade[ball color = gray!40, opacity = 0.4] (M) circle[radius=5mm] node{?};
\end{tikzpicture}

\end{document}

答案1

在您的坐标系中,它会很乱,因为您不使用正交投影,球体看起来就像一个鸡蛋。如果您使用正交投影,半径为 的球体r在屏幕坐标中就如同半径相同的圆。

\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{60}{30}

\begin{tikzpicture}[tdplot_main_coords, font=\small]
  \pgfmathsetmacro\a{2}
  \pgfmathsetmacro\b{2.5}
  \pgfmathsetmacro\c{3}
  % Pyramid
  \draw (0,0,0) coordinate[label=below:$A$] (A)
  --(\a,0,0) node[midway, below]{$a$} coordinate[label=below:$B$] (B)
  --(\a,\b,0) node[midway,right=2mm]{$b$} coordinate[label=$C$] (C);

  \draw[densely dashed] (C)--(0,\b,0) coordinate[label=left:$D$] (D)--(A);
  \draw (A)--(0,0,\c) node[midway, left]{$c$} coordinate[label=$S$] (S);

  \path (\a/2,\b/2,\c/2) coordinate[label=$M$](M);
   % Diagonals
  \draw (A)--(C); 
   \draw ($(A)!0.5!(C)$) coordinate coordinate[label=below:$P$]  (P) --  node[midway, left]{$h$} (M); 
  \draw (D)--(B);

   % Point M
  \draw (S)--(M) node[midway, above]{$r$} -- (C) node[midway, above]{$r$};

  \draw[densely dashed] (D) -- (M);
  \foreach \P in {A,B,C} \draw (M) -- (\P);

  \shade[tdplot_screen_coords,ball color = gray!40, opacity = 0.4] 
   (M) circle[radius={sqrt(\a*\a+\b*\b+\c*\c)/2}];
\end{tikzpicture}
\end{document}

相关内容