Describing Multiple Cubes using a Single Struct
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Aniruddha Katre
on 4 Sep 2014
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
See Also
Categories
Find more on Image Acquisition Toolbox Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!