Visualization Technology and Applications

Ulises Cervantes-Pimentel
Kernel Developer

Wolfram Research, Inc.

The objective of this presentation is to give a general overview of the technology involved in the implementation of the Mathematica 6.0 plotting functions. All the visualization functions have being reviewed and in most cases rewritten to incorporate state of the art algorithms in computational geometry, data analysis and 3D graphics mesh generation. We make use of the extraordinary tools in symbolic analysis that Mathematica offers to provide the new function and data visualization with unique features not found in any other algebraic computational system.

Adaptive Refinement

One of the most important improvements in V6.0 is the introduction of adaptive sampling. Based on geometric properties it is possible to obtain a more accurate function representation.

Manipulate[
Plot[Sin[x ], {x, 0,Pi},
Method -> {Refinement -> {"Dihedral", (70 - n) Degree}}, Mesh -> 
All,MeshStyle->{Red,PointSize[0.015]},PlotPoints->8], {n, 0, 70, 1}]

Manipulate[
Plot3D[Sin[x y], {x, 0, Pi}, {y, 0, Pi},
Method -> {Refinement -> {"Dihedral", (90 - n) Degree}}, Mesh -> 
All], {n, 0, 90, 1}]

Manipulate[
Plot3D[Sin[x y], {x, 0, Pi}, {y, 0, Pi},
Method -> {Refinement -> {"Dihedral", (90 - n) Degree,Automatic,"Quad"}}, Mesh -> 
All], {n, 0, 90, 1}]

<<NumericalMath`OrderStar`

fun=Exp[Cos[z]+I Cosh[z]];
approx=Pade[fun,{z,0,2,3}];
OrderStar[approx,fun,PlotRange->{{-5,5},{-5,5}},PlotPoints->40,OrderStarSubPlots->{},MaxRecursion->3,ImageSize->450,Mesh->None]

ParametricPlot3D[boysurface[u,v],{u,0,Pi},{v,0,Pi},Boxed->False,ViewPoint->{-1.369, 4.483, 1.824},AspectRatio->1,Axes->False,Mesh->All,ImageSize->400]

Piecewise plotting

Piecewise functions have being introduced in V5.1. With V6.0 we introduce support in plotting these special functions. Plot, Plot3D and ParametricPlot3D construct mesh representations for each component in the Piecewise expansion of a function.

Clear[x,y]
ComparePlot3D[f_, x_, y_, opts___]:=Grid[{{
Plot3D[f,x,y,opts],Plot3D[f,x,y,opts, Method->{}]}}]
ComparePlot[f_, x_, opts___]:=Grid[{{
Plot[f,x,opts, PlotStyle->{Red, Thickness[0.005]}],Plot[f,x,opts, Method->{},PlotStyle->{Red, Thickness[0.005]}]}}]

ComparePlot[Floor[2+Ceiling[1+Floor[x^2]]], {x, -5, 5}]

Do[Print[Plot[ Sin[i x] Sign[x-3] Sign[x-2.5] ,{x,2,4},Mesh->10,MaxRecursion->4,Filling->True, FillingStyle->RGBColor[0,1,0,0.2],MeshStyle->Blue]],{i,1,9,3}]

ComparePlot3D[E^Boole[x^2+y^2*Boole[y>0]<1], {x, -2, 2}, {y, -2, 2},Mesh->All]

ComparePlot3D[Abs[x*y]*Boole[x^2+y^2≤2^2],{x,-5,5},{y,-5,5}, PlotRange->All,BoundaryStyle->None]

ComparePlot3D[Sqrt[Abs[y - x^2]]*Boole[Inequality[x^2, LessEqual, y, Less, 4]], {x, -5, 5}, {y, -5, 5},BoundaryStyle->None]

Improved ContourPlot

For ContourPlot we extend the adaptivity to be applied to the contour lines, this has the advantage of producing smooth curves independently of the initial samping.

ContourPlot[Sin[x y],{x,0,3},{y,0,3},Mesh->All,Contours->3,ColorFunction->Hue]

Contour labels are being supported, automatic placement via a mini-max algorithm.

ContourPlot[Sin[2x ]Sin[2y],{x,-3,3},{y,-3,3},ContourLabels->Automatic]

