필터 지우기
필터 지우기

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 CenterFile Exchange에서 STL (STereoLithography)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by