Friday 15 March 2013

image - Simple cubic lattice using three-dimensional array -



image - Simple cubic lattice using three-dimensional array -

i want draw simple cubic lattice using matlab.

i have read how plot 3d grid (cube) in matlab, however, want color every little cube.

i have three-dimensional array in matlab, such as,

cube(:,:,1) = [1 0 1 0 1 1 1 1 0] cube(:,:,2) = [0 0 1 1 1 1 0 1 0] cube(:,:,3) = [1 1 1 0 1 1 1 0 1]

how can draw simple cubic lattice using array, in cube(:,:,1) denotes first floor of cubic lattice, cube(:,:,2) denotes sec floor, , cube(:,:,3) 3rd floor.

a 0 denotes little white cube, whilst 1 denotes little black cube.

the desired result this: http://www.instructables.com/id/puzzle-cube/

i couldn't find simpler, is!

c = randi(2,[3 3 3])-1; colorc = char(repmat('k',[3 3 3])); colorc(c == 0) = 'y'; figure(1); x = 0 : 2 y = 0 : 2 z = 0 : 2 vert = [1 1 0; 0 1 0; 0 1 1; 1 1 1; 0 0 1; 1 0 1; 1 0 0; 0 0 0]; vert(:,1) = vert(:,1) + x; vert(:,2) = vert(:,2) + y; vert(:,3) = vert(:,3) + z; fac = [1 2 3 4; 4 3 5 6; 6 7 8 5; 1 2 8 7; 6 7 1 4; 2 3 5 8]; patch('faces',fac,'vertices',vert,'facecolor',colorc(x + 1, y + 1, z + 1)); axis([0, 3, 0, 3, 0, 3]); alpha('color'); alphamap('rampdown'); axis equal hold on end end end

gives this,

if delete alpha('color'); , alphamap('rampdown');and utilize axis off, get,

arrays image matlab plot 3d

No comments:

Post a Comment