フィルターのクリア

Describing Multiple Cubes using a Single Struct

2 ビュー (過去 30 日間)
Chris Williams
Chris Williams 2014 年 9 月 4 日
コメント済み: Chris Williams 2014 年 9 月 5 日
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.

回答 (1 件)

Aniruddha Katre
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
  1 件のコメント
Chris Williams
Chris Williams 2014 年 9 月 5 日
Thanks, but I don't think stlwrite will accept a struct in that form.
This works:
nv1=length(fv1.vertices);
fv_combined.vertices=[fv1.vertices;fv2.vertices]
fv_combined_faces=[fv1.faces; fv2.faces+nv1]
However , the problem now is that the merged file is getting very large. How can I address this please?|

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSTL (STereoLithography) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by