7

I have a list of 3D points in a np.array called pointsList, values are float :

[[1., 2., 10.],
 [2., 0., 1.],
 [3., 6., 9.],
 [1., 1., 1.],
 [2., 2., 2.],
 [10., 0., 10.],
 [0., 10., 5.],
... etc.

This code makes a Delaunay triangulation of the cloud of points:

import numpy as np
import scipy.spatial 

tri = scipy.spatial.Delaunay(pointsList) 
# Delaunay triangulation

indices = tri.simplices
# indices of vertices

vertices = points[indices]
# the vertices for each tetrahedron

However, before that triangulation step, I'd like to remove from my list all the points that are inside of the convex hull

A solution would be to create a new np.array named shortlist, and store them there.

But what function in scipy (or any other solution), will do that?

How can I program this operation?

Thank you

adrienlucca.net
  • 677
  • 2
  • 10
  • 26

1 Answers1

15

The convex hull is a subgraph of the Delaunay triangulation.

So you might just use scipy.spatial.ConvexHull(), e. g.

from scipy.spatial import ConvexHull
cv = ConvexHull(pointList)

hull_points = cv.vertices
# the vertices of the convex hull

set(range(len(pointList))).difference(ch.vertices)
# the vertices inside the convex hull

Comparison scipy.spatial.Delaunay and scipy.spatial.ConvexHull (2D)

enter image description here

embert
  • 7,336
  • 10
  • 49
  • 78
  • 1
    How did you plot that image? – TripShock Jul 05 '14 at 17:41
  • @TripShock It's two images. I fed matplotlib with the scatter data (scatter plot) and the data of the linked vertices (line plot). The linked vertices you can get via the indices in the `simplices` attribute. – embert Jul 05 '14 at 18:44
  • @embert Thanks for the answer, but how can I compute the Delaunay triangulation *after* having performed the ConvexHull operation?? – adrienlucca.net Jul 18 '14 at 14:02
  • 1
    @adrienlucca.wordpress.com Why you want to do that? You can perform Delaunay *once* (scipy.spatial.Delaunay) and by doing so, you'll have the ConvexHull available, too (scipy.spatial.Delaunay.convex_hull). – embert Jul 18 '14 at 16:12