Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Shading Functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg14347] Re: Shading Functions
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 15 Oct 1998 00:28:50 -0400
  • References: <6vuo01$899@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Des Penny wrote in message <6vuo01$899 at smc.vnet.net>...
>Hi Folks:
>
>I'm having trouble invoking the shading function in one form.
>
>The following works ok:
>
>In[1]:=
>p1=Plot3D[Sin[x y],{x,-1,1},{y,-2,2}, AxesLabel->{X,Y,Z}];
>
>If we map the range of the plot into {0,0.8}, we will now be able to
>color the heights of a plot so that the lowest points are red and the
>highest points are Blue/Purple.
>
>In[2]:=
>PlotRange[p1]
>Out[2]=
>{{-1.,1.},{-2.,2.},{-1.04461,1.04461}}
>
>In[3]:=
>zrange=PlotRange[p1][[3]]
>Out[3]=
>{-1.04461,1.04461}
>
>The max and min values of Sin are {-1,1}, so this checks.
>
>We now want to map the heights, z, into the range {0,0.8}. Using the
>linear map, c=a z+b we find c=0.40 z+0.40 will work.
>
>In[4]:=
>(0.4 zrange+0.4)
>Out[4]=
>{-0.0178423,0.817842}
>
>If we now operate on each z value with Hue we will display this z value
>in the correct color:
>
>In[5]:=
>Clear[colorFun];
>colorFun[z_]:=Hue[0.4(z+1)]
>
>In[6]:=
>p2=Plot3D[{Sin[x y], colorFun[Sin[x y]]},{x,-1,1},{y,-2,2},
>AxesLabel->{X,Y,Z}];
>
>This works fine.
>
>However the following does not work correctly.  I'm not sure why.
>
>In[7]:=
>Show[p2, ColorFunction->colorFun];
>
>I was under the impression that the above statement caused colorFun to
>operate on the z values of the function.  We should get the same plot
>as the preceeding Plot3D but we don't.  The output of the above clearly
>shows that colorFun is operating, but not correctly.
>
>Can anyone help explain what's going on?
>
>Cheers,
>
>Des Penny
>
>

Des,

The mechanisms are different.
Here is an attempt at describing them.


1) With Plot3D[{f[x, y],c[x,y]},{x,xmin,xmax},{y,ymin,ymax}]

For each polygon displayed, the color is given by the "average" of
c[x,y] over the x y 's  for the vertices What does "average" mean? The
following seems to work , where  av means average over the polygon
vertex x y's) , but cav also takes into account the cycling of
Hue[x](for example Hue[0] and Hue[1] both give red) in a way that I
have not yet sorted out completely.

    average RGB[r,g,b]  = RGBColor[ av[r], av[g], av[b]]
    average Hue[h, s,b] = RGBColor[ cav[r], av[g], av[b]]

The colors are stored in an extra grid in the SurfaceGraphics object
generated.

2) With Plot3D[f[x y],{x,xmin,xmax},{y,ymin,ymax}, ColorFunction ->cf]

Each polygon is shaded by the color directive cf[average scaled height
at vertices],
Where, with PlotRange  = {{xmin,xmax},{ ymin,ymax}, {zmin,zmax}, the
scaling of the heights is linear with zmin ->0 and zmax ->1.

An extra twist is that {zmin, zmax} will not usually be {Min[f{x,y} at
plot points],
Max[f{x,y} at plot points]}.

3) Your example

In place of your In[7]

Show[p1, ColorFunction->(Hue[.8#]&)]

will give a result close to the result from p2.

Allan

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




  • Prev by Date: Recommended books for Mathematica
  • Next by Date: Re: Mathmatica Problem...
  • Previous by thread: Re: Shading Functions
  • Next by thread: Re: Shading Functions