Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a random matrix RandomReal[{1, 2}, {20, 20}], whose elements represent the heights of an array of tiles. The cross sections of each tile are square and identical, viz, 10 x 10. How can I draw such a 3D structure? In addition, I need to put several layers on each tile, and each layer has the thickness of 0.5. In this case, how can I draw the whole structure or its cross section? Will partial transparency help?

Here is my code:

lambda= 500;
n1 = 1.5; n2 = 1.3;
h1 = lambda/4/n1; h2 = lambda/4/n2;
NQWS = 5;
Wx = 300; Dy = 300;
NX = 20; NY = 20;
h = lambda + RandomReal[{0, 2 lambda}, {NX, NY}];
corner1 = 
  Flatten[Table[{i*Wx, j*Dy, 0}, {i, 0, NX - 1}, {j, 0, NY - 1}], 1];
corner2 = 
  Flatten[Table[{i*Wx, j*Dy, h[[i, j]]}, {i, 1, NX}, {j, 1, NY}], 1];
h1corner1 = 
  Flatten[Table[{i*Wx, j*Dy, 
     h[[i + 1, j + 1]] + k*(h1 + h2) + h1}, {i, 0, NX - 1}, {j, 0, 
     NY - 1}, {k, 0, NQWS - 1}], 2];
h1corner2 = 
  Flatten[Table[{i*Wx, j*Dy, h[[i, j]] + k*(h1 + h2)}, {i, 1, NX}, {j,
      1, NY}, {k, 1, NQWS}], 2];
h2corner1 = 
  Flatten[Table[{i*Wx, j*Dy, h[[i + 1, j + 1]] + k*(h1 + h2)}, {i, 0, 
     NX - 1}, {j, 0, NY - 1}, {k, 0, NQWS - 1}], 2];
h2corner2 = 
  Flatten[Table[{i*Wx, j*Dy, h[[i, j]] + k*(h1 + h2) + h1}, {i, 1, 
     NX}, {j, 1, NY}, {k, 1, NQWS}], 2];
Graphics3D[{EdgeForm[None], Blue, 
  Table[Cuboid[corner1[[i]], corner2[[i]]], {i, 1, NX*NX}], 
  Opacity[0.8], Gray, 
  Table[Cuboid[h1corner1[[i]], h1corner2[[i]]], {i, 1, NX*NX*NQWS}], 
  Opacity[0.1], Red, 
  Table[Cuboid[h2corner1[[i]], h2corner2[[i]]], {i, 1, NX*NX*NQWS}]}, 
 Boxed -> False, Lighting -> "Neutral"]

and the following picture is the output structure:

rough surface

Well, I hope to get one like this:

SEM

If I just take the top view in my picture, I cannot tell the difference between the tiles of different heights. Any comments?

share|improve this question
1  
"In addition, I need to put several layers on each tile, and each layer has a same thickness of 0.5" ... not clear enough for me (What is a "layer"?) –  belisarius May 21 '13 at 17:50
    
I mean, such layers are several different types of materials from the random height substrate, so different colors might be needed to represent them. –  Tony Dong May 21 '13 at 17:56
    
So you're just piling up transparent cuboids. What is your difficulty doing that? –  belisarius May 21 '13 at 17:58
    
all right, I got it; probably I need to check my codes. –  Tony Dong May 21 '13 at 18:02
    
A few illustrative pictures from you might be in order... –  J. M. May 21 '13 at 18:04

1 Answer 1

Some things that might interest you:

dat = RandomReal[{1, 2}, {10, 10}];
ListPlot3D[dat, InterpolationOrder -> 0, Filling -> Bottom, Mesh -> None]

enter image description here

pillar[w_][h1_?NumericQ, {x_, y_}] := pillar[w][{0, h1}, {x, y}]
pillar[w_][{h0_, h1_}, {x_, y_}] := Cuboid[{x - w/2, y - w/2, h0}, {x + w/2, y + w/2, h1}]

Graphics3D[{
  Opacity[0.5],
  MapIndexed[pillar[1], dat, {2}]
}]

enter image description here

stack[w_][{hs__}, {x_, y_}] := 
 pillar[w][#, {x, y}] & /@ Partition[Accumulate@{0, hs}, 2, 1]

Graphics3D[{
  Opacity[0.5],
  MapIndexed[stack[1][{#, 0.5}, #2] &, dat, {2}]
}]

enter image description here

share|improve this answer
    
Thanks a lot, Mr.Wizard. –  Tony Dong May 21 '13 at 20:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.