How to write multiple object surfaces/solids to a single .stl file?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have multiple object surfaces (refer to the image attached below) in Matlab defined by X,Y,Z coordinate data and Triangle connectivity (T). I am using stlwrite function to create a stl file from triangulation object. It can write only one triangulation object surface to a stl file. So if I have 100's of objects, I will have to create that many stl files. But, Is there a way to write all object surfaces into a single stl file? Thank you.

0 commentaires
Réponses (2)
Pratyush Swain
le 18 Avr 2024
Hi Vinit,
I understand you want to write multiple object surfaces to a single stl file. I believe this MATLAB answer thread will be helpful for your usecase: https://www.mathworks.com/matlabcentral/answers/701737-how-could-i-generate-several-ellipsoids-in-a-single-stl-file#comment_1227172.
In the above case , the user has successfully written two ellipsoid figures into an stl file. He creates triangulation object and applies alphaShape function for each ellipsoid after which the boundary faces are extracted and new set of triangulation is established,then creates a structure to store faces and vertices of each ellipsoid and a final triangulation of all figures is forged and written to file.
I am hopeful going through above thread will provide you with helpful insights for your task.
1 commentaire
DGM
le 15 Juil 2025
The use of alphashape() is completely irrelevant here. User already has the triangulations.
DGM
le 15 Juil 2025
Modifié(e) : DGM
le 17 Juil 2025
If you already have a set of triangulation objects, or multiple sets of triangulated F,V data, the rest is fairly simple. It's little more than concatenation and some index offsets.
% you already have an array of triangulation objects
% so let's just make one for testing
p0 = 2.8; p = [1/p0 1 p0]; os = 2.5;
Tc = cell(numel(p),1);
for k = 1:numel(p)
[X Y Z] = superquad(p(k),1,48);
[F V] = surf2patch(X + os*(k-1),Y,Z,'triangles');
Tc{k} = triangulation(F,V);
end
% combine everything into one triangulation object
T = tricat(Tc); % attached
% write it
stlwrite(T,'test.stl')
% read it back for show and tell
T = stlread('test.stl');
[F V] = t2fv(T);
patch('faces',F,'vertices',V,'facecolor',[0.2 0.8 1]*0.8,'edgecolor','none');
view(3); view(-35,15); camlight;
axis equal; grid on
If you had (e.g.) a cell array of F,V lists instead of a cell array ot triangulation objects, the same process applies. Get F and V for each part, combine them with the output lists.
Depending on the context, you might want to prune redundant vertices from the F,V data after it's consolidated. In this case, there are none.
EDIT: I updated this example to use tricat() to combine the data. That will work for triangulation objects, F,V lists, or a number of other types of data. The output vertex list is automatically pruned (again, that doesn't matter in this example).
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!