Subtracted 3D shape not fully defined

4 visualizzazioni (ultimi 30 giorni)
Coleman
Coleman il 12 Feb 2025
Risposto: Umar il 12 Feb 2025
I've been using c = subtract(shape1,shape2) but the resulting shape c does not appear to be fully defined. It only has vertices but the other important properties return []. This is an issue when c is concave because alphaShape does not generate the correct shape from the vertices. Is there a way to determine the fully defined shape the results from the subtraction of two 3D custom shapes?

Risposte (1)

Umar
Umar il 12 Feb 2025

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.

Categorie

Scopri di più su Bounding Regions in Help Center e File Exchange

Tag

Prodotti


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by