ContourPlot[Sin[x y],{x,0,3},{y,0,3},ContourLabels->Automatic,ContourLabelsFunction->(Text[#1,#2,Background->Yellow]&)]

ContourPlot[Sin[x y], {x, 0, 1}, {y, 0, 1}, ContourLabels->Automatic, 
ContourLabelsFunction->(Tooltip[{Purple, PointSize[0.025],Point[#2]},#1]&),ColorFunction->Hue,Contours->15]

Region Function

All the new Visualization functions support clipping via an arbitrary function, which is called a RegionFunction. In particular RegionPlot and RegionPlot3D are capable of plotting 2D an 3D functions

cg=Plot[{Sin[x],Cos[x],Cos[3x+Pi/6]},{x,0,3Pi},PlotStyle->{{Dashing[{0.1,0.01}],RGBColor[1,0,0]},RGBColor[1,1,0],RGBColor[0,1,0]},MeshStyle->{{RGBColor[0,0,1]},{RGBColor[1,0,1]}},Mesh->5,Filling->True,FillingStyle->{{Opacity[0.4],RGBColor[1,0,0]},{Opacity[0.2],RGBColor[0,0,1]},{Opacity[0.4],RGBColor[1,1,0]}},MeshFunctions->{#2&},RegionFunction->Function[{x,y},(x>6 || x<5) && y≥-1.9]]

RegionPlot[Mod[Ceiling[x]+Ceiling[y],2]==0,{x,-3,3},{y,-3,3},Mesh->All]

RegionPlot[ Xor[ (((x+(1/2)))^2)+ (y^2)≤1, (((x-(1/2)))^2)+ (y^2)≤1], {x,-1.6,1.6}, {y,-1,1},Mesh->5]

Suport for trascendental functions.

RegionPlot[Sin[2 x] + Cos[3 y] >= 1,{x, -2 Pi, 2 Pi},{y, -2 Pi, 2 Pi},PlotPoints->30]

RegionPlot3D[(x^2+y^2+z^2>1 && +x+y-z<=2),{x,-1,1},{y,0,1},{z,-1,1},Boxed->False,ViewPoint->{1.58,-3.1,-1.49}]

Mesh Functions

Mesh overlaying is supported using arbitrary MeshFunctions. This extends the standar cartessian mesh lines.

DensityPlot[Sin[x + Cos[y]],{x,0,2Pi},{y,0,2Pi},ColorFunction->(RGBColor[#,#,0]&),Mesh->5,MeshStyle->{{Blue},{Magenta}}]

DensityPlot[Sin[x + Cos[y]],{x,0,2Pi},{y,0,2Pi},ColorFunction->(RGBColor[#,#,0]&),Mesh->5,MeshStyle->{{Blue},{Magenta}},MeshFunctions->{#1-Sin[#2]&,#2-Sin[#1]&}]

Examples based on the book Modern Differential Geometry of Curves and Surfaces with Mathematica, by Alfred Gray.

$Path=Join[$Path,{"E:\\math\\CAS"}];
<<CAS.m

ParametricPlot3D[whitneyumbrella[u,v],{u,-1,1},{v,-1,1},PlotRange->All,Mesh->{10,15},MeshStyle->{{White},{Blue}}]

whg=ParametricPlot3D[whitneyumbrella[u,v],{u,-1,1},{v,-1,1},PlotRange->All,MeshFunctions->{gcurvature[whitneyumbrella][#4,#5]&},Mesh->{Table[t,{t,-1,0,0.1}]},PlotPoints->30,MeshShading->Table[{RGBColor[1-t,0,t,0.7]},{t,0,1,0.1}],BoundaryStyle->Black];

whm=ParametricPlot3D[whitneyumbrella[u,v],{u,-1,1},{v,-1,1},PlotRange->All,MeshFunctions->{mcurvature[whitneyumbrella][#4,#5]&},Mesh->{Table[t,{t,-1,1,0.1}]},PlotPoints->30,MeshShading->Table[{RGBColor[1-t,0,t,0.7]},{t,0,1,0.05}],BoundaryStyle->Black];

whk1=ParametricPlot3D[whitneyumbrella[u,v],{u,-1,1},{v,-1,1},PlotRange->All,MeshFunctions->{k1[whitneyumbrella][#4,#5]&},Mesh->{Table[t,{t,-1,1,0.1}]},PlotPoints->30,MeshShading->Table[{RGBColor[1-t,0,t,0.7]},{t,0,1,0.05}],BoundaryStyle->Black];

whk2=ParametricPlot3D[whitneyumbrella[u,v],{u,-1,1},{v,-1,1},PlotRange->All,MeshFunctions->{k2[whitneyumbrella][#4,#5]&},Mesh->{Table[t,{t,-1,1,0.1}]},PlotPoints->30,MeshShading->Table[{RGBColor[1-t,0,t,0.7]},{t,0,1,0.05}],BoundaryStyle->Black];

Grid[{{whg,whm},{whk1,whk2}}]

mog=ParametricPlot3D[monkeysaddle[u,v],{u,-Pi/2,Pi/2},{v,-Pi/2,Pi/2},MeshFunctions->{gcurvature[monkeysaddle][#4,#5]&},Mesh->9,PlotPoints->40,PlotRange->{-1.5,1.5},MeshShading->Table[{RGBColor[1-t,0,t,0.7]},{t,0,0.9,0.1}]];

mom=ParametricPlot3D[monkeysaddle[u,v],{u,-Pi/2,Pi/2},{v,-Pi/2,Pi/2},MeshFunctions->{mcurvature[monkeysaddle][#4,#5]&},Mesh->9,PlotPoints->40,PlotRange->{-1.5,1.5},MeshShading->Table[{RGBColor[1-t,0,t,0.7]},{t,0,0.9,0.1}]];

mok1=ParametricPlot3D[monkeysaddle[u,v],{u,-Pi/2,Pi/2},{v,-Pi/2,Pi/2},MeshFunctions->{k1[monkeysaddle][#4,#5]&},Mesh->9,PlotPoints->40,PlotRange->{-1.5,1.5},MeshShading->Table[{RGBColor[1-t,0,t,0.7]},{t,0,0.9,0.1}]];

mok2=ParametricPlot3D[monkeysaddle[u,v],{u,-Pi/2,Pi/2},{v,-Pi/2,Pi/2},MeshFunctions->{k2[monkeysaddle][#4,#5]&},Mesh->9,PlotPoints->40,PlotRange->{-1.5,1.5},MeshShading->Table[{RGBColor[1-t,0,t,0.7]},{t,0,0.9,0.1}]];

Grid[{{mog,mom},{mok1,mok2}}]

Clear[tt,x,y,z,t]
t=7.5;
tt=x^2*Cos[x]+y^2*Cos[y]+z^2*Cos[z]+(37*Cos[t/5]+33)/2.;

Gaussian Curvature

K[x_,y_,z_]=Simplify[2 
(D[tt, x]*D[tt,y] *(D[tt,x,y]*D[tt,z,z] - D[tt,x,z]*D[tt,y,z]) +
D[tt, x]*D[tt,z] *(D[tt,x,z]*D[tt,y,y] - D[tt,x,y]*D[tt,y,z]) +
D[tt, y]*D[tt,z] *(D[tt,y,z]*D[tt,x,x] - D[tt,x,y]*D[tt,x,z])) -
D[tt, x]*D[tt,x] *(D[tt,y,y]*D[tt,z,z] - D[tt,y,z]*D[tt,y,z]) -
D[tt, y]*D[tt,y] *(D[tt,x,x]*D[tt,z,z] - D[tt,x,z]*D[tt,x,z]) -
D[tt, z]*D[tt,z] *(D[tt,x,x]*D[tt,y,y] - D[tt,x,y]*D[tt,x,y])] /
(-(D[tt,x]*D[tt,x]+D[tt,y]*D[tt,y]+D[tt,z]*D[tt,z])^2)

ContourPlot3D[tt,{x,-5,5},{y,-5,5},{z,-5,5},PlotPoints->48,Contours->{0.0},Mesh->6,MeshStyle->Black,MeshFunctions->(K[#1,#2,#3]&),MeshShading->Table[{RGBColor[1,t,0,0.7]},{t,0,1,0.17}]]

Mesh Shading

boysurface[u_,v_]={(1/2) Sin[v] (((Cos[u])^2) ((Cos[v])^2) Sin[v]+((Cos[u])^4) ((Sin[v])^3)+((Cos[u])^3) ((Sin[v])^2) (Cos[v]-Sin[u] Sin[v])+Cos[u] (-((Cos[v])^3)+((Sin[u])^3) ((Sin[v])^3))-Sin[u] (2 ((Cos[v])^3)+((Cos[v])^2) Sin[u] Sin[v]-2 Cos[v] ((Sin[u])^2) ((Sin[v])^2)+((Sin[u])^3) ((Sin[v])^3))),-(1/2) (Sqrt[3]) (((Cos[v])^4)-Cos[u] ((Cos[v])^3) Sin[v]+((Cos[u ])^2) ((Cos[v])^2) ((Sin[v])^2)+((Cos[u])^3) Cos[v] ((Sin[v])^3)+(1/4) (-2+2 Cos[2 u]+Sin[4 u]) ((Sin[v])^4)),(1/8) (Cos[v]+(Cos[u]+Sin[u]) Sin[v]) (4 (Cos[u]-Sin[u]) Sin[v] (Cos[v]-Cos[u] Sin[v]) (Cos[v]-Sin[u] Sin[v])+(((Cos[v]+(Cos[u]+Sin[u]) Sin[v]))^3))};

ParametricPlot3D[boysurface[u,v],{u,0,Pi},{v,0,Pi},Boxed->False,ViewPoint->{-1.369, 4.483, 1.824},AspectRatio->1,Axes->False,Mesh->5,ImageSize->400,MaxRecursion->3,MeshShading->{{SurfaceColor[Red],SurfaceColor[Blue]},{SurfaceColor[Green],SurfaceColor[Yellow]}}]

Clear[r, KleinBottle]
r[u_]:=4(1-Cos[u]/2);
KleinBottle[u_/; u≤Pi , v_]:={
6 Cos[u](1+Sin[u])+r[u] Cos[u] Cos[v],
16 Sin[u] + r[u] Sin[u] Cos[v],
r [u] Sin[v]
	}
KleinBottle[u_ /; u>Pi,v_]:={
6 Cos[u] (1 + Sin[u])+ r[u] Cos[v+Pi],
16 Sin[u],
r[u] Sin[v]
}

ParametricPlot3D[KleinBottle[u,v],{u,0,2 Pi},{v,0,2 Pi},ViewPoint->{-2,-8,-15},Boxed->False,Axes->False, MaxRecursion->3,Mesh->{5,10},ImageSize->400,MeshShading->{{SurfaceColor[Red],SurfaceColor[Blue]},{SurfaceColor[Green],SurfaceColor[Yellow]}}]

ListPlot3D

Irregular data support

d = Table[{x = 3 Random[]-1.5,y = 3 Random[]-1.5, Exp[-Sqrt[x^2+y^2]]},{200}];

ListPlot3D[d]

ListPlot3D[d,RegionFunction->(#1^2+#2^2<2&),PlotRange->All]

ListPlot3D[d,MaxPlotPoints->11,Mesh->All]

ContourPlot3D

ContourPlot3D is a native function in V6.0. Highly improved for speed and handling of multiple surfaces.

tubes[x_,y_,z_]:=(x^2+y^2-144)((x-20)^2+z^2-64)

ContourPlot3D[tubes[x,y,z],{x,-15,30},{y,-30,30},{z,-25,25},Contours->{10000},Mesh->All,ContourStyle->Automatic,NormalsFunction->Automatic]

ContourPlot3D[x^2+y^2+z^2,{x,-1,1},{y,-1,1},{z,-1,1},Boxed->False,Axes->False,Contours->4,ContourStyle->{{RGBColor[1,0,0,0.7]},{RGBColor[1,1,0,0.7]},{RGBColor[0,1,0,0.7]},{RGBColor[0,0,1,0.7]}},Mesh->5]

ContourPlot3D[x^2+y^2-z^2,{x,-1,0},{y,-1,1},{z,-1,1},ContourShading->{SurfaceColor[Red],SurfaceColor[Yellow],SurfaceColor[Green],SurfaceColor[Blue]},Mesh->None,ImageSize->500,Contours->10,PlotPoints->25]

ContourPlot3D[x^2+y^2-z^2,{x,-1,0},{y,-1,1},{z,-1,1},ContourStyle->{{SurfaceColor[Yellow],Thickness[0.04]}},Mesh->None]

Smooth shading via geometric or analytic vertex normal computation.

ClebschSurf=16 (x^3)+16 (y^3)-31 (z^3)+24 (x^2) z-48 (x^2) y-48 x (y^2)+24 (y^2) z-54 (Sqrt[3]) (z^2)-72 z;

clebschgr=ContourPlot3D[ClebschSurf,{x,-2.5,2.5},{y,-2.5,2.5},{z,-2.5,2.5},Contours->{1},Mesh->None,PlotPoints->50,ContourStyle->{{SurfaceColor[RGBColor[.6,.4,.1],White,200]}},Background->Black,Boxed->False,Axes->False,ImageSize->500,ViewPoint->{2.043,-2.684,0.262},NormalsFunction->Function[{x,y,z},{48 (x^2)-96 x y-48 (y^2)+48 x z,-48 (x^2)-96 x y+48 (y^2)+48 y z,-72+24 (x^2)+24 (y^2)-108 (Sqrt[3]) z-93 (z^2)}],SphericalRegion->True,Mesh->All]

Summary

SetOptions[InputNotebook[],
"NotebookRenderingEngine"->"Automatic",
"CacheGraphics"->True]

Conclusions

SetOptions[InputNotebook[],
"NotebookRenderingEngine"->"Automatic",
"CacheGraphics"->True]