Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*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 2005

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

Search the Archive

Re: Light and surface colors

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58704] Re: [mg58688] Light and surface colors
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 15 Jul 2005 03:02:19 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Daniele,

I tried to send you a Mathematica notebook with the code for this but your
server rejected it because of a full mailbox.

To make a shaded plot with regular Mathematica graphics we could use
ParametricPlot3D with the 4th argument in the parametrization. The 4th
argument gives graphics directives for plotting the surface. We don't have
to turn the Lighting off if we give SurfaceColor instead of a raw color.

We redefine the pressure for the parameters of the ellipsoid.

ellipsoid[a_, b_, c_][u_, v_] := {a Cos[v]Cos[u], b Cos[v]Sin[u], c Sin[v]}
pressure[x_, y_, z_] := x^2 + y^2 + Sin[4z];
pressure[u_, v_] =
  pressure[x, y, z] /. Thread[{x, y, z} -> ellipsoid[7, 5, 4][u, v]]
49*Cos[u]^2*Cos[v]^2 + 25*Cos[v]^2*Sin[u]^2 + Sin[16*Sin[v]]

Then define the parametrization for the ellipsoid with the function on it.

ellipsoidfunction[a_, b_, c_][u_, v_] := {a Cos[v]Cos[u], b Cos[v]Sin[u],
    c Sin[v], {EdgeForm[], SurfaceColor[Hue[pressure[u, v]/50]]}}

Then we can plot.

ParametricPlot3D[ellipsoidfunction[7, 5, 4][u, v], {u, 0, 2*Pi},
   {v, -Pi/2, Pi/2},
   PlotPoints -> 100,
   ImageSize -> 450];

There are three problems with this plot. 1) The regular Mathematica lighting
tends to interfer with the colors on the surface. 2) The Hue color function
is not easy to interpret. What is high pressure and what is low pressure? 3)
It doesn't give a very accurate indication of what the shape of the contours
are. They are not quite as regular as one might expect.

My second solution uses DrawGraphics (from my web site below). It trims a
grid of polygons in the uv-plane to the contour regions and then maps the
resulting grids to the ellipsoidal surface. It uses the TwoColorScale
function to give a color scale that gives shades of blue for values below 25
and shades of red for colors above 25. It is much easier to interpret
two-color plots - they are similar to cartographic maps. The NeutralLighting
option is used to turn down the color saturation of the regular lighting so
it doesn't interfer with the surface colors.

Needs["DrawGraphics`DrawingMaster`"]

colorfun =
    TwoColorScale[{-0.29, 25, 49.7}, {ColorMix[RoyalBlue, Black][0.5],
        RoyalBlue, ColorMix[RoyalBlue, White][0.8], ColorMix[Red,
White][0.8],
         Red, ColorMix[Red, Black][0.5]}];

polygrid = N[MakePolyGrid[{40, 20}, {{0, -Pi/2}, {2*Pi, Pi/2}}]];
contours = Range[-0.29, 49.7, (49.7 + 0.29)/10];

Do[polys[i] = TrimPolygons[pressure[#1, #2] & ,
     {contours[[i]], contours[[i + 1]]}][polygrid],
  {i, 1, Length[contours] - 1}]

Draw3DItems[
   {Table[{SurfaceColor[colorfun[(contours[[i]] + contours[[i + 1]])/2]],
      EdgeForm[], polys[i] /. {(u_)?NumberQ, (v_)?NumberQ} ->
        ellipsoid[7, 5, 4][u, v]}, {i, 1, Length[contours] - 1}]},
   BoxRatios -> Automatic,
   NeutralLighting[0.1, 0.5, 0],
   Boxed -> False,
   Axes -> False,
   PlotRegion -> {{-0.1, 1.1}, {-0.3, 1.2}},
   ViewPoint -> {1.534, -2.831, 1.04},
   Background -> Linen,
   ImageSize -> 450];

The contours actually are somewhat irregular and wavy as one can check by
making a ContourPlot of the pressure in the uv-plane using a high number of
plot points.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/






From: Daniele Lupo [mailto:danwolf_no_spam_please_ at libero.it]
To: mathgroup at smc.vnet.net


Hi to everyone.

I've just obtained a Student License of Mathematica, and I'm working in
graphics...

I've created, after a half-day of work, an image representing an ellipsoid,
with a colored surface

When I try to represent it, I must put Ligthing->False to see surface
colors.

I'd like to know if there's a way to obtain a rendered image, in which I
can have both light and surface color, to give a shadow to the figure and
create a more 3D effect.

Thanks for replies.

Below there's the code...


Daniele


--------------------------

<< Graphics`ContourPlot3D`;

a = 7; b = 5; c = 4; r = 1;

ellipsoid = ContourPlot3D[
    (x/a)^2 + (y/b)^2 + (z/c)^2 - r, {
    x, -10, 10}, {y, -10, 10}, {z, -10, 10},
    PlotPoints -> 12,
    AspectRatio -> Automatic
    ];

(*It finds the median point of vertices of a list of a 3D coordinates*)
midpoint[l_] := Apply[Plus, Transpose[l], 2]/Length[l];


(*Function to map in the ellipsoid surface*)
pressure[x_, y_, z_] := x^2 + y^2 + Sin[4z];

(*Color Function*)
color[x_] := Hue[pressure @@ midpoint[x]/50];

(*Rule to change original graphic object*)
colorpolygon = Polygon[coord_] :>
{color[coord],EdgeForm[{}],Polygon[coord]};

(*creation of new, colored ellipsoid*)
coloredellipse = ellipsoid /. colorpolygon;

(*Visualization of the shape*)
(*I'd like to have also the light...*)
Show[coloredellipse, Lighting -> False];



  • Prev by Date: Enhancements to special functions in Version 5.2
  • Next by Date: Re: D[...] change in 5.1
  • Previous by thread: Re: Light and surface colors
  • Next by thread: Re: Light and surface colors