2
$\begingroup$

I'm using ChartElementData["CylindricalSector3D"] to generate graphics representing a series of stacked concentric rings (4 rings, 3 layers high). I'm looking to highlight sections of this via variable opacities, so I've set it up as a function f[a,b,c,{d1,d2,d3,d4},{e1,e2,e3}]; a/b/c sets up some basic parameters, dn are the opacities of the rings, and en are the opacities of the layers.

Also, since "CylindricalSector3D" natively draws a vertical face that would have visible edges, I've generated new outlines using cylinders with FaceForm[None]. Code:

rads2[bore_] := 0.5*{{30.35 + 1.75*bore, 37.1}, {18.95 + 1.75*bore, 30.35 - 1.75*bore}, {7.3 + 0.8*bore, 18.95 - 1.75*bore}, {0, 7.3 - 0.8*bore}};
hts2 = {5.7, 6.4, 6.2};
faceHeights[zSep_, heights_, zoffset_] := 0.5*heights*{-1, 1} + 0.5*zoffset*(6.4 + heights + 2*zSep)*{1, 1};

cols2 = {Darker[Purple, 0.5], Blue, Darker[Green, 0.7], Darker[Orange, 0.3]};
lght[color_, blending_] := {{"Ambient", GrayLevel[0.4]}, {"Directional", Blend[{GrayLevel[0.1], color}, blending], {0, 0, 1}}};

