3D plot coloring (using z value)

June 18 2011 acer 10376
Maple

6

This post in reply to the Question, change the shading=zhue colors

The ability to color a 3D plot using a color function is geared more for functions of x and y only.

But quite often, the surface or pointwise 3D position of the plot is itself being specified as a height z which is a function of x and y. For the plot3d comand, that's pretty much the way it works (whether using an expression or a procedure).

So, of course, the very same rule that generates the z value for the position can be used in the color function. The `option remember` can be used to avoid repeating the z calculations.

An alternative is to produce an original plot (using plot3d and the GRID structure here -- it would need changes for other generated plot structures) and then simply replace its COLOR or SHADING section with the desired color specification.

In this way, any custom color function can be used, and in particular a scheme could be used which only depends on the precomputed z-positions. The precomputed z-values (z-positions) are right there and accessible in the GRID portion of the plot structure. And the maximal and minimal z-positions can be used so as to attain particular desired colors at the extremes of the plot (making the whole coloring scheme be relative to the plot's actual position -- not known in advance, in general -- which isn't really possible using the first example's color function method).

Here are some examples. I'd actually been looking at with this topic already, off and on, but Christopher2222's question spurred me to post earlier than planned. Ideally, this could all be wrapped into some nice procedure that allowed easy use (eg. special cases like named colors for top and bottom positions being simply supplied as optional arguments, etc).

 

restart:

expr:=50+100*(y/10-5)*(x/10-5)^2/((y/10-5)^2+(x/10-5)^4):

f:=unapply(expr,[x,y],proc_options=[remember]):

P2:=plot3d(f,1..100,1..180,style=patch,
axes=boxed,color=[((x,y)->1-f(x,y)/100),((x,y)->f(x,y)/200),0]):
P2;

P1:=plot3d(f,1..100,1..180,shading=zhue,axes=boxed): P1;

Q:=op([1,3],indets(P1,specfunc(anything,GRID))):
zmin,zmax,nrowsQ,ncolsQ:=min(Q),max(Q),op(map(rhs,[rtable_dims(Q)])):

RGBfun:=proc(value)
   1-value, value, 0;
end proc:

colseq:=seq(seq(RGBfun(Q[i,j]/(zmax-zmin)),
                                j=1..ncolsQ),i=1..nrowsQ):
P1new:=subsindets(P1,specfunc(anything,SHADING),t->COLOR(RGB,colseq)):
P1new;

RGBfun:=proc(value)
   evalf(cos(value*2*Pi)), 1/2-evalf(cos(value*2*Pi)), 1/2-evalf(sin(value*2*Pi));
end proc:

colseq:=seq(seq(RGBfun(Q[i,j]/(zmax-zmin)),
                                j=1..ncolsQ),i=1..nrowsQ):
P1new:=subsindets(P1,specfunc(anything,SHADING),t->COLOR(RGB,colseq)):
P1new;

 

 

Download colorfunc.mw

 

acer

Please Wait...