-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathhull_numpy.py
More file actions
84 lines (64 loc) · 1.87 KB
/
Copy pathhull_numpy.py
File metadata and controls
84 lines (64 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def convex_hull_numpy(points):
"""Compute the convex hull of a set of points.
Parameters
----------
points : array_like[point]
XYZ coordinates of the points.
Returns
-------
ndarray[int](N, )
Indices of the points on the hull.
ndarray[int](M, 3)
Faces of the hull.
Raises
------
ValueError
If the input data is not 3D.
See Also
--------
convex_hull_xy_numpy
Notes
-----
The faces of the hull returned by this function do not necessarily have consistent
cycle directions. To obtain a mesh with consistent cycle directions, construct
a mesh from the returned vertices, this function should be used in combination
with :func:`compas.topology.unify_cycles`.
"""
from numpy import asarray
from scipy.spatial import ConvexHull
points = asarray(points)
n, dim = points.shape
if dim < 3:
raise ValueError("The point coordinates should be at least 3D: %i" % dim)
points = points[:, :3]
hull = ConvexHull(points)
return hull.vertices, hull.simplices
def convex_hull_xy_numpy(points):
"""Compute the convex hull of a set of points in the XY plane.
Parameters
----------
points : array_like[point]
XY(Z) coordinates of the points.
Returns
-------
ndarray[int](N, )
Indices of the points on the hull.
ndarray[int](M, 2)
Lines of the hull.
Raises
------
ValueError
If the input data is not at least 2D.
See Also
--------
convex_hull_numpy
"""
from numpy import asarray
from scipy.spatial import ConvexHull
points = asarray(points)
n, dim = points.shape
if dim < 2:
raise ValueError("The point coordinates should be at least 2D: %i" % dim)
points = points[:, :2]
hull = ConvexHull(points)
return hull.vertices, hull.simplices