Consider this example
Graphics3D[{EdgeForm[None], Opacity[0.5],
Blue, Cuboid[{0, 0, 0}, {1, 1, 1/3}],
Green, Cuboid[{0, 0, 1/3}, {1, 1, 2/3}],
Red, Cuboid[{0, 0, 2/3}, {1, 1, 1}],
Gray, Opacity[1], Sphere[{1/2, 1/2, #/3 - 1/6}, 0.1] & /@ {1, 2, 3}},
Boxed -> False]
For the green box, the edges and the surfaces in the back are also quite visible. For blue and red boxes the contrast is much smaller. How to improve it such a way that the edges would be visible from the difference in colour and also make the balls inside visible?
One possible way can be using an extra layer with slightly different opacity
Graphics3D[{EdgeForm[None], Opacity[0.5],
Blue, Cuboid[{0, 0, 0}, {1, 1, 1/3}],
Green, Cuboid[{0, 0, 1/3}, {1, 1, 2/3}],
Red, Cuboid[{0, 0, 2/3}, {1, 1, 1}],
Opacity[0.6],
Blue, Polygon[{{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}}],
Red, Polygon[{{0, 0, 2/3}, {0, 1, 2/3}, {0, 1, 1}, {0, 0, 1}}],
Gray, Opacity[1], Sphere[{1/2, 1/2, #/3 - 1/6}, 0.1] & /@ {1, 2, 3}},
Boxed -> False]
For a lot of boxes, it does not seem to be a good option.
Answer
One (tedious) way is to define a box with different Opacity for different surfaces.
opqbox[{x1_, y1_, z1_}, {x2_, y2_, z2_}, {d_, u_, l_, r_, b_, f_}] := {EdgeForm[None],
Opacity[b], Polygon[{{x1, y1, z1}, {x2, y1, z1}, {x2, y2, z1}, {x1, y2, z1}}],
Opacity[u], Polygon[{{x1, y1, z2}, {x2, y1, z2}, {x2, y2, z2}, {x1, y2, z2}}],
Opacity[r], Polygon[{{x1, y1, z1}, {x2, y1, z1}, {x2, y1, z2}, {x1, y1, z2}}],
Opacity[l], Polygon[{{x1, y2, z1}, {x2, y2, z1}, {x2, y2, z2}, {x1, y2, z2}}],
Opacity[o], Polygon[{{x1, y1, z1}, {x1, y2, z1}, {x1, y2, z2}, {x1, y1, z2}}],
Opacity[f], Polygon[{{x2, y1, z1}, {x2, y2, z1}, {x2, y2, z2}, {x2, y1, z2}}]}
opc={0.5,0.15,0.35,0.20,0.25,0.25};
Graphics3D[{EdgeForm[None],Opacity[0.5],
Blue,opqbox[{0,0,0},{1,1,1/3},opc],
Green,opqbox[{0,0,1/3},{1,1,2/3},opc],
Red,opqbox[{0,0,2/3},{1,1,1},opc],
Gray,Opacity[1],Sphere[{1/2,1/2,#/3-1/6},0.1]&/@{1,2,3}},
Boxed->False]
d, u, l, r, b, f are the Opacity for down, up, left, right, back and front face.
This cube is made by the method suggested by Michael E2 in this answer.




Comments
Post a Comment