Skip to main content
1 of 2
george2079
  • 39.1k
  • 1
  • 44
  • 111

if you do not know the range a priori you can run the plot once to get it, then again to plot:

dist[x_, y_, z_] = Abs[x + y];
range = dist @@@ 
   Reap[ParametricPlot3D[{Cos[u] Cos[v], Sin[u] Cos[v], Sin[v]}, {u, 
       0, 2 \[Pi]}, {v, -\[Pi]/2, \[Pi]/2}, 
      ColorFunction :> (Sow[{#1, #2, #3}] &)]][[2, 1]] // MinMax

{0.292893, 1.70711}

ParametricPlot3D[{Cos[u] Cos[v], Sin[u] Cos[v], Sin[v]}, {u, 0, 
  2 \[Pi]}, {v, -\[Pi]/2, \[Pi]/2}, 
 ColorFunction :> (Blend[{{range[[1]], Red}, {range[[2]], Green}}, 
     dist[#1, #2, #3]] &)]

enter image description here

george2079
  • 39.1k
  • 1
  • 44
  • 111