title: Picture Convex hull in 3D Scatter Plot
body: <p>I followed the tutorial about 3D visualization using the package "rgl" <a href="http://www.sthda.com/english/wiki/a-complete-guide-to-3d-visualization-device-system-in-r-r-software-and-data-visualization" rel="nofollow noreferrer">here</a></p>
  
  <p>So I was able to draw a 3D Scatter Plot with "iris" data and create an ellipsoid surrounding 95 % of the data points:</p>
  
  <pre><code>library("rgl")
  data(iris)
  x &lt;- sep.l &lt;- iris$Sepal.Length
  y &lt;- pet.l &lt;- iris$Petal.Length
  z &lt;- sep.w &lt;- iris$Sepal.Width
  plot3d(x, y, z, col="blue", box = FALSE,
     type ="s", radius = 0.15)
  ellips &lt;- ellipse3d(cov(cbind(x,y,z)), 
                  centre=c(mean(x), mean(y), mean(z)), level = 0.95)
  plot3d(ellips, col = "blue", alpha = 0.2, add = TRUE, box = FALSE)
  </code></pre>
  
  <p>I know that the first 50 data points belong to a different population compared the the rest of the dataset, so colour them in a different way and us two ellipsoids to cover them:</p>
  
  <pre><code>plot3d(x, y, z, col=c(rep("gold2",50),rep("forestgreen",100)), box = FALSE,
     type ="s", radius = 0.15)
  ellips1 &lt;- ellipse3d(cov(cbind(x[1:50],y[1:50],z[1:50])), 
                  centre=c(mean(x[1:50]), mean(y[1:50]), mean(z[1:50])), level = 0.999)
  ellips2 &lt;- ellipse3d(cov(cbind(x[51:150],y[51:150],z[51:150])), 
                   centre=c(mean(x[51:150]), mean(y[51:150]), mean(z[51:150])), level = 0.999)
  plot3d(ellips1, col = "gold2", alpha = 0.2, add = TRUE, box = FALSE)
  plot3d(ellips2, col = "forestgreen", alpha = 0.2, add = TRUE, box = FALSE)
  </code></pre>
  
  <p>Although both populations can be clearly differentiated from each other, the ellipsoids touch each other. Therefore the ellipsoids are not a good visual representation of the data points. In a 2D Plot I would prefer to use a polynom whitch sourrounds all the data points, but in 3D something like a convex hull should be adequate, i.e. a polyhedron consisting of triangel areas which combine three outer data points each. </p>
  
  <p>I think the function convhulln() using the QuickHull algorithm in the package "geometry" would be helpful but I am not able to use this.</p>
  
  <p>Does somebody have an idea how to picture such a convex hull in the rgl plot? Is it also possible to do this with the plot3D package, since there is a great tutorial <a href="http://www.sthda.com/english/wiki/impressive-package-for-3d-and-4d-graph-r-software-and-data-visualization" rel="nofollow noreferrer">here</a> which I could use to make a beautiful plot with my own data.</p>
  
  <p>I am "only" a Biologist using R for science and not a mathematician or R programmer, so please explain your solution for me. Thanks a lot.</p>