1

I would like to plot a convex hull given the coordinates of the vertices.

The points are:

0   0   0
0   0   0.285957
0   0.285957    0.285957
0   0.3812378724    0.1906189362
0   0.571914    0
0.1906761276    0.3812378724    0.1906189362
0.285957    0.285957    0.285957
0.571914    0   0
0.571914    0   0.285957

{x, y, z} columns.

I can make the plot with Mathematica resulting in this figure:

enter image description here

I have seen this example in this link "Plot TikZ items concerning the 3D position, not the order of appearance in the code", which I think is similar to my problem.

I would like to know if there is a way to make a figure from the vertices like this and use transparency to distinguish two or three solids with the same axis figure.

Regards

user1993416
  • 1,046
  • I guess you'd greatly benefit from taking the linked example, adapting it as far as you can and then ask a question in which you have an MWE rather than just a set of coordinates. –  Jun 05 '18 at 17:03
  • @marmot I am sorry not providing an MWE. It results difficult for me since I have never used Tikz. Although I know some LaTeX I do not know what I am looking for the solution of the link. – user1993416 Jun 05 '18 at 17:58
  • I posted something that can serve as an MWE. –  Jun 05 '18 at 18:05

1 Answers1

2

I do not understand precisely what you are asking. If it is how to draw the polygons, the following may help. Otherwise you have at least an MWE to play with and to explain what you want. The strategy is to draw triangles (since your screen shot has triangles) of the vertices contained in the list. As far as I know, there is no function that finds out the bounding polygons of a list of 3D vertices, i.e. the convex hull.

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\usepgfplotslibrary{patchplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[view/h=-60,xlabel=$x$,ylabel=$y$,colormap/blackwhite]
\addplot3[%xmin=0,xmax=1,
    opacity=0.5,
    table/row sep=\\,
    patch,
    patch type=polygon,
    vertex count=3,
    patch table with point meta={%
    % pt1 pt2 pt3 pt4 pt5 cdata
        0 1 2 1\\
        0 2 8 2\\
        0 1 8 3\\
    }
]
table {
    x y z\\
    0   0   0\\ %0
    0   0   0.285957\\ %1
    0   0.285957    0.285957\\ %2
    0   0.3812378724    0.1906189362\\ %3
    0   0.571914    0\\ %4
    0.1906761276    0.3812378724    0.1906189362\\ %5
    0.285957    0.285957    0.285957\\ %6
    0.571914    0   0\\ %7
    0.571914    0   0.285957\\ %8
};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • thank you for your answer. Could you tell me what does the part vertex count=3, patch table with point meta={% % pt1 pt2 pt3 pt4 pt5 cdata 0 1 2 1\\ 0 2 8 2\\ 0 1 8 3\\ } – user1993416 Jun 05 '18 at 18:46
  • @user1993416 vertex count=3 just says that the polygons will be triangles (in the linked answer they had 5 corners, i.e. were pentagons). The second thing tells pgfplots which of the triangles it should draw. You have 8 vertices, so there will be 8x7x6 triangles which one could draw, and I just selected three of them. The last entry is the color. In the example, I chose a colormap such that this number translates to a gray level. –  Jun 05 '18 at 18:49
  • I have finished the plot, but I would need to change the viewpoint. Do you know how to rotate the figure? – user1993416 Jun 05 '18 at 19:37
  • @user1993416 Just play with -60 in view/h=-60. –  Jun 05 '18 at 19:38
  • The plot I get with pgfplot has a high quality. My problem is how to tell pgf the patch table because I only have the set of points. I should first plot the convex hull of the points with Mathematica and after that identify the vertices of each patch. Do you know how I could add another convex hull to the same figure? – user1993416 Jun 05 '18 at 20:21
  • @user1993416 You can add an arbitrary number of \addplot3 commands in a given axis environment, I think. What might be tricky, however, is the ordering of the polygons, but I have not tried this in this context. –  Jun 05 '18 at 20:23
  • @user1993416 Yes, of course. Just do \addplot3[colormap/viridis,... for instance. –  Jun 05 '18 at 20:31