MathGroup Archive 1997

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

Search the Archive

Re: Coloring Graphics.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9665] Re: Coloring Graphics.
  • From: "Xah" <xah at best.com>
  • Date: Fri, 21 Nov 1997 01:31:02 -0500
  • Organization: smtp.best.com
  • Sender: owner-wri-mathgroup at wolfram.com

In article <64gkei$2kg at smc.vnet.net>, phbrf at t-online.de (Peter Breitfeld)
wrote:
>I have a problem coloring my 3D - output.

I see a couple of questions on Mathematica graphics recently. I'll try
to give a one paragraph tutorial on Mathematica graphics.

Mathematica graphics consists of graphics primitives and graphics
directives. Example of graphics primitives are:
Point,Line,Circle,Disk,Polygon,Rectangle...etc. Examples of graphics
directives are: Thickness, AbsoluteThickness,
Dashing,Hue,RGBColor,EdgeForm,SurfaceColor...etc. Directives control
how primitves are rendered.

To couple a graphics directive to a primitive, you place the directive
in front of the primitive. For example, {Hue[0],Point[{0,0}]} will
colored the point red. A collection of graphics primitives makes up a
graphics object. The collection may or may not contain any directives.
Now, there are few types of graphics objects. Graphics is a graphics
object for 2-dimentional graphics, and has this format
Graphics[primitiveCollection,(options)]. The primitiveCollection is a
list of 2D graphics primitives possibliy mixed with directives. The
second argument is an optional List of options such as
{Axes->True,Background->Hue[0],...}. The 3 dimentional counterpart for
Graphics is Graphics3D, and has the same form
Graphics3D[primitives,(options)]. To display your graphics, you use
Show command. For example:
Show[Graphics[{Hue[0],PointSize[.02],Point[{0,0}]},Axes->True]]. Show
can accept a list of graphics for displaying multiple graphics, e.g.
Show[{Graphics[{Hue[0],PointSize[.02],Point[{0,0}]},Axes->True],
    Graphics[{Hue[.7],PointSize[.02],Point[{0,1}]},Axes->True]}].

This is the basics of building up 2D or 3D images in Mathematica. For
some of the build-in plotting commands such as Plot, ParametricPlot,
ParametricPlot3D, they buildup the graphics primitives collection
internally, then wrap the appropriate graphics object head (Graphics or
Graphics3D) with appropriate options as the second argument, and Show
them automatically. Their output is still the same old graphics object
(Graphics or Graphics3D).

Besides Graphics and Graphics3D, there are other types of graphics
objects in Mathematica. For example, we have
ContourGraphics,SurfaceGraphics,DensityGraphics. Basically, they are a
matrix of height values at grid points. This is so because surfaces of
functions can be so represented for efficiency reasons (i.e. because
there're never intersections). These graphics objects are returned by
ContourPlot, SurfacePlot, and DensityPlot respectively. If you want to
work with them as the general Mathematica graphics, you can convert
them into a list of graphics directives by attaching the head
Graphics3D. The result is then a Graphics3D object consisting of a list
of graphics primitives. Here's an example, (which is an solution to the
original questioner)

Clear[primitiveCollection1,primitiveCollection2]; primitiveCollection1=
  First at Graphics3D@
      Plot3D[Cos[x*y],{x,0,Pi},{y,0,Pi},DisplayFunction->Identity];
primitiveCollection2=
  First at Graphics3D@
      Plot3D[Sin[x*y],{x,0,Pi},{y,0,Pi},DisplayFunction->Identity];
Show at Graphics3D[{{SurfaceColor[Hue[0]],primitiveCollection1},{
        SurfaceColor[Hue[.7]],primitiveCollection2}},{
      AxesLabel->{"x","y","z"},LightSources->{{{1,1,1},GrayLevel[1]}}}];

For those who wishes to have complete understanding of Mathematica
graphics, I highly recommend Nancy Blackman and Smith Cameron's
Mathematica Graphics Guide Book. This book is written while Mathematica
v.2, but there is (essentially) no difference between Mathematica
graphics in v.2 and v.3.

 Xah, xah at best.com
 http://www.best.com/~xah/Wallpaper_dir/c0_WallPaper.html
 Mountain View, CA, USA


  • Prev by Date: RE: Named Commands list?
  • Next by Date: Re: How to remove an option?
  • Previous by thread: Coloring Graphics.
  • Next by thread: Hatching of a polygon