-1

I am facing some problem in creating the meshed rectangle. I know the max and min coordinate values (xmin, xmax, ymin, ymax, zmin, zmax). So, I can easily find the vertex of the rectangle which are

[xmin ymin zmin; 
 xmax ymin zmin; 
 xmax ymax zmin; 
 xmin ymax zmin;
 xmin ymin zmax; 
 xmax ymin zmax; 
 xmax ymax zmax;
 xmin ymax zmax]

Now how can I create the rectangle with the surface mesh?

Suever
  • 64,497
  • 14
  • 82
  • 101
galib
  • 93
  • 2
  • 9

1 Answers1

0

You can do this using a patch in which you define vertices and the patch faces. For a rectangular prism, you can create your vertices and faces in the following way:

[xx,yy,zz] = ndgrid([xmin, xmax], [ymin, ymax], [zmin zmax]);
vertices = [xx(:), yy(:), zz(:)];

% Each row corresponds to a face of the prism and the values are indices into vertices
faces = [1     2     6     5
         2     4     8     6
         4     3     7     8
         3     1     5     7
         1     2     4     3
         5     6     8     7];

p = patch('Faces', faces, ...
          'Vertices', vertices, ...
          'FaceColor', [0, 0.4470, 0.7410], ...
          'FaceAlpha', 0.2);                        % Set transparency so we can see it

enter image description here

Suever
  • 64,497
  • 14
  • 82
  • 101
  • Thanks for your help!!!! But I need the surface mesh also. Can you help me with that? – galib Mar 22 '16 at 18:38
  • @galib What format are you looking for? Technically the `faces` and `vertices` above compose a surface mesh – Suever Mar 22 '16 at 18:41
  • @ Suever ...something like this.... http://nmr.mgh.harvard.edu/~fangq/temp/testmesh.png. or is it possible to use pdetoolbox to generate this kind of meshing. I know how to generate mesh using pdetool for .stl files. But here, I can't use .stl files, that's the problem. – galib Mar 22 '16 at 19:46