I am new to 3D-Calculations and i searched for a while, but couldnt find any solutions (maybe I am using the wrong search terms).
So i have different 3D-Point-Clouds - for example a "pyramid" with 5 points:
The array looks like this:
pts = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0],
[0.5, 0.5, 1], ])
Now i want to extract all "surfaces" - my plan was to calculate the convex-hull but I couldnt find any properties to get the surface - i tested with scipy.spatial
hull = ConvexHull(pts)
For example i want following output:
surfaceCount: 5
surface[0]: [0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0] (yellow)
surface[1]: [0, 0, 0], [0, 1, 0], [0.5, 0.5, 1] (blue)
surface[2]: [0, 0, 0], [1, 0, 0], [0.5, 0.5, 1] (no color)
surface[3]: [1, 0, 0], [1, 1, 0], [0.5, 0.5, 1] (orange)
surface[4]: [1, 1, 0], [0, 1, 0], [0.5, 0.5, 1] (green)
How can i calculate these "surfaces"?
Thanks Mr.Dev
EDIT: Ok, i thought my questions was specific engough - but here is my next try (i found the library "pyvista")
I have following code:
import numpy as np
import pyvista as pv
points = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0],
[0.5, 0.5, 1], ])
# points is a 3D numpy array (n_points, 3) coordinates of a sphere
cloud = pv.PolyData(points)
volume = cloud.delaunay_3d(alpha=5.)
shell = volume.extract_geometry()
surf = volume.extract_surface()
ug = surf.cast_to_unstructured_grid()
surf.plot()
pv.save_meshio("test.obj", surf)
This code generates me a *.obj file
# Created by meshio v5.2.2, 2022-01-16T16:44:24.834322
v 0.0 0.0 0.0
v 1.0 1.0 0.0
v 1.0 0.0 0.0
v 0.5 0.5 1.0
v 0.0 1.0 0.0
f 1 2 3
f 1 3 4
f 1 5 2
f 1 4 5
f 3 2 4
f 2 5 4
And shows me a plot:
I expected to find 5 "faces" in this object file - but there are 6 - because the "Ground" is splitted into two triangles - entries:
f 1 2 3
f 1 5 2
So my question is: Is it possible (maybe with pyvista), to generate an output file (doesn't matter if its an .obj file or something else) in which i can find exactly 5 "faces" for the pyramide?
Thanks
You don't need Delaunay. Moreover the faces must be given by the indices of their points.
import numpy as np
import pyvista as pv
pts = np.array([[0, 0, 0],
[1, 0, 0],
[1, 1, 0],
[0, 1, 0],
[0.5, 0.5, 1]], np.float64)
faces = np.hstack([[3, 0, 1, 4],
[3, 1, 2, 4],
[3, 2, 3, 4],
[3, 0, 3, 4],
[4, 0, 1, 2, 3]])
mesh = pv.PolyData(pts, faces)
mesh.plot()
mesh.area
Out[24]: 3.23606797749979