Clear Filters
Clear Filters

How to convert a 3D model into an STL File ?

18 views (last 30 days)
Arshiya Pandey
Arshiya Pandey on 19 Apr 2023
Edited: Sai Kiran on 26 Apr 2023
I am having difficulty in converting my model into an stl file. When I used the stlwrite function directly, it gave me an error stating the argument should be a triangulation object. I tried using the delaunay triangulation metho but to no avail. I do'tt know how to proceed further. Can someone please point me in the right direction?
Here is a snippet of my matlab code:
% Define the dimensions of the room
roomWidth = 5;
roomLength = 10;
wallWidth = 0;
wallHeight = 3;
wallPositions = [0 0; roomWidth 0; roomWidth roomLength; 0 roomLength; 0 0; roomWidth/2 roomLength/2];
% Define the vertices of the walls
vertices = [
wallPositions(1,1) wallPositions(1,2) 0;
wallPositions(2,1) wallPositions(2,2) 0;
wallPositions(2,1) wallPositions(2,2) wallHeight;
wallPositions(1,1) wallPositions(1,2) wallHeight;
wallPositions(1,1)+wallWidth wallPositions(1,2)+wallWidth 0;
wallPositions(2,1)-wallWidth wallPositions(2,2)+wallWidth 0;
wallPositions(2,1)-wallWidth wallPositions(2,2)+wallWidth wallHeight;
wallPositions(1,1)+wallWidth wallPositions(1,2)+wallWidth wallHeight;
wallPositions(3,1) wallPositions(3,2) 0;
wallPositions(4,1) wallPositions(4,2) 0;
wallPositions(4,1) wallPositions(4,2) wallHeight;
wallPositions(3,1) wallPositions(3,2) wallHeight;
wallPositions(3,1)-wallWidth wallPositions(3,2)+wallWidth 0;
wallPositions(4,1)+wallWidth wallPositions(4,2)+wallWidth 0;
wallPositions(4,1)+wallWidth wallPositions(4,2)+wallWidth wallHeight;
wallPositions(3,1)-wallWidth wallPositions(3,2)+wallWidth wallHeight;
wallPositions(1,1) wallPositions(1,2) 0;
wallPositions(4,1) wallPositions(4,2) 0;
wallPositions(4,1) wallPositions(4,2) wallHeight;
wallPositions(1,1) wallPositions(1,2) wallHeight;
wallPositions(1,1)+wallWidth wallPositions(1,2)+wallWidth 0;
wallPositions(4,1)+wallWidth wallPositions(4,2)+wallWidth 0;
wallPositions(4,1)+wallWidth wallPositions(4,2)+wallWidth wallHeight;
wallPositions(1,1)+wallWidth wallPositions(1,2)+wallWidth wallHeight;
wallPositions(2,1) wallPositions(2,2) 0;
wallPositions(3,1) wallPositions(3,2) 0;
wallPositions(3,1) wallPositions(3,2) wallHeight;
wallPositions(2,1) wallPositions(2,2) wallHeight;
wallPositions(2,1)-wallWidth wallPositions(2,2)+wallWidth 0;
wallPositions(3,1)+wallWidth wallPositions(3,2)+wallWidth 0;
wallPositions(3,1)+wallWidth wallPositions(3,2)+wallWidth wallHeight;
wallPositions(2,1)-wallWidth wallPositions(2,2)+wallWidth wallHeight
];
% Define the faces of the walls
faces = [
1 2 3 4;
1 5 6 4;
2 5 6 3;
1 2 5 4;
4 3 6 5;
1 2 3 6];
% Define the colors of the walls
colors = [
0.8 0.8 0.8;
0.8 0.8 0.8;
0.8 0.8 0.8;
0.8 0.8 0.8;
0.8 0.8 0.8;
0.8 0.8 0.8];
% Create a patch object for the walls
walls = patch('Vertices', vertices, 'Faces', faces, 'FaceVertexCData', colors, 'FaceColor', 'flat');
view(3);
% Set the axis limits of the room
axis([0 roomWidth 0 roomLength 0 wallHeight]);
% Label the axes of the room
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');

Answers (1)

Sai Kiran
Sai Kiran on 26 Apr 2023
Edited: Sai Kiran on 26 Apr 2023
Hi,
As per my understanding you want to convert the 3D model into .stl format.
The 'stlwrite' function only supports conversion 2D triangulation objects to .stl format.
Tetrahedron triangulation(3D) is not supported as of now.
I hope it helps!
Thanks.

Products

Community Treasure Hunt

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

Start Hunting!