6
$\begingroup$

Is it possible to use a gradient fill on the top surface of this annulus in matematica?

Graphics3D[
 ResourceFunction["Annulus3D"][{{0, 0, 0}, {0, 0, 2}}, {1, 3}]
]

I tried to use the Color function option but it doesn't work.

enter image description here

$\endgroup$
1
  • $\begingroup$ If you feel that the below answer solves your problem, make sure to accept it (click the checkmark). If not, leave a comment or edit your question to provide additional clarification. $\endgroup$ Aug 16, 2023 at 22:40

1 Answer 1

10
$\begingroup$

Something like this perhaps? This selects Hue based on angle:

n = 200;
s = Subdivide[n];
gOpts = {EdgeForm[], Hue[#], 
     ResourceFunction["Annulus3D"][{{0, 0, 0}, {0, 0, 1}}, {1, 
       3}, {#*2 Pi, (# + 1/n)*2 Pi}]} & /@ Most[s];
Graphics3D[gOpts, Boxed -> False, Lighting -> "Neutral"]

enter image description here

Another version with Hue based on radius:

n = 200;
maxR = 3;
rInner = 1;
s = Subdivide[rInner, maxR, n];
rescaled = Rescale[s];
gOpts = Table[{EdgeForm[], Hue[rescaled[[i]]], 
    ResourceFunction["Annulus3D"][{{0, 0, 0}, {0, 0, 1}}, {s[[i - 1]],
       s[[i]]}]}, {i, 2, n}];
Graphics3D[gOpts, Boxed -> False, Lighting -> "Neutral"]

enter image description here

Add-on

As pointed out in a comment below, you may only want the top to be colored. I used an example under the styling section of the Annulus3D documentation to just color the top surface (the top, bottom, and inner and outer radius are the first four elements of an Annulus3D object it looks like). This is a pretty ugly implementation so you can likely make it easier to read:

n = 200;
s = Subdivide[n];
gOpts = Flatten[
   Table[{baseL, baseH, circumIn, circumOut} = 
     ResourceFunction["Annulus3D"][{{0, 0, 0}, {0, 0, 1}}, {1, 
        3}, {i*2 Pi, (i + 1/n)*2 Pi}][[1 ;; 4]];
    {{EdgeForm[], Hue[i], baseH}, {EdgeForm[], Black, 
      baseL}, {EdgeForm[], Black, circumIn}, {EdgeForm[] , Black, 
      circumOut}}, {i, Most[s]}], 1];
Graphics3D[gOpts, Boxed -> False, Lighting -> "Neutral"]

enter image description here

$\endgroup$
1
  • $\begingroup$ @infinitezero thanks for pointing this out. I added another example, though the code for it can probably be improved $\endgroup$
    – ydd
    Aug 14, 2023 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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