Using:
brick = Graphics3D[{Opacity[0.1], Cuboid[{-1, -1, 0}, {1, 1, 7}]}];
sh = Show[brick, Boxed -> False, Axes -> False, ImageSize -> 200,
ViewPoint -> {-1, -3, 0.8}]
I am able to generate this figure:
but I would need to have a data-dependent color gradient in the vertical direction, something like this (sketched in PowerPoint):
and yet have reduced opacity (i.e., some transparency), as I will be later adding objects inside the cuboid, like this:
In other words, I strive to add a vertical gradient for the cuboid in this last figure. The gradient should be proportional to the known vertical component of the arrows pictured within.
Possible or impossible?
Note: This last figure was generated using this code:
mx = {{-0.03531465108285024`}, {-0.1283046412785981`},
{-0.24771693472139578`}, {-0.4132775274322698`},
{-0.6328859911062533`}, {-0.8473624829000416`},
{-0.7837308535290136`}};
my = {{-0.12948515385140505`}, {-0.13668245759341002`},
{-0.17327322834888242`}, {-0.243821916431452`},
{-0.3487914280726116`}, {-0.45468558648142543`},
{-0.41631413754133023`}};
mz = {{-0.9909482484399573`}, {-0.9822625802845403`},
{-0.953190140247742`}, {-0.8772965420277177`},
{-0.6910608996801697`}, {-0.2735259613942102`}, {0.4605417079976964`}};
arrows = Flatten[
Table[{Red,
Arrow[Tube[{{0, 0, (k - 1) + 0.5},
Flatten[{mx[[k]], my[[k]], mz[[k]] + (k - 1) + 0.5}]}]]}, {k,
1, 7}]];
arrows = Graphics3D[arrows,
PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}, {-1, 7}}];
brick = Graphics3D[{Opacity[0.1],
Cuboid[{-1, -1, -0.5}, {1, 1, 8 - 0.5}]}];
sh = Show[{brick, arrows}, Boxed -> False, Axes -> False,
ImageSize -> 200, ViewPoint -> {-1, -3, 0.8}]






RescaleandClip:smoothStep2[a_, b_, x_] := With[{t = Clip[Rescale[x, {a, b}], {0., 1.}]}, t^2 Subtract[3., 2. t]];... – Henrik Schumacher Apr 09 '18 at 08:57Clip[]norRescale[]are compilable, tho. – J. M.'s missing motivation Apr 09 '18 at 09:00smoothStep2is as fast (at least on my machine). But what I actually tried to point for the OP is that we don't need aCompilehere. (Admittedly, I am usually quite quick in drawingCompilebut I am aware that it may be hard to grasp for beginners.) – Henrik Schumacher Apr 09 '18 at 09:05