MathGroup Archive 2003

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

Search the Archive

Re: Coloring a surface

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39121] Re: Coloring a surface
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 30 Jan 2003 01:06:10 -0500 (EST)
  • References: <b183vl$koi$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Jean P." <Jean.Pellegri at wanadoo.fr> wrote in message
news:b183vl$koi$1 at smc.vnet.net...
> I want plot and color a surface x=f(u,v), y=g(u,v), z=h(u,v)
>
>  How to create a color function colorfunc[x,y,z] (or colorfunc[u,v])
> that associate a color at each point of the surface ??
>
> Thanks
>
> Scuse for my very bad english language !!
>
> Jean P.
>

Jean,

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.
To see the colors specfied we have to turn off the lighting.

ParametricPlot3D[
  {Cos[u](1 + Cos[t]/2), Sin[u](1 + Cos[t]/2), Sin[t],
   {EdgeForm[Hue[0.7]], Hue[t]}
  },
  {t, 0, 2Pi},{u, 0, Pi},
 Lighting ->False,
  Boxed -> False, Axes->False
];


ParametricPlot3D[
  {Cos[u](1 + Cos[t]/2), Sin[u](1 + Cos[t]/2), Sin[t],
   {EdgeForm[Hue[0.7]],
   FaceForm[Hue[t],Hue[2u]]}
  },
  {t, 0, 2Pi},{u, 0, Pi},
 Lighting ->False,
  Boxed -> False, Axes->False
];

To get detailed coloring you will need to use a large number of small
polygons (PlotPoints->500, say) and suppress the edges of the polygons
(EdgeForm[ ]).

Here is a more complex example. Please look up any  new terms in the Help
Browser.

First by reflected light and specified light sources.

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->False
];

Now, turn off the lighting to see the "painted" version

Show[%, Lighting -> 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.

--
Allan

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









  • Prev by Date: Re: domain for sum of geometric series
  • Next by Date: Re: Re: Integrating Abs[Sin[]^2]
  • Previous by thread: RE: Coloring a surface
  • Next by thread: Re: Coloring a surface