Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Cubic mesh problem

Subject: Cubic mesh problem

From: Liana

Date: 10 Nov, 2011 05:03:12

Message: 1 of 6

Hi,

I try to create a cubic mesh. The problem is that surf(X,Y,Z) generates 2D mesh for Z=0.5. But I need to decompose a cube into smaller cubes. Where is a mistake? Thanks.

% Generate 8 vertices of a cube
xyz = [0 0 0; 0 1 0; 1 0 0; 1 1 0; 0 0 1; 1 0 1; 0 1 1; 1 1 1];
rangeX=floor(min(xyz(:,1))):.2:ceil(max(xyz(:,1)));
rangeY=floor(min(xyz(:,2))):.2:ceil(max(xyz(:,2)));
[X,Y]=meshgrid(rangeX,rangeY);
Z=griddata(xyz(:,1),xyz(:,2),xyz(:,3),X,Y,'cubic');
% Visualize a mesh
surf(X,Y,Z);

Subject: Cubic mesh problem

From: Bruno Luong

Date: 10 Nov, 2011 08:31:11

Message: 2 of 6

"Liana" wrote in message <j9flug$seo$1@newscl01ah.mathworks.com>...
> Hi,
>
> I try to create a cubic mesh. The problem is that surf(X,Y,Z) generates 2D mesh for Z=0.5. But I need to decompose a cube into smaller cubes. Where is a mistake? Thanks.
>
> % Generate 8 vertices of a cube
> xyz = [0 0 0; 0 1 0; 1 0 0; 1 1 0; 0 0 1; 1 0 1; 0 1 1; 1 1 1];
> rangeX=floor(min(xyz(:,1))):.2:ceil(max(xyz(:,1)));
> rangeY=floor(min(xyz(:,2))):.2:ceil(max(xyz(:,2)));
> [X,Y]=meshgrid(rangeX,rangeY);
> Z=griddata(xyz(:,1),xyz(:,2),xyz(:,3),X,Y,'cubic');
> % Visualize a mesh
> surf(X,Y,Z);

You confuse between 'cublic' used in griddata, which is a piecewise *third* order polynomial which has noting to do with a 'cube' - a geometry property.

Bruno

Subject: Cubic mesh problem

From: Liana

Date: 10 Nov, 2011 16:35:31

Message: 3 of 6

Thanks, I see. Could you please give an idea how to create a data structure similar to a set of tetrahedrons in delaunay triangulation, but instead of tetrahedrons I'd like to use cubes. Is there any built-in approach?

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j9g24f$3sp$1@newscl01ah.mathworks.com>...
> "Liana" wrote in message <j9flug$seo$1@newscl01ah.mathworks.com>...
> > Hi,
> >
> > I try to create a cubic mesh. The problem is that surf(X,Y,Z) generates 2D mesh for Z=0.5. But I need to decompose a cube into smaller cubes. Where is a mistake? Thanks.
> >
> > % Generate 8 vertices of a cube
> > xyz = [0 0 0; 0 1 0; 1 0 0; 1 1 0; 0 0 1; 1 0 1; 0 1 1; 1 1 1];
> > rangeX=floor(min(xyz(:,1))):.2:ceil(max(xyz(:,1)));
> > rangeY=floor(min(xyz(:,2))):.2:ceil(max(xyz(:,2)));
> > [X,Y]=meshgrid(rangeX,rangeY);
> > Z=griddata(xyz(:,1),xyz(:,2),xyz(:,3),X,Y,'cubic');
> > % Visualize a mesh
> > surf(X,Y,Z);
>
> You confuse between 'cublic' used in griddata, which is a piecewise *third* order polynomial which has noting to do with a 'cube' - a geometry property.
>
> Bruno

Subject: Cubic mesh problem

From: Liana

Date: 10 Nov, 2011 18:56:27

Message: 4 of 6

I should define my question more accurately.
So, I need to decompose a cube into smaller cubes. I created an array xyz of coordinates for the grid points (vertices of small cubes). Now I need to explore all grid points and create cubes, i.e. cubes = struct('vertices',{}); cubes(1).vertices = [0 0 1; ...; 1 1 1]; % 8 vertices

Are there Matlab built-in functions that can do this?

