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 am very poor at visualization. I want to make a transparent "building" filled with gas. I wrote the following code for the building and it's fine.

 w = 100;
 l = 200;
 h = 30;
 m = 70;
 backwall = {{0, l, 0}, {w, l, 0}, {w, l, h}, {0, l, h}};
 side1 = {{0, 0, 0}, {0, 0, h}, {0, l, h}, {0, l, 0}};
 side2 = {{w, 0, 0}, {w, 0, h}, {w, l, h}, {w, l, 0}};
 floor = {{0, 0, 0}, {w, 0, 0}, {w, l, 0}, {0, l, 0}};
 top = {{0, 0, h}, {w, 0, h}, {w, l, h}, {0, l, h}};
 front = {{0, 0, 0}, {w, 0, 0}, {w, 0, h}, {0, 0, h}};
 leftRoof = {{0, 0, h}, {w/2, 0, m}, {w/2, l, m}, {0, l, h}};
 rightRoof = {{w, 0, h}, {w/2, 0, m}, {w/2, l, m}, {w, l, h}};
 fig = Graphics3D[{
   Transparent, Style[Polygon[{backwall, side1, side2, floor, front, leftRoof,rightRoof}],
   Lighting -> {{"Ambient", Green}}]},
   Boxed -> False,
   RotationAction -> "Clip"]

But in a second step, I want to fill the building with gas, which is also transparent. Why? Because after filling it with the gas, I will put points inside the building.

For this purpose, I wrote the following code.

data = RandomReal[60, {10, 3}];
data1 = RandomReal[60, {10, 3}];
redPoints = Graphics3D[{PointSize -> Large, Style[Point[#], Blue]} & /@ data, 
  Boxed -> False];
bluePoints = Graphics3D[{PointSize -> Large, Style[Point[#], Red]} & /@ data1, 
  Boxed -> False];
Show[{fig, redPoints, bluePoints}]

After evaluation of the above code, I am getting an image like this:

enter image description here

Transparent-building-wise and point-placement-wise this is fine; my problem is filling the building with gas. How can get the gas (light gray color) to fill the inside of the entire building. Can anyone help me?

share|improve this question
    
So which is it — snow or gas? If it's a colorless gas then problem solved, right? :D (I don't understand your question) –  rm -rf Feb 27 '13 at 7:49
    
@ rm -rf ,I want colored gas.I will remove that snow word in my question.also feel free ,If you want to edit my question. –  subbu Feb 27 '13 at 7:54
    
I think you're overcomplicating the question with "gas forms"... You probably just want a filled 3D polygon with Opacity. –  rm -rf Feb 27 '13 at 7:56
1  
possible duplicate of How can I make a transparent 3D Rectangle? –  Yves Klett Feb 27 '13 at 8:19
1  
@subbu but all you seem to need are semi-transparent polygons, for which this question is entirely sufficient. –  Yves Klett Feb 27 '13 at 8:29

3 Answers 3

up vote 7 down vote accepted

RegionPlot3D creates a surface made of polygons, not a solid volume, so it gives the same result as simply making the original polygons partially transparent.

Adding the roof ends:

roofBack = {{w, l, h}, {w/2, l, m}, {0, l, h}};
roofFront = {{w, 0, h}, {w/2, 0, m}, {0, 0, h}};

This uses just the 9 building polygons rather than the hundreds created by RegionPlot3D:

building = {backwall, side1, side2, floor, front, 
 leftRoof, rightRoof, roofBack, roofFront};

Graphics3D[{Opacity[0.5, Gray], Polygon[building]}, Boxed -> False]

enter image description here

Notice that the walls are still picking up colour from the lights. As in the original code in the question, you can Style the polygons with their own ambient Lighting for a completely flat effect:

Graphics3D[{Opacity[0.5, Gray],
  Style[Polygon[building], Lighting -> {{"Ambient", White}}]
  }, Boxed -> False]

enter image description here

For a slightly nicer (IMO) effect, you could use VertexColors to fade the polygons with increasing z:

Graphics3D[{Opacity[0.5],
  Style[Polygon[building,
    VertexColors -> Map[0.5 + #[[3]]/80 &, building, {2}]],
   Lighting -> {{"Ambient", White}}]
  }, Boxed -> False]

enter image description here

share|improve this answer

I suggest something like

gas = RegionPlot3D[
  0 < x < 100 && 0 < y < 200 && z > 0 && z < 30 + x/2 && 
  z < 80 - x/2, {x, 0, 250}, {y, 0, 250}, {z, 0, 100}, 
  PlotStyle -> Directive[Gray, Opacity[0.5]], Mesh -> None]

Show[{fig, redPoints, bluePoints, gas}]

gas

share|improve this answer
    
Thanks for your answer,but RegionPlot was not fixed exactly inside the Building. little bit of gaps are there on the top,sides.I will try that.again thanks for your answer –  subbu Feb 27 '13 at 9:41
    
subbu, I noticed that as well, that's why I qualified my answer with "something like". Consider my answer as a concept that requires further work. –  Iiss Feb 27 '13 at 10:01
    
added picture - but used PlotPoints to 120 for better fit. Perhaps it's a heavy gas; Wolfium, perhaps - heavier than air? :) –  cormullion Feb 27 '13 at 10:10
    
cormullion, this looks much better, and maybe if you use <= and >= rather than < and >, the gaps might disapear, and if I could just calculate the height of the roof, that might help as well, I'll get right to that... –  Iiss Feb 27 '13 at 11:54

I'm a bit worried about this idea of filling a building with gas, to be honest. But perhaps some good old-fashioned CO2 would be OK.

gas =  Flatten[
   Table[{x, y, z}, 
      {x, 10, w - 10, 10}, 
      {y, 10, l - 10, 10}, 
      {z, 10, h - 10, 5}], 2];

Graphics3D[{
  Opacity[0.2, Gray], 
  Polygon[building], 
  White, 
  Opacity[0.1],
  Sphere[#, RandomInteger[{1, 10}]] & /@ gas}, 
  Lighting -> "Neutral",
  Boxed -> False]

You would need to develop a region-function that can fill the space more accurately.

gas

share|improve this answer
    
Nice gas/giant bed! –  ssch Feb 27 '13 at 13:42
    
+1 for woolly sheep! lol (warning: processor intensive) –  Mr.Wizard Feb 27 '13 at 14:49

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.