opcts[opH_, opV_] := Opacity[0.15 + 0.85*opH*opV];
segments[rad_, zSep_, opH_, opV_, heights_, zoffset_] := {opcts[opH, opV], EdgeForm[None], ChartElementData["CylindricalSector3D"][{{0, 2 \[Pi]}, rad, faceHeights[zSep, heights, zoffset]}, 0]};
edges[i_, j_, bore_, zSep_, opH_, opV_, heights_, zoffset_] := {FaceForm[None], EdgeForm[Directive[Thickness[0.003], opcts[opH, opV]]], Map[Cylinder[{{0, 0, faceHeights[zSep, heights, zoffset][[1]]},{0, 0, faceHeights[zSep, heights, zoffset][[2]]}}, #] &, rads2[bore][[i]]]};

First block is basic geometric setup. The second one defines my custom lighting: I'm highlighting the different rings by having them lit from above by different colors. The third generates individual segment and edges, which will be combined with Table to form the full image.

Both the segments and outlines seem to work great, independently:

allsegments[bore_, zSep_, coloring_, opacHoriz_, opacVert_] :=  Graphics3D[Table[{Lighting -> lght[cols2[[i]], coloring], segments[rads2[bore][[i]], zSep, opacHoriz[[i]], opacVert[[j]], hts2[[j]], j - 2]}, {i, 1, 4}, {j, 1, 3}], Boxed -> False, Method -> {"ShrinkWrap" -> True}];
alledges[bore_, zSep_, coloring_, opacHoriz_, opacVert_] := Graphics3D[Table[{edges[i, j, bore, zSep, opacHoriz[[i]], opacVert[[j]], hts2[[j]], j - 2]}, {i, 1, 4}, {j, 1, 3}], Boxed -> False, Method -> {"ShrinkWrap" -> True}];

opts = Transpose@{
{0, 0, 0, {1, 1, 1, 1}, {1, 1, 1}},
{0.5, 0.5*10, 0.5, {1, 1, 1, 1}, {1, 1, 1}},
{1, 10, 1, {1, 1, 1, 1}, {1, 1, 1}},
{1, 10, 1, {1, 1, 1, 1}, {1, 0, 0}},
{1, 10, 1, {1, 1, 1, 1}, {0, 1, 0}},
{1, 10, 1, {1, 1, 1, 1}, {0, 0, 1}},
{1, 10, 1, {1, 0, 0, 0}, {1, 1, 1}},
{1, 10, 1, {0, 1, 0, 0}, {1, 1, 1}},
{1, 10, 1, {0, 0, 1, 0}, {1, 1, 1}},
{1, 10, 1, {0, 0, 0, 1}, {1, 1, 1}}
};
GraphicsRow[MapThread[allsegments, opts], ImageSize -> 1300]
GraphicsRow[MapThread[alledges, opts], ImageSize -> 1300]

enter image description here

However, when I try to combine them into a single Graphics3D object, most of my highlighting seems to be affected. This seems surprising since both are populated by identical Tables in the preceding example, and I just grouped the arguments together.

combinedFeats[bore_, zSep_, coloring_, opacHoriz_, opacVert_] := Graphics3D[Table[{Lighting -> lght[cols2[[i]], coloring], segments[rads2[bore][[i]], zSep, opacHoriz[[i]], opacVert[[j]], hts2[[j]], j - 2], edges[i, j, bore, zSep, opacHoriz[[i]], opacVert[[j]], hts2[[j]], j - 2]}, {i, 1, 4}, {j, 1, 3}], Boxed -> False, Method -> {"ShrinkWrap" -> True}];
GraphicsRow[MapThread[combinedFeats, opts], ImageSize -> 1300]

enter image description here

Interestingly, the appropriate lighting is actually still present, but apparently applied from the bottom:

GraphicsRow[Table[Show[combinedFeats[1, 10, 1, {1, 1, 1, 1}, {1, 1, 1}], ViewPoint -> {1.3, -2.4, vpz}], {vpz, {2, 0, -2}}], ImageSize -> 1000]

enter image description here

Further, even though the compiled segments and outlines are generated properly (first image), trying to combine these with Show yields similar (but different) issues:

combinedImgs[bore_, zSep_, coloring_, opacHoriz_, opacVert_] := Show[{allsegments[bore, zSep, coloring, opacHoriz, opacVert], alledges[bore, zSep, coloring, opacHoriz, opacVert]}, Boxed -> False];
GraphicsRow[MapThread[combinedImgs, opts], ImageSize -> 1300]

enter image description here

Normally I wouldn't be surprised to have to flesh out some unwanted interaction to lighting/camera settings when interleaving the segments and edges (compared to using them together, but that obviously doesn't explain the issue that appears with show.

Note:

  • I was able to come up with a refreshingly simple (if not entirely satisfying) workaround that was suitable for my example - add a second light source from the opposite site. So, this is mostly for my edification.
  • Also, I was using ParametricPlot3D in an earlier version and don't remember these issues popping up, but I ended up switching to Cylinders because they were simpler in form and faster to evaluate.
  • Lastly, there's probably more elegant ways than using "CylindricalSector3D" (it's a bit on the clunky side), but other versions of this ended up using non-circular sectors, so I was looking to build off that

Thanks in advance!

$\endgroup$
  • 1
    $\begingroup$ I can't reproduce your output from GraphicsRow[MapThread[combinedFeats, opts], ImageSize -> 1300]. I see this. What version of Mathematica and what OS are you using? My screenshot is from 11.3 on Mac. $\endgroup$ – Chip Hurst Dec 28 '18 at 2:14
  • $\begingroup$ Interesting...I'm using 11.1.1 on Windows $\endgroup$ – stallada Dec 28 '18 at 5:56
  • 1
    $\begingroup$ @stallada What is the question? $\endgroup$ – Alex Trounev Dec 28 '18 at 13:59
  • $\begingroup$ Here's a summary. Basically, I have two object definitions (one for a shape, and another corresponding to it's outline) which both seem to work properly when I generate them (via a table) independently. When I generate them together though, the output has incorrect lighting. Strangely, even combining the two independent graphics with Show yields the same type of issues, but differently. @ChipHurst tried it and it worked for him, so I assume it's some weird issue on my end. $\endgroup$ – stallada Dec 29 '18 at 15:56
  • $\begingroup$ It could be an OS issue. I don’t have a windows machine to test on, but you might want to try rearranging the order of your graphic primitives. Also see if any RenderingOptions settings help. $\endgroup$ – Chip Hurst Dec 29 '18 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.