(*^ ::[ frontEndVersion = "Macintosh Mathematica Notebook Front End Version 2.1"; macintoshStandardFontEncoding; paletteColors = 128; automaticGrouping; currentKernel; fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e8, 24, "Times"; ; fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e6, 18, "Times"; ; fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, e6, 14, "Times"; ; fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, a20, 18, "Times"; ; fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, a15, 14, "Times"; ; fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, a12, 12, "Times"; ; fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; ; fontset = input, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L-5, 12, "Courier"; ; fontset = output, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5, 12, "Courier"; ; fontset = message, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, R65535, L-5, 12, "Courier"; ; fontset = print, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5, 12, "Courier"; ; fontset = info, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, B65535, L-5, 12, "Courier"; ; fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, 12, "Courier"; ; fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, 10, "Geneva"; ; fontset = header, inactive, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = leftheader, inactive, L2, 12, "Times"; ; fontset = footer, inactive, noKeepOnOnePage, preserveAspect, center, M7, 12, "Times"; ; fontset = leftfooter, inactive, L2, 12, "Times"; ; fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; ; fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; ] :[font = special1; inactive; preserveAspect; ] Lighting and Three Dimensional Graphics This notebook will enable you to reproduce pictures like the ones drawn by the Java applets you've already looked at. The Java applets work with a sphere but later you will be able to use Mathematica and a little more mathematics to work with other surfaces -- for example, saddles and cones. The cell below is the most important cell in this notebook. This is the cell that you will change to work with specular shading rather than Lambertian shading and to work with three different colored light sources rather than one white light source.. This cell is a function that defines the shading of one point P = (x, y) on the sphere when the light is coming from the direction V = (vx, vy, vz) The vector V must be a unit vector and the vector P must have length less than or equal to 1. Before going on, look at this cell and understand what it is doing mathematically -- that is, how the shading is determined mathematically. Recall that colors are specified using RGBColor by three real numbers between zero and one that specify the intensity of red, green, and blue. For a monochromatic image all three numbers will be equal -- (0, 0, 0) represents black and (1, 1, 1) represents white. Now after you understand the mathematics in this cell evaluate it. ;[s] 16:0,1;68,0;259,3;270,0;746,1;757,0;879,1;896,0;911,1;912,0;950,1;951,0;1177,1;1185,0;1406,2;1472,0;1474,-1; 4:8,13,9,Times,0,12,0,0,0;6,13,9,Times,1,12,0,0,0;1,13,9,Times,1,12,65535,0,0;1,13,9,Times,2,12,0,0,0; :[font = input; preserveAspect; backColorRed = 43690; backColorGreen = 43690; backColorBlue = 43690; ] ColorAt[x_, y_] := Block[{z, dotprod, intensity}, z := Sqrt[1 - x*x - y*y]; intensity := N[x * vx + y * vy + z * vz]; RGBColor[intensity, intensity, intensity] ] :[font = special1; inactive; preserveAspect; ] The next cell draws the sphere with Lambertian shading. There are several parameters that you can change. vx and vy -- the two parameters that define the x and y coordinates of the direction from which the light is coming. The cell computes the z coordinate vz using the fact that the vector V must be a unit vector. n -- the number of rows and columns in the image of the sphere. When n is fairly big (25 in the original cell) the quality of the image is fairly good but the cell can take a long time to evaluate. When you are experimenting with changes you may want to set n to a smaller number -- perhaps 10 -- in the interests of speed. Then when you are want to look at a higher quality image you can set it back to 25. For an even higher quality image or if your computer is very fast you might try setting n to 50. Evaluate the following cell now. ;[s] 23:0,0;108,1;117,0;156,1;157,0;162,1;163,0;248,1;249,0;261,1;263,0;295,1;296,0;321,1;322,0;391,1;392,0;581,1;582,0;821,1;822,0;830,2;863,0;866,-1; 3:12,13,9,Times,0,12,0,0,0;10,13,9,Times,1,12,0,0,0;1,13,9,Times,1,12,65535,0,0; :[font = input; preserveAspect; ] Clear[Image, Shade, vx, vy, vz, n] vx := 0.0 (* x-coordinate of light source *) vy := 0.0 (* y-coordinate of light source *) vz := Sqrt[1 - vx * vx - vy * vy] (* z-coordinate *) n := 25 Shade[x_, y_] := If[x*x + y*y >= 1.0, RGBColor[0, 0, 0], ColorAt[x, y]] Image = Table[ Table[{Shade[x/n, y/n], Rectangle[{(x - 0.5)/n, (y - 0.5)/n}, {(x + 0.5)/n, (y + 0.5)/n}]}, {x, -n, n}], {y, -n, n}]; Show[Graphics[Image], PlotRange -> {{-1, 1}, {-1, 1}}, AspectRatio -> Automatic, Axes -> False] :[font = special1; inactive; preserveAspect; backColorRed = 43690; backColorGreen = 43690; backColorBlue = 43690; ] You should try several experiments by modifying the cells above. Try the first two experiments first and then try additional experiments as you read through this module. 1. Move the single light source in the cell above around so that it illuminates the sphere from different directions. 2. Add some diffuse lighting so that every point on the sphere is shaded with a light gray in addition to the lighting from the bare bulbs above. Warning: The light level can't be above 1 for each color. 3. Try Lambertian reflection with three different light sources. 4. Try specular reflection with a single light source. 5. Try specular reflection with three different light sources. 6. Add some diffuse lighting so that every point on the sphere is shaded with a light gray in addition to the lighting from the bare bulbs above. ;[s] 3:0,0;440,1;498,0;837,-1; 2:2,13,9,Times,0,12,0,0,0;1,13,9,Times,1,12,0,0,0; ^*)