1
$\begingroup$

I am new to Mathematica, and I am currently using it to plot 3D figures. My problem is when I use Graphic3D with Specularity and try to add color gradient on top of the 3D object (in my case, a tube) using Glow function.

Graphics3D[{Glow@ColorData["CandyColors"][#] & /@ Table[1/i, {i, 100}],
   Tube[BSplineCurve[KnotData[{3, 1}, "SpaceCurve"] /@ Subdivide[0, 2 Pi, 100],
     SplineClosed -> True], .4]},
   Boxed -> False]

The color somehow just doesn't show.

Update

I also tried to use

Graphics3D[{Directive[Glow[ColorData["CandyColors"][#]],
  Specularity[White, 10]] & /@ Range[1, 100],
    Table[Tube[BSplineCurve[KnotData[{3, 1}, "SpaceCurve"] /@ Subdivide[0, 2 Pi, 100],
      SplineClosed -> True], .4], {i, 1, 100}]},
    Boxed -> False]

with Directive. Also doesn't work.

Can someone please tell me what went wrong in this case?

PS: I want something like this enter image description here

$\endgroup$
2
  • $\begingroup$ If you're using a Mathematica notebook, you should be able to tell that your '#' in the KnotData is pink, meaning it's not associated with a function. You need # followed by & somewhere. I think you meant KnotData[#, "SpaceCurve"] & After this you'll then get errors because # will get filled in with a number from the Subdivide and KnotData doesn't take a number like that. You probably meant KnotData["Trefoil", "SpaceCurve"] /@ Subdivide[0, 2 Pi, 100] $\endgroup$
    – flinty
    Commented Jul 30 at 11:01
  • $\begingroup$ @flinty Sorry for the confusion. I edited the question so that now the command correctly produces the problem I mentioned. $\endgroup$
    – kiz
    Commented Jul 30 at 12:01

1 Answer 1

3
$\begingroup$

Using BSplineFunction instead of BSplineCurve allows the use of ColorFunction. Something like this:

f = BSplineFunction[
  KnotData[{3, 1}, "SpaceCurve"] /@ Subdivide[0, 2 Pi, 100], SplineClosed -> True];

ParametricPlot3D[f[x], {x, 1, 100}, Axes -> False, Boxed -> False, 
 AspectRatio -> 1, PlotStyle -> Tube[.5], 
 ColorFunction -> "CandyColors", PlotRange -> 3.5, 
 Lighting -> {SpotLight[White, ImageScaled[{1, 1, 1}], 1], 
   SpotLight[White, ImageScaled[{1, 1, 1}], 1]}]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks a great deal for your answer. However, when I tried to plot for other knots ({4,1} and {6,3} etc.), the tube either broke or got flat in multiple regions. I adjusted the value for the B-spline range and tube radius, but the resulting plot is just not as good as Tube[BSplineCurve[KnotData[{6,3}, "SpaceCurve"] /@ Subdivide[0, 2 Pi, 100]. Is there a neat way of dealing with this? Thanks in advance for your help: ) $\endgroup$
    – kiz
    Commented Jul 31 at 5:30
  • 1
    $\begingroup$ @kiz For KnotData[{6,3}, "SpaceCurve"] this method works perfectly for me, just set PlotRange -> 7.5 $\endgroup$
    – yarchik
    Commented Jul 31 at 19:39
  • 1
    $\begingroup$ @yarchik That indeed solves it. Thanks! I tried to use PlotRange -> All with Specularity and Glow, but the glow was too bright that it appeared to be a breakage. The resulting plot is a bit too squeezed but I think changing the viewing angle would do the job for now. Thanks again for your help! $\endgroup$
    – kiz
    Commented Aug 1 at 3:24

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.