Re: Function Coloring with ParametricPlot3D
- To: mathgroup at smc.vnet.net
- Subject: [mg31271] Re: Function Coloring with ParametricPlot3D
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Fri, 26 Oct 2001 04:28:11 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
David Park wanted to use ParametricPlot3D with a fourth argument to specify
the color of Polygons and ensure only two colors are used in the resulting
graphic. David found that the straight forward approach in the code below
uses four colors.
------------
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},
Lighting->False];
--------------
Below I compute the average of the four corners of each polygon outside the
plot command. I think my approach here is an example of efficient
functional programming in Mathematica.
--------------
Clear[cfun];
cfun[x_, y_,_]:=Module[{val = Sqrt[x^2 + y^2]},
Which[ val <= 7, PaleGreen, val > 7, OrangeRed]
];
Block[{$DisplayFunction = Identity},
gr = ParametricPlot3D[{x, y, 0}, {x, 0, 10}, {y, 0, 10}];
average = Apply[Plus[##]/4.0&, gr[[1, All, 1]], {-3}];
Part[gr,1] = Transpose[ {cfun@@@average, First[gr]} ]
];
Show[gr, Lighting->False];
--------------
Some may be wondering what the {-3} inside Apply does. This is a level
specification. For an explanation of that look up "Level specification" on
my website. Also ## is SlotSequence[1] which is also explained on my
website
http://www.verbeia.com/mathematica/tips/Tricks.html
------
Regards,
Ted Ersek