如何使用 Tikz/pgf 绘制 3D 凸包?

如何使用 Tikz/pgf 绘制 3D 凸包?

如何使用 Tikz/pgf 绘制 3D 凸包?

例如,如果我们想使用 Tikz/pgf 绘制以下金字塔或四面体? 在此处输入图片描述

假设顶点是(1,1,1), (1,−1,−1), (−1,1,−1), (−1,−1,1).

不过我查阅了以下代码:

\pgfplotsset{width=7cm,compat=1.3}
\begin{tikzpicture}
\begin{axis}
% We have `plotdata/first3d.dat' with
% ---------
% 0 0 0.8
% 1 0 0.56
% 2 0 0.5
% 3 0 0.75
%
% 0 1 0.6
% 1 1 0.3
% 2 1 0.21
% 3 1 0.3
%
% 0 2 0.68
% 1 2 0.22
% 2 2 0.25
% 3 2 0.4
%
% 0 3 0.7
% 1 3 0.5
% 2 3 0.58
% 3 3 0.9
% -> yields a 4x4 matrix:
\addplot3[surf] file {plotdata/first3d.dat};
\end{axis}
\end{tikzpicture}

给出以下凸包

在此处输入图片描述

但是上面的代码在我的乳胶编辑器中显示错误并且无法编译。

是否有其他方法/其他代码可以使用 Tikz/pgf 绘制凸包?

至少帮我画一下四面体

答案1

你可以尝试一下这个代码。

\documentclass[12 pt,border=1mm]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{80}{120}
\begin{tikzpicture}[tdplot_main_coords,line join=round]
\path (1,1,1) coordinate (A)
(1,-1,-1)  coordinate (B)
(-1,1,-1)  coordinate (C)
(-1,-1,1)  coordinate (D);
\draw[thick,fill=gray] (D) -- (B) -- (C) -- cycle;
\draw[thick,fill=gray] (D) -- (A)  -- (C) -- cycle;
\draw[dashed] (A) -- (B);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容