Sub Nil Space
Author : Lisa Hickok
Credits : Geoff & Katie

SzgLink Initialization
(Evaluate this first)

Evaluate the next 3 cells. Evaluate the input lines, which are the lines written in bold face.

$Version

SetDirectory[NotebookDirectory[]]
<<SzgLink`

"/b1/imath08/szgbin"

?SzgLink`*

Shapes construction

<<Mesh`

mesh=InitMesh["hand_73k"];
mhand=SimplifyMesh[mesh,Method->1000];

handw=GeometryPlot3D[RotationTransform[180 Degree,{0,0,1}][RotationTransform[90 Degree,{-1,0,0}][mhand]],Mesh->All];GeometryPlot3D[RotationTransform[180 Degree,{0,0,1}][RotationTransform[90 Degree,{-1,0,0}][mhand]],Mesh->All,ColorFunction->(Pink&)];

MathLink connections
(Evaluate this next)

Set CAVE application' s name.

$szgbin = "caveMathematica.exe";

Launch local exe CAVE application

$szglink=None;
$szglink=Install["C:\\aszgard\\szg\\VStudio8\\Release\\caveMathematica.exe"]

Launch remote TCPIP CAVE application

Ports and IP addresses (Evaluate the appropriate one of these 2nd).
Evaluate the first cell if running CaveMathematica on this computer.

(* IP address of the machine running Mathematica *)
machineip = "127.0.0.1"

machineip = "140.177.14.230"

(*Beckman*)
machineip="130.126.127.158"

(*Beckman Salami*)
machineip="130.126.127.47"

(*Beckman Salami (private subnet) *)
machineip="192.168.0.47"

(*Beckman Alice (Jim's Desktop*)
machineip="130.126.127.250"

Evaluate the next cell

(* Ports for Mathematica -> caveMathematica communication. Note port2 must be port1+1 (as a string). *)
port1 ="9996";
port2 = ToString[ToExpression[port1]+1];
(* Ports for caveMathematica -> Mathematica communication *)
masterport1 = ToString[ToExpression[port2]+1];
masterport2 = ToString[ToExpression[masterport1]+1];

Open MathLink connection in Listen Mode (Evaluate this 3rd).

$szglink = Install[port1<>"@"<>machineip<>","<>port2<>"@"<>machineip, LinkMode->Listen, LinkProtocol->"TCPIP"]

(* 

	Now on a console:
	./caveMathematica <ip_address> [<port>]
Or for a cluster:
 dex <virtual_computer> caveMathematica <ip_address> [<port>]
      (<ip_address> is the address of this computer that you evaluated above, <port> is optional, defaults to 9996).
*)

Now on a console :

  ./caveMathematica  < ip_address >  [< port >]
  
(< ip_address > is the address of this computer that you evaluated above, < port > is optional, defaults to 9996).

Now wait until simulator window appears

Cave imported functions

TableForm@Sort[LinkPatterns[$szglink]]

caveMathematica MathLink shared link (Evaluate this next).

CaveOpenSecondaryLink[" -linkconnect -linkprotocol tcpip -linkname "<>masterport1<>"@"<>machineip<>","<>masterport2<>"@"<>machineip]

$szgcavelink = LinkOpen[masterport1<>"@"<>machineip<>","<>masterport2<>"@"<>machineip,LinkMode->Listen, LinkProtocol->"TCPIP"]

MathLink`AddSharingLink[$szgcavelink,MathLink`AllowPreemptive->True]

(* Now press button 1 in caveMathematica to establish the mathlink connection. *)

Now press button 1 (normal mouse click)  in caveMathematica to establish
 the mathlink connection.

??SzgLink`RenderSZG

Close caveMathematica and MathLink connections.
(* This currently causes caveMathematica.exe to crash or hang. Kill it _before_ evaluating this *)

If[$szgcavelink=!=None,LinkClose[$szgcavelink]]
Uninstall[$szglink]
$szglink=None;
$szgcavelink = None;

Applications

Sub Nil Space

The Nil circle
This notebook shows only the animation of the changing tangent planes as you traverse a circle in nil space

The circle is formed by taking a step of fixed length and then turning 
a fixed degree and taking another step along the new tangent plane

(*the degree you turn*)
θ = Pi/32;
(*the number of steps*)
iterations= 200;
(*the step size*)
stepSize  = .25;

(*The user should not change any of the code beyond this point*)
{x1,y1,z1} = {0.0,0,0};
point = {x1, y1,z1};
pointList = {point};
pointlist = {{{x1, y1},z1}};
u = {1,0, 0};
v = {0,1, 0};
v1 = {1,0,0};


For[i=0, i < iterations, i ++,
u = {1.0,0, 2*point[[2]]};
v = {0,1, -2*point[[1]]};
n = Cross[u,v];
n = n/Norm[n];
vtemp = ((v1 -(v1.n)*n)/Norm[(v1 -(v1.n)*n)])*Norm[v1];
v2 = vtemp*Cos[θ] + (Cross[n,vtemp])*Sin[θ];
newpoint = point + v2*stepSize;
pointList = Append[pointList, newpoint];
(*pointlist = Append[pointlist, {{newpoint[[1]], newpoint[[2]]},newpoint[[3]]}];*)
point = newpoint;
v1 =v2;]
clist = {};
For[i =1 , i<iterations, i++,
clist = Append[clist, {Pink, Cylinder[{pointList[[i]], pointList[[i+1]]},.5]}];
]
(*Graphics3D[clist,Axes->True,BoxRatios->{1,1,3},DisplayFunction:>((RenderSZG[#];#)&)]
Graphics3D[clist,Axes->True,BoxRatios->{1,1,3},DisplayFunction:>(RenderSZG[#]&)]*)

Animate[{f,g,h}=pointList[[i]];
u={1,0,2 g};
v={0,1,-2 f};
e=Cross[u,v];
{a,b,c}=e;
d=e.{f,g,h};
Show[Graphics3D[{Thick,Line[pointList]},BoxRatios->{1,1,3}, DisplayFunction:>((RenderSZG[#];#)&)],Plot3D[(-a/c)*x+(-b/c)*y+d/c,{x,-40,40},{y,-40,40},Mesh->{{{f, Thick}}, {{g,Thick}}},ColorFunction->"BrightBands",PlotRange->{pointList[[iterations]][[3]],0},BoxRatios->{1,1,3},ClippingStyle->None,DisplayFunction:>((RenderSZG[#];#)&)]] ,{i, 1,iterations,1},AnimationRate->.55]

Geodesic to a point on the z axis
evaluate the next 3 cells

CaveClearVariables[];
CaveFlyButtons[4,5,6]
CaveClearObject["FlyTrack"]

zcor = 10;
α = Sqrt[zcor/Pi];

x=α*Sin[t];
y=(α)*(-Cos[t]+1);
dz=.5*(x*D[y,t]-D[x,t]*y);
dz=TrigReduce[dz];
z=Integrate[dz,t];

path=ParametricPlot3D[{x,y,z},{t,0,2Pi},PlotRange->All,MaxRecursion->1,PlotPoints->15];
trackpath = Cases[path,a_Line:>a[[1]],Infinity][[1]];

CaveFlyPath[trackpath,{{}},{{}},{{}},60]

points = Table[{x,y,z}, {t, 0, 2*Pi, .01}];

track=ParametricPlot3D[{x,y,z},{t,0,2*Pi}, BoxRatios->{1,1,1},PlotStyle->Tube[{0.05,0.05}], ColorFunction->"BrightBands"]

FlyTrackSZG[track]

Animate[{f,g,h}= points[[i]];
u={1,0,-g/2};
v={0,1,f/2};
e=Cross[u,v];
{a,b,c}=e;
d=e.{f,g,h};
Show[Plot3D[(-a/c)*xx+(-b/c)*yy+d/c,{xx,-10,10},{yy,-10,10},PlotRange -> {-zcor, zcor}, Mesh->{{{f, Thick}}, {{g,Thick}}},BoxRatios->{1,1,1},ClippingStyle->None,ColorFunction->"DarkRainbow",DisplayFunction:>((RenderSZG[#];#)&)],ParametricPlot3D[{x,y,z},{t,0,2*Pi}, BoxRatios->{1,1,1},ColorFunction->"BrightBands",PlotRange->All]], {i, 1,2*Pi/.01,1},AnimationRate->.75]

Geodesic tube

CaveClearVariables[];
CaveFlyButtons[4,5,6]

x=1*Sin[t];
y=(1)*(-Cos[t]+1);
dz=.5*(x*D[y,t]-D[x,t]*y);
dz=TrigReduce[dz];
z=Integrate[dz,t];

path=ParametricPlot3D[{x,y,z},{t,0,2Pi},PlotRange->All,MaxRecursion->1,PlotPoints->15];
trackpath = Cases[path,a_Line:>a[[1]],Infinity][[1]];

CaveFlyPath[trackpath,{{}},{{}},{{}},60]


(*path=ParametricPlot3D[{x,y,z},{t,0,2*Pi}, BoxRatios->{1,1,1},PlotStyle->Tube[{0.05,0.05}], ColorFunction->"BlueGreenYellow",Mesh->10]
trackpath = Cases[path,a_Line:>a[[1]],Infinity][[1]];

CaveFlyPath[trackpath,{{}},{{}},{{}},15]*)
track=ParametricPlot3D[{x,y,z},{t,0,2*Pi}, BoxRatios->{1,1,1},PlotStyle->Tube[{0.05,0.05}], ColorFunction->"BlueGreenYellow",Mesh->10]

FlyTrackSZG[track]

Tangent Plane along the x-axis 
This function show how the tangent plane changes along the x axis

{f,g,h}={0,0,0};
Animate[u={1,0,2 g};
v={0,1,-2 f};
e=Cross[u,v];
{a,b,c}=e;
d=e.{f,g,h};
Plot3D[(-a/c)*x+(-b/c)*y+d/c,{x,-50,50},{y,-50,50},PlotRange->{-100,100},Mesh->{{{f, Thick}}, {{g,Thick}}},DisplayFunction:>((RenderSZG[#];#)&)] ,  {f, -50, 50,1}]

Tangent Plane along the y-axis 
This function show how the tangent plane changes along the y axis

{f,g,h}={0,0,0};
Animate[u={1,0,2 g};
v={0,1,-2 f};
e=Cross[u,v];
{a,b,c}=e;
d=e.{f,g,h};
Plot3D[(-a/c)*x+(-b/c)*y+d/c,{x,-50,50},{y,-50,50},PlotRange->{-100,100},Mesh->{{{f, Thick}}, {{g,Thick}}}, DisplayFunction:>((RenderSZG[#];#)&)], {g, -50,50,1}]

Tangent Plane along the z-axis 
This function show how the tangent plane changes along the z axis

{f,g,h}={0,0,0};
Animate[u={1,0,2 g};
v={0,1,-2 f};
e=Cross[u,v];
{a,b,c}=e;
d=e.{f,g,h};
Plot3D[(-a/c)*x+(-b/c)*y+d/c,{x,-50,50},{y,-50,50},PlotRange->{-100,100},Mesh->{{{f, Thick}}, {{g,Thick}}}DisplayFunction:>((RenderSZG[#];#)&)], {h, -50,50,1}]

Finding the tangent plane with sliders

(*Another example*)
(* CaveEvaluateButtons[up, down, select] *)
CaveEvaluateButtons[4,5,6]

szgg = 0;
szgf = 0;
szgh = 0;
CaveClearVariables[];
CaveAddVariable["szgg",0.,10.,0.1];
CaveAddVariable["szgf",0.,10.,0.1];
CaveAddVariable["szgh",0.,10.,0.1];

Slider[Dynamic[szgg] ,{-50,50}]
Slider[Dynamic[szgf] ,{-50,50}]
Slider[Dynamic[szgh] ,{-50,50}]

Dynamic[u={1,0,2 *szgg};
v={0,1,-2 *szgf};
e=Cross[u,v];
{a,b,c}=e;
d=e.{szgf,szgg,szgh};
Plot3D[(-a/c)*x+(-b/c)*y+d/c,{x,-50,50},{y,-50,50},PlotRange->{-100,100},PlotLabel-> {szgf,szgg,szgh},Mesh->None,ColorFunction->"RustTones", DisplayFunction:>((RenderSZG[#];#)&)]]

Lisa Hickok

Example 1.

<<Mesh`
Import["http://www.mathematicaguidebooks.org/V6/downloads/RiemannSurfacePlot3D.m"]

(*Trott shape #1*)
shape1=PolyhedronData["MathematicaPolyhedron"];
gc1=shape1[[1]];
Manipulate[RenderSZG[GeometryPlot3D[{gc1,Rotate[gc1,a,{0,0,1}]},ColorFunction->(RGBColor[#1,#2,0]&)]],{{a,0},-Pi/4,Pi/4,Pi/20}]

(*Trott shape #2*)
RenderSZG[GeometryPlot3D[Graphics3DMesh[RiemannSurfacePlot3D[w==(z^(1/3)),Re[w],{z,w}, ViewPoint->{-2.5,-2.2,0.8}]]]]

(*Trott shape #3*)
RenderSZG[GeometryPlot3D[Graphics3DMesh[RiemannSurfacePlot3D[w==(((1-(z^5)))^(1/5)),Im[w],{z,w},PlotPoints->{80,40}]]]]

(*Trott shape #4*)
RenderSZG[GeometryPlot3D[Graphics3DMesh[RiemannSheetParametricPlot3D[(( ArcCsc[(1+I)+z])/(Sqrt[z])),Re,{z,0,Pi},PlotPoints->60,
 ViewPoint->{0.73,-3.31,0.052}]]]]

(*example using GAP*)

Plot3D[Sin[x+Cos[y]],{x,-Pi,2Pi},{y,-Pi,Pi},PlotPoints->{10,10},MaxRecursion->1,Mesh->1,MeshFunctions->{"Gap"[0.8]},MeshShading->{None,Red},DisplayFunction:>(RenderSZG[#]&)]