Subtracted 3D shape not fully defined
Answers (1)
0 votes
Hi @Coleman,
After reviewing your comments, my understanding is that when using `c = subtract(shape1, shape2)`, you correctly obtain the vertices of the resultant shape `c`. However, you mentioned that essential properties (such as faces or edges) are not being defined properly, leading to issues when attempting to use `alphaShape` for further processing. This can happen if the subtraction results in a non-manifold geometry or if there are isolated vertices without corresponding faces. Here are possible solutions to consider:
1. Check Shape Validity: Before performing the subtraction, ensure that both `shape1` and `shape2` are valid shapes. You can use MATLAB’s built-in functions to verify their properties:
isValid1 = isvalid(shape1); isValid2 = isvalid(shape2);
2. Visual Inspection: Use the `show` function to visually inspect both shapes before and after subtraction. Adjusting transparency can help you see how they intersect.
show(shape1); hold on; show(shape2); hold off;
3. RetainShape Option: Experiment with the `RetainShape` parameter in the `subtract` function. Setting it to 1 (`c = subtract(shape1, shape2, RetainShape=1)`) may provide additional information about the resulting shape.
4. Use of alphaShape: After obtaining vertices from your subtraction operation, if you still face issues with generating a proper shape using `alphaShape`, consider adjusting parameters such as the alpha radius or using hole and region thresholds:
shp = alphaShape(c.Vertices(:,1), c.Vertices(:,2), c.Vertices(:,3), alphaRadius, 'HoleThreshold', someValue);
5. Post-processing: If your resultant shape remains poorly defined, consider reconstructing it by generating a mesh from the vertices using functions like `trisurf`, or employing Delaunay triangulation:
DT = delaunayTriangulation(c.Vertices); trimesh(DT);
6. Alternative Libraries: If MATLAB's built-in functions do not yield satisfactory results, consider exploring external libraries or toolboxes designed for geometric processing (e.g., CGAL for C++, if applicable).
Let me know if this helps.
Categories
Find more on Bounding Regions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!