Describing Multiple Cubes using a Single Struct
3 次查看(过去 30 天)
显示 更早的评论
If I use patch to draw two cubes like this:
format compact h(1) = axes('Position',[0.2 0.2 0.6 0.6]);
%----first cube------ vert = [1 1 1; 1 2 1; 2 2 1; 2 1 1 ; ... 1 1 2;1 2 2; 2 2 2;2 1 2]; fac = [1 2 3 4; ... 2 6 7 3; ... 4 3 7 8; ... 1 5 8 4; ... 1 2 6 5; ... 5 6 7 8]; patch('Faces',fac,'Vertices',vert,'FaceColor','r'); % patch function material shiny; alpha('color'); alphamap('rampdown'); view(30,30);
%------second cube----- hold on; vert2 = [1 1 1; 1 2 1; 2 2 1; 2 1 1 ; ... 1 1 2;1 2 2; 2 2 2;2 1 2]-0.5; fac2 = [1 2 3 4; ... 2 6 7 3; ... 4 3 7 8; ... 1 5 8 4; ... 1 2 6 5; ... 5 6 7 8]; patch('Faces',fac2,'Vertices',vert2,'FaceColor','b'); % patch function
...how can I then combine the data into a single struct? I need the data for both cubes to be in the same struct (with fields fv.faces and fv.vertices), so I can then save it to an STL file using stlwrite.
Alternatively (to achieve the same objective) if I have face and vertices data for two overlapping objects, how can I combine it into one set of face and vertices data?
Thanks.
0 个评论
回答(1 个)
Aniruddha Katre
2014-9-4
You can create struct arrays to store the same type of data for multiple cubes.
For example, you can store the faces and vertices data for the first cube as:
fv(1).faces = fac;
fv(1).vertices = vert;
Then you can store the same information for the second cube as:
fv(2).faces = fac2;
fv(2).vertices = vert2;
For more information about Struct Arrays, see:
and
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!