1
$\begingroup$

I have a function f[u,v] from $R^2 \to R$ that I want to use like coloring function over the surface:

sigma[u_,v_]:={Cos[u]*Cos[v],Sin[u]*Cos[v],Sin[v]^3}.

For that I've used the expression:

ParametricPlot3D[sigma[u, v], {u, 0, Pi}, {v, 0, 2*Pi}, Mesh -> None, 
 ColorFunction -> Function[{u, v}, ColorData["Rainbow"][f[u, v]]]]

where

 f[u_,v_]:=-((576 Cos[2 u])/(17 - 9 Cos[4 u])^2).

The result is:

enter image description here

which is not what I wanted.

I need that my coloring function evaluates colors in the coordinates position over the surfaces, depending from the sign of f[u,v] (for instance darker blue when f in strongly negative and a lighter color when f is strongly positive).

Thank you.

$\endgroup$
  • $\begingroup$ Try ParametricPlot3D[sigma[u, v], {u, 0, Pi}, {v, 0, 2*Pi}, Mesh -> None, ColorFunction -> (ColorData["Rainbow"][#3] &)]. $\endgroup$ – IPoiler Jan 21 '16 at 18:13
2
$\begingroup$

In addition to the scaling issue, you need have your color function use the correct variables. To quote the documentation

The arguments supplied to functions in MeshFunctions and RegionFunction are x, y, z, u, and v. Functions in ColorFunction and TextureCoordinateFunction are by default supplied with scaled versions of these arguments.

This means that in order to use the parametric variables, u and v, as I believe you intend, you need to alter your function

Function[{x, y, z, u, v}, ColorData["Rainbow"][Rescale[f[u, v], {min, max}]]]

which gives

enter image description here

$\endgroup$
  • $\begingroup$ Thank you for answering it works now😊 $\endgroup$ – Cesare Jan 22 '16 at 21:06
1
$\begingroup$

If you are going to use a custom color function you have to do the scaling of its values yourself. So you need to find the range of values of your color function, rescale its output value accordingly and tell ParametricPlot3D not to do scaling itself.

min = NMinValue[{f[u, v], 0 <= u <= Pi && 0 <= v <= 2 Pi}, {u, v}];
max = NMaxValue[{f[u, v], 0 <= u <= Pi && 0 <= v <= 2 Pi}, {u, v}];
ParametricPlot3D[sigma[u, v], {u, 0, Pi}, {v, 0, 2*Pi}, Mesh -> None, 
 ColorFunction -> 
     Function[{u, v}, ColorData["Rainbow"][Rescale[f[u, v], {min, max}]]], 
 ColorFunctionScaling -> False]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Thank you for your answer ; actually i didn't express myself good, i want that in the point {u', v'}, the color of Sigma{u', v'} is given by f[u', v']. $\endgroup$ – Cesare Jan 22 '16 at 20:43
  • $\begingroup$ Have a look at rcollyer's answer. I was assuming that you were referring to the x,y values since your f took only two arguments. $\endgroup$ – Sjoerd C. de Vries Jan 22 '16 at 20:52
  • $\begingroup$ Yes, thank you again $\endgroup$ – Cesare Jan 22 '16 at 21:05

Your Answer

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

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