TransWikia.com

How to plot 3D convex hull using Tikz/pgf?

TeX - LaTeX Asked on May 1, 2021

How to draw 3D convex hull using Tikz/pgf ?

For example, if we want to plot the following pyramid or Tetrahedron using Tikz/pgf ?
enter image description here

Say,the vertices are (1,1,1), (1,−1,−1), (−1,1,−1), (−1,−1,1).

However I have looked up the following code:

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}

giving the following convex hull

enter image description here

But the above code showing error and nor compiling in my latex editor.

are there other way/other codes to draw convex hull using Tikz/pgf ?

help me at least to draw the tetrahedron

One Answer

You can try this code.

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}

enter image description here

Answered by minhthien_2016 on May 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP