I am facing an issue while combining two stl.

2 visualizaciones (últimos 30 días)
Vijay
Vijay el 29 de Oct. de 2024
Respondida: DGM el 18 de Jul. de 2025
I have two 3D geometries along with their associated nodes and faces. I want to combine these two STL geometries by merging their nodes and faces into single geometry.

Respuestas (2)

Gayatri
Gayatri el 29 de Oct. de 2024
Hi Vijay,
Below is a MATLAB script that demonstrates how to combine two STL into one single geometry:
% Read the STL files
shape1 = stlread('file1.stl');
shape2 = stlread('file2.stl');
% Extract nodes and faces from both geometries
vertices1 = shape1.Points;
faces1 = shape1.ConnectivityList;
vertices2 = shape2.Points;
faces2 = shape2.ConnectivityList;
% Adjust face indices for the second geometry by adding the number of vertices from the first geometry to the second's face indices
updatedFaces2 = faces2 + size(vertices1, 1);
% Combine the vertices and faces
mergedVertices = [vertices1; vertices2];
mergedFaces = [faces1; updatedFaces2];
% Create a new triangulation object for the merged geometry
mergedGeometry = triangulation(mergedFaces, mergedVertices);
% Write the merged geometry to a new STL file
stlwrite(mergedGeometry, 'merged_geometry.stl');
Please refer the below documentations for 'stlread' and 'stlwrite' functions:

DGM
DGM el 18 de Jul. de 2025
See also:
This answer uses convenience funtions to do the concatenation, and it will automatically clean up redundant vertices. It works with triangulation objects and other formats.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by