combine two stl into one

53 views (last 30 days)
Alberto Acri
Alberto Acri on 22 Jun 2024
Commented: DGM on 31 Mar 2025
I have two 3D geometries ('sol_1.stl' and 'sol_2.stl') and their corresponding nodes and faces.
I would like to combine the two STL geometries into a single geometry, or merge the nodes and faces of the two geometries into one.
  • sol_1.st + sol_2.st -> sol_fin.stl
  • nodes_sol_1 + nodes_sol_2 -> nodes_sol_fin (simple)
  • faces_sol_1 + faces_sol_2 -> faces_sol_fin

Accepted Answer

Avni Agrawal
Avni Agrawal on 28 Jun 2024
I understand that you are trying to combine two STL geometries into a single geometry by merging their nodes and faces in MATLAB, you can follow these steps:
  1. Read the STL files to get the nodes and faces.
  2. Merge the nodes and faces from both geometries.
  3. Write the combined geometry to a new STL file.
Below is a MATLAB script that demonstrates how to do this:
% Read the STL files
fv1 = stlread('../sol/sol_1.stl');
fv2 = stlread('../sol/sol_2.stl');
% Extract nodes (vertices) and faces from the first geometry
nodes1 = fv1.Points;
faces1 = fv1.ConnectivityList;
% Extract nodes (vertices) and faces from the second geometry
nodes2 = fv2.Points;
faces2 = fv2.ConnectivityList;
% Merge nodes
% Note: We need to adjust the face indices of the second geometry
% by adding the number of nodes in the first geometry
% Combine nodes
combinedNodes = [nodes1; nodes2];
% Adjust face indices for the second geometry
adjustedFaces2 = faces2 + size(nodes1, 1);
% Combine faces
combinedFaces = [faces1; adjustedFaces2];
% Create a new triangulation object for the combined geometry
combinedGeometry = triangulation(combinedFaces, combinedNodes);
% Write the combined geometry to a new STL file
stlwrite(combinedGeometry, 'combined_geometry.stl');
I hope this helps.
  1 Comment
DGM
DGM on 31 Mar 2025
Note that this doesn't actually do any CSG to combine the geometry (e.g. the union). This just creates a model with two independent connected components.
If the objects intersect, there will be no new vertices or edges formed at their intersection, and the model will have interior and/or tangential faces and edges.

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!