MathGroup Archive 2001

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

Search the Archive

Re: Function Coloring with ParametricPlot3D

  • To: mathgroup at smc.vnet.net
  • Subject: [mg31267] Re: Function Coloring with ParametricPlot3D
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Fri, 26 Oct 2001 04:28:06 -0400 (EDT)
  • References: <9r57ic$s3v$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

David,
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
corners.



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.

ParametricPlot3D[
  {Cos[u](1 + Cos[t]/2), Sin[u](1 + Cos[t]/2), Sin[t],
   {EdgeForm[Hue[0.7]],
  FaceForm[
   {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.

%[[1,1]]

{EdgeForm[Hue[0.7]],
  FaceForm[{Hue[0.165347,0.3,0.9],
      SurfaceColor[Hue[0.165347,0.3,0.9]]},{Hue[0.165347],
      SurfaceColor[Hue[0.165347]]}],
  Polygon[{{1.5,0.,0.},{1.47291,0.,0.324699},{1.45282,0.242433,
        0.324699},{1.47954,0.246892,0.}}]}

Turn off the lighting to see the "painted" version

Show[%, Lighting -> False];

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"David Park" <djmp at earthlink.net> wrote in message
news:9r57ic$s3v$1 at smc.vnet.net...
> 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
corners,
> 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 earthlink.net
> http://home.earthlink.net/~djmp/
>
>
>




  • 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)