MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Function Coloring with ParametricPlot3D

  • To: mathgroup at
  • Subject: [mg31267] Re: Function Coloring with ParametricPlot3D
  • From: "Allan Hayes" <hay at>
  • Date: Fri, 26 Oct 2001 04:28:06 -0400 (EDT)
  • References: <9r57ic$s3v$>
  • Sender: owner-wri-mathgroup at

Here is an excerpt from my column in Mathematica in Education in Education
and Research 8.1.
You will see that averages of the parameters for the four corners are used
in the fourth coordinate.
We could construct a function to use the coordinate values at the four

Automatic styling with ParametricPlot3D

The optional fourth coordinate, the style coordinate, s in
ParametricPlot[{x, y, z, s}, {t, tmin, tmax},{u, umin, umax}] can be used to
give directives to individual polygons.

  {Cos[u](1 + Cos[t]/2), Sin[u](1 + Cos[t]/2), Sin[t],
   {Hue[t],SurfaceColor[Hue[2u, 0.3, 0.9]]},
   {Hue[2u, 0.3, 0.9], SurfaceColor[Hue[t]]}
  {t, 0, 2Pi},{u, 0, Pi},
  LightSources -> {{{1, 0, 1}, GrayLevel[1]}},
  Boxed -> False, Axes\[Rule]False

The directives given to a polygon are calculated by a kind of averaging :
for example, if s is {RGBColor[r,g,b], EdgeForm[Thickness[t]]}then we get
triples like {RGBColor[ avr, avg, avb ], EdgeForm[Thickness[avt]], polygon},
where avr ....  denote the averages over the values of the parameters{t,u}
that give the vertices of the polygon (not over the coordinates of the
vertices). The same rule works for Thickness, GrayLevel and CMYKColor;  but
not for Hue, which has to take into account that, for example, Hue[0] and
Hue[1] both give red. I have not yet worked out how this is done. A single
directive need not be in a list.
Here is the first styled polygon from the above output.



Turn off the lighting to see the "painted" version

Show[%, Lighting -> False];

Allan Hayes
Mathematica Training and Consulting
Leicester UK
hay at
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"David Park" <djmp at> wrote in message
news:9r57ic$s3v$1 at
> Dear MathGroup,
> There is a percularity of the ParametricPlot3D command with color
> specification as the fourth element that bugs me.
> It appears that this is the way that the algorithm works. Mathematica
> calculates the color that would result from the four corners of the square
> and then blends the colors. I suppose that in some sense this can be
> considered to be reasonable. But if you write a color function that
> specifices a specific set of colors, this blending introduces new colors
> which one may not want. Here is an example.
> Needs["Graphics`Colors`"]
> cfun[x_, y_] :=
>  Module[{val = Sqrt[x^2 + y^2]},
>   Which[
>   val <= 7, PaleGreen,
>   val > 7, OrangeRed]]
> ParametricPlot3D[{x, y, 0, cfun[x, y]}, {x, 0, 10}, {y, 0, 10},
>  PlotPoints -> 8,
>  Lighting -> False];
> What I would like to do is have Mathematica determine a single function
> value for each square, perhaps by averaging the values at the four
> and then apply my color function to that single value. In that case there
> would be no blending, unless I decide to do the blending in my color
> function.
> Does anyone know how to work around this?
> David Park
> djmp at

  • Prev by Date: Re: Function Coloring with ParametricPlot3D
  • Next by Date: Solving NL-PDE by (Mathematica) NDSolve?
  • Previous by thread: Re: Function Coloring with ParametricPlot3D
  • Next by thread: (-8)^(1/3)