基于Python 3的3D散点图凸面网格构建技术问询
Great question! Let's break this down step by step for you:
1. Is using Delaunay Triangulation feasible for building a convex surface mesh?
Absolutely—here's the breakdown:
- 3D Delaunay Triangulation generates a tetrahedral mesh from your point cloud, and the surface of this tetrahedral mesh is exactly the convex hull of your original points. So it’s a valid approach to get a convex surface mesh.
- That said, the raw surface from Delaunay (or directly from
ConvexHull) will only use your outermost input points. If those points are unevenly distributed on the convex boundary, the resulting triangles will be skewed (not near-equilateral) by default.
2. Saving ConvexHull coordinates and connectivity
Your existing ConvexHull object already contains all the data you need—you just need to extract and save it properly:
hull.points: The full array of your input 3D Cartesian coordinates (shape:[number_of_points, 3])hull.simplices: The face connectivity array, where each row holds the 3 indices of vertices that form a triangular face (shape:[number_of_faces, 3])
Here’s how to save these to disk with NumPy:
# Save vertex coordinates np.save('convex_hull_vertices.npy', hull.points) # Save face connectivity data np.save('convex_hull_faces.npy', hull.simplices)
To reload them later, simply use np.load() on these files.
3. Making convex hull triangles more equilateral
The core issue with raw ConvexHull output is that it’s tied directly to your input point distribution. To get near-equilateral triangles, you’ll need to remesh and optimize the convex hull surface. Libraries like trimesh or pyvista make this straightforward.
Here’s a practical example using trimesh:
First, install the library if you haven’t:
pip install trimesh
Then, refine and optimize your convex hull mesh:
import numpy as np from scipy.spatial import ConvexHull import trimesh # Load your point cloud pts = np.load('cart.npy') hull = ConvexHull(pts) # Convert ConvexHull data to a trimesh object mesh = trimesh.Trimesh(vertices=hull.points, faces=hull.simplices) # Step 1: Refine the mesh to add more vertices (creates smaller, more flexible triangles) # Adjust iterations to control how many new vertices are added (higher = finer mesh) refined_mesh = mesh.subdivide_loop(iterations=2) # Step 2: Optimize triangle shapes to be near-equilateral # Set target_edge_length to a value that fits your data (smaller = finer, more uniform triangles) optimized_mesh = refined_mesh.remesh(target_edge_length=0.5) # Save the final optimized mesh data np.save('optimized_vertices.npy', optimized_mesh.vertices) np.save('optimized_faces.npy', optimized_mesh.faces) # Optional: Visualize the result optimized_mesh.show()
Quick tips for optimization:
- Loop subdivision: Smooths the mesh and adds evenly spaced vertices, giving you more control over triangle shape.
- Target edge length: Tweak this value based on your point cloud’s scale—this dictates how uniform the final triangle sizes will be.
- If you don’t want to add new vertices, you can use Laplacian smoothing with shape constraints, but this won’t fix extremely skewed triangles as effectively as full remeshing.
4. Alternative: Extracting surface from 3D Delaunay Triangulation
If you specifically want to use Delaunay for your workflow, you can generate a tetrahedral mesh and extract its surface (which matches the convex hull):
from scipy.spatial import Delaunay # Generate 3D Delaunay tetrahedral mesh delaunay = Delaunay(pts) # Extract surface faces (equivalent to ConvexHull.simplices) surface_faces = delaunay.convex_hull # You’ll still need to remesh this surface to get near-equilateral triangles, as explained above
内容的提问来源于stack exchange,提问作者Sandra52