Thanks.
"Liana" wrote in message <j9gugj$478$1@newscl01ah.mathworks.com>...
> Thanks, I see. Could you please give an idea how to create a data structure similar to a set of tetrahedrons in delaunay triangulation, but instead of tetrahedrons I'd like to use cubes. Is there any built-in approach?
>
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j9g24f$3sp$1@newscl01ah.mathworks.com>...
> > "Liana" wrote in message <j9flug$seo$1@newscl01ah.mathworks.com>...
> > > Hi,
> > >
> > > I try to create a cubic mesh. The problem is that surf(X,Y,Z) generates 2D mesh for Z=0.5. But I need to decompose a cube into smaller cubes. Where is a mistake? Thanks.
> > >
> > > % Generate 8 vertices of a cube
> > > xyz = [0 0 0; 0 1 0; 1 0 0; 1 1 0; 0 0 1; 1 0 1; 0 1 1; 1 1 1];
> > > rangeX=floor(min(xyz(:,1))):.2:ceil(max(xyz(:,1)));
> > > rangeY=floor(min(xyz(:,2))):.2:ceil(max(xyz(:,2)));
> > > [X,Y]=meshgrid(rangeX,rangeY);
> > > Z=griddata(xyz(:,1),xyz(:,2),xyz(:,3),X,Y,'cubic');
> > > % Visualize a mesh
> > > surf(X,Y,Z);
> >
> > You confuse between 'cublic' used in griddata, which is a piecewise *third* order polynomial which has noting to do with a 'cube' - a geometry property.
> >
> > Bruno

Subject: Cubic mesh problem

From: Bruno Luong

Date: 11 Nov, 2011 10:49:28

Message: 5 of 6

"Lulu" wrote in message <j9h6or$375$1@newscl01ah.mathworks.com>...
> I should define my question more accurately.
> So, I need to decompose a cube into smaller cubes. I created an array xyz of coordinates for the grid points (vertices of small cubes). Now I need to explore all grid points and create cubes, i.e. cubes = struct('vertices',{}); cubes(1).vertices = [0 0 1; ...; 1 1 1]; % 8 vertices
>

Not sure what is the problem you have. Just do the usual matlab programming

% Coordinates of all the grid points of (0,1)x(0,1)x(0,1) split in 4 x 4 x 4 smaller cubes
x=linspace(0,1,5)
y=linspace(0,1,5)
z=linspace(0,1,5)
[X Y Z]=ndgrid(x,y,z);
XYZ = [X(:) Y(:) Z(:)]

% cube indexed at (2,3,4)
i=2; j=3; k=4;
[I J K]=ndgrid(i+[0 1],j+[0 1],k+[0 1]);
ind=sub2ind(size(X),I,J,K)

% Here coordinates of the small cube
XYZ(ind,:)

Modify the code and organize the data at your will.

Bruno

Subject: Cubic mesh problem

From: Lulu

Date: 11 Nov, 2011 18:45:26

Message: 6 of 6

Thank you. This helped a lot. I didn't know about 'ndgrid' function.

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j9iujo$ma8$1@newscl01ah.mathworks.com>...
> "Lulu" wrote in message <j9h6or$375$1@newscl01ah.mathworks.com>...
> > I should define my question more accurately.
> > So, I need to decompose a cube into smaller cubes. I created an array xyz of coordinates for the grid points (vertices of small cubes). Now I need to explore all grid points and create cubes, i.e. cubes = struct('vertices',{}); cubes(1).vertices = [0 0 1; ...; 1 1 1]; % 8 vertices
> >
>
> Not sure what is the problem you have. Just do the usual matlab programming
>
> % Coordinates of all the grid points of (0,1)x(0,1)x(0,1) split in 4 x 4 x 4 smaller cubes
> x=linspace(0,1,5)
> y=linspace(0,1,5)
> z=linspace(0,1,5)
> [X Y Z]=ndgrid(x,y,z);
> XYZ = [X(:) Y(:) Z(:)]
>
> % cube indexed at (2,3,4)
> i=2; j=3; k=4;
> [I J K]=ndgrid(i+[0 1],j+[0 1],k+[0 1]);
> ind=sub2ind(size(X),I,J,K)
>
> % Here coordinates of the small cube
> XYZ(ind,:)
>
> Modify the code and organize the data at your will.
>
> Bruno

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us