by Gerrard_Liddell » Thu Mar 28, 2013 1:53 am
The problem is the function in the option
ColorFunction -> Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r},
Evaluate[color[\[CurlyTheta], \[CurlyPhi], fxn]]]
Either put it in by hand
SphericalPlot3D[
1/4 Sqrt[5/\[Pi]] (-1 + 3 Cos[\[CurlyTheta]]^2), {\[CurlyTheta],
0, \[Pi]}, {\[CurlyPhi], 0, 2 \[Pi]},
ColorFunction ->
Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r},
RGBColor[1/2 (1 + Sign[-1 + 3 Re[Cos[\[CurlyTheta]]^2]]), 0,
1/2 (1 - Sign[-1 + 3 Re[Cos[\[CurlyTheta]]^2]]), 0.75`]],
ColorFunctionScaling -> False, ImageSize -> 150, Axes -> False,
Boxed -> False, PlotRange -> All]
Here is a way of getting it into the spherical plot in so it does work correctly:
Clear[fxn];
Hold[SphericalPlot3D[
fxn, {\[CurlyTheta], 0, Pi}, {\[CurlyPhi], 0, 2*Pi},
ColorFunction ->
Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r},
Evaluate[color[\[CurlyTheta], \[CurlyPhi], fxn]]],
ColorFunctionScaling -> False,
ImageSize -> 150, Axes -> False, Boxed -> False,
PlotRange -> All]] /.
fxn -> (1/4)*Sqrt[5/Pi]*(3*Cos[\[CurlyTheta]]^2 - 1)
Here is a discussion of some of this:
If you construct the function and insert it via
With[{ fxn = 1/4 Sqrt[5/Pi] (3 Cos[\[CurlyTheta]]^2 - 1)},
Hold@SphericalPlot3D[
fxn, {\[CurlyTheta], 0, Pi}, {\[CurlyPhi], 0, 2 Pi},
ColorFunction ->
Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r},
Evaluate@color[\[CurlyTheta], \[CurlyPhi], fxn]],
ColorFunctionScaling -> False, ImageSize -> 150, Axes -> False,
Boxed -> False, PlotRange -> All]
]
off course it does not work because of scoping replacing the dummy variables:
Hold[SphericalPlot3D[
1/4 Sqrt[5/\[Pi]] (-1 + 3 Cos[\[CurlyTheta]]^2), {\[CurlyTheta],
0, \[Pi]}, {\[CurlyPhi], 0, 2 \[Pi]},
ColorFunction ->
Function[{x$, y$, z$, \[CurlyTheta]$, \[CurlyPhi]$, r$},
Evaluate[
color[\[CurlyTheta]$, \[CurlyPhi]$,
1/4 Sqrt[5/\[Pi]] (-1 + 3 Cos[\[CurlyTheta]]^2)]]],
ColorFunctionScaling -> False, ImageSize -> 150, Axes -> False,
Boxed -> False, PlotRange -> All]]
The function
Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r},
Evaluate@color[\[CurlyTheta], \[CurlyPhi], fxn]]
does evaluate to:
Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r},
RGBColor[1/2 (1 + Sign[-1 + 3 Re[Cos[\[CurlyTheta]]^2]]), 0,
1/2 (1 - Sign[-1 + 3 Re[Cos[\[CurlyTheta]]^2]]), 0.75]]
A trace of SphericalPlot reveals that it does correctly evaluate the option to
"ColorFunction" ->
"Function"[{"x", "y", "z", "\[CurlyTheta]", "\[CurlyPhi]", "r"},
"RGBColor"[
"Times"[1/2,
"Plus"[1,
"Sign"["Plus"[-1,
"Times"[3, "Re"["Power"["Cos"["\[CurlyTheta]"], 2]]]]]]], 0,
"Times"[1/2,
"Plus"[1,
"Times"[-1,
"Sign"["Plus"[-1,
"Times"[3, "Re"["Power"["Cos"["\[CurlyTheta]"], 2]]]]]]]],
0.75]]
(the strings are to allow analysis of the trace)
Hope this helps
Gerrard