Old versions of Mathematica ($VersionNumber < 6
) supported a particular syntax of ParametricPlot3D[]
that allowed for graphics specifications to be supplied as the fourth component of a vector-valued function; e.g. ParametricPlot3D[{f[u, v], g[u, v], h[u, v], Hue[w[u, v]]}, {u, umin, umax}, {v, vmin, vmax}]
.
Nowadays, this functionality has been superseded by the options ColorFunction
, PlotStyle
, and other related functions. Unfortunately, some flexibility seems to have been lost with these changes.
For instance, the old implementation of ParametricPlot3D[]
allowed me to use FaceForm[]
to color the two faces of a polygon differently, with the stuff within FaceForm[]
depending on the parameters. This allowed me to do things like this:
<<Version5`Graphics` (* simulates old-school graphics *)
ParametricPlot3D[{(3 + Cos[u]) Cos[v], (3 + Cos[u]) Sin[v], Sin[u],
{EdgeForm[], FaceForm[ColorData["DarkRainbow"][Rescale[v, {0, Pi/2}]],
ColorData["BrightBands"][Rescale[v, {0, Pi/2}]]]}},
{u, -7 Pi/6, 7 Pi/12}, {v, Pi/6, Pi/2},
Axes -> False, Boxed -> False, Lighting -> False, PlotPoints -> 41]
Unfortunately, as can be seen through close inspection, I miss out on the adaptive plotting capability that is provided by the current implementation of ParametricPlot3D[]
.
I know that in the current version, the output is a GraphicsComplex[]
object, with the colors assigned through the option VertexColors
, which doesn't interact at all with directives like FaceForm[]
. It has been suggested to me that I do two plots with the different colorings, with one a perturbed version of the other, and then combining these two into one Graphics3D[]
object. This seems rather wasteful to me, however.
In short: how can I do parameter-dependent coloring of a surface plotted with ParametricPlot3D[]
, with the faces colored differently?
(added 1/21/2011)
Both of the answers given so far rely on the fact that color gradients in Mathematica can be turned into images that can subsequently be used as textures. Unfortunately, this doesn't seem to be applicable to general coloring schemes. Consider for instance the following twisted cylinders:
<<Version6`Graphics` (* restore default graphics *)
With[{a = 1, p = 2/3},
GraphicsGrid[{
{ParametricPlot3D[{a Cos[u] Cos[p Pi v] - a Sin[u] Sin[p Pi v],
a Cos[p Pi v] Sin[u] + a Cos[u] Sin[p Pi v], v},
{u, 0, 3 Pi/2}, {v, -1, 1}, Axes -> None, Boxed -> False,
ColorFunction -> (Hue[(1 - Cos[3 Pi #5] Sin[4 #4])/2] &),
ColorFunctionScaling -> False, Mesh -> False, PlotPoints -> 85],
ParametricPlot3D[{a Cos[u] Cos[p Pi v] - a Sin[u] Sin[p Pi v],
a Cos[p Pi v] Sin[u] + a Cos[u] Sin[p Pi v], v},
{u, 0, 3 Pi/2}, {v, -1, 1}, Axes -> None, Boxed -> False,
ColorFunction -> (Hue[(1 + Cos[3 #4] Cos[4 Pi #5])/2] &),
ColorFunctionScaling -> False, Mesh -> False, PlotPoints -> 85]}
}]]
where the cylinder on the left is colored with Hue[(1 - Cos[3 Pi v] Sin[4 u])/2
and the one on the right is colored with Hue[(1 + Cos[3 u] Cos[4 Pi v])/2]
. I want to be able to use something like FaceForm[Hue[(1 + Cos[3 u] Cos[4 Pi v])/2], Hue[(1 - Cos[3 Pi v] Sin[4 u])/2]]
, as with the following image:
<< Version5`Graphics`
With[{a = 1, p = 2/3},
ParametricPlot3D[{a Cos[u] Cos[p Pi v] - a Sin[u] Sin[p Pi v],
a Cos[p Pi v] Sin[u] + a Cos[u] Sin[p Pi v], v, {EdgeForm[],
FaceForm[Hue[(1 + Cos[3 u] Cos[4 Pi v])/2],
Hue[(1 - Cos[3 Pi v] Sin[4 u])/2]]}},
{u, 0, 3 Pi/2}, {v, -1, 1},
Axes -> None, Boxed -> False, Lighting -> False, PlotPoints -> 85]]
and it looks to me that the current solutions don't apply to this situation. What can be done here?
ColorFunction
for each plot. $\endgroup$