How to convert a 3D model into an STL File ?
25 次查看(过去 30 天)
显示 更早的评论
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');
0 个评论
回答(1 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!