SaveToRotaterFormat.m
Usage Examples

Introduction

This is an example notebook for using the pagkage SaveToRotaterFormat.m.
The package is used for converting Mathematica graphics to a format that can be used by Rotater or rotate.com.

Rotater v.3.5 by Craig Kloeden is a real-time 3D visualization program for the Macintosh. A DOS/Windows version rotate.com is written by Marijke van Gans. These programs reads a simple ASCII file of coordinates, then you can rotate the 3D object in real-time using your mouse. Both program represents the 3D object by wireframe. They are fast and free.
The latest version of Rotater and rotate.com can be found at:
http://raru.adelaide.edu.au/rotater/
http://www.silicon-alley.com/cat/rotate.html

The Mathematica package SaveToRotaterFormat.m is written by me. It is free. I reserve the copyright. I wrote several other packages. You can find them on MathSource (http://www.mathsource.com) with search word "Xah", or on my web page.

I'd love to hear from you. As of 1997 May, I can be contact at

Xah Lee (xah@best.com)
http://www.best.com/~xah/SpecialPlaneCurves_dir/specialPlaneCurves.html
650 Alamo Court, Apt#1.
Mountain View, CA 94043
USA

Loading the package & On-line Documentation

Needs["SaveToRotaterFormat`"]

?SaveToRotaterFormat

To see all the options of SaveToRotaterFormat, use Options[].

Options[ SaveToRotaterFormat]

Examples

Plot3D, ContourPlot, and DensityPlot

Plot3D, ContourPlot, and DensityPlot return graphic data with head SurfaceGraphics, ContourGraphics, and DensityGraphics respectively. They all have identitical data structure, namely, they are two dimensional arrays. These will be converted to points in Rotater.

Plot3D[ Cos[x] Sin[y], {x, -Pi,Pi}, {y, -Pi, Pi}]
SaveToRotaterFormat["myGra.rot", %, "#Surface of Cos[y] Sin[y]"]

The file is save in your current directory. Existing file of the same name will be overwritten. To find out where is your current directory, use Directory[]. To set your current directory, use
SetDirectory[]. You can have Mathematica automatically set the current directory to a disired place by putting the command SetDirectory["diseredDirectory"] in the init.m file found in your Mathematica Directory. For more information about directories with Mathematica, see Mathematica by Stephen Wolfram 2nd ed. p.489.

To convert an SurfaceGraphics object to Rotater as wireframes, you need first wrap Graphics3D on the data to convert it to an Graphics3D object.

Graphics3D@ Plot3D[ Cos[x y], {x, 0,Pi}, {y, 0, Pi}]
SaveToRotaterFormat["cosWave.rot", %, "#Surface of Cos[x y]",
ClosePolygon->True]

SaveToRotaterFormat will handle graphics data with complex numbers or errors correctly, by discarding the bad data points. You can use BoxRatios option to scale the output graphic.

(*50 seconds*)
Plot3D[ Log[x y +1], {x, -Pi,Pi}, {y, -Pi, Pi},
	PlotPoints->{25,25}, Mesh->False, ColorFunction->(Hue[0,#,1]&)]

SaveToRotaterFormat["arch.rot", %, BoxRatios->{1,1,1}]

ContourGraphics data returned by ContourPlot will appear in Rotater as points.

ContourPlot[ Cos[x]-y^2, {x, -2 Pi, 2 Pi}, {y, -Pi, Pi}]
SaveToRotaterFormat[ "eyes.rot", %, "#testing testing"]

To export ContourGraphics as wireframes, you need to convert it to SurfaceGraphics data, then to Graphics3D data first.

Graphics3D@ SurfaceGraphics@ ContourPlot[ x y , {x,-5,5},{y,-5,5}]

SaveToRotaterFormat[ "hypePara.rot", %,
	"#hyperbolic paraboloid.\n#by Joe (joe@podunk.edu)\n",
	BoxRatios->{1,1,1}, ClosePolygon->True]

DensityGraphics returned by DensityPlot can also be exported.

DensityPlot[ Cos@x Sin@y, {x, - Pi, Pi}, {y, -Pi, Pi}]
SaveToRotaterFormat[ "wave.rot", %, "#a wave\n"]

Like ContourGraphics data, you can convert DensityGraphics to Graphics3D data by first converting it to SurfaceGraphics data.

(*30 seconds *)
Graphics3D@ SurfaceGraphics@ DensityPlot[
	E^(Sin[x] Cos[y]), {x,-Pi, Pi},{y,-Pi, Pi},
	PlotPoints->{20,20}
]

SaveToRotaterFormat[ "wave2.rot", %, "#One hell of a wave\n", ClosePolygon->True]

ParametricPlot3D

ParametricPlot3D returns Graphics3D object, which will be exported to Rotater as wireframes automatically.

ParametricPlot3D[
	{ Cos[t] Sin[x] , Sin[t] Cos[x] , t},
	{x,-Pi, Pi}, {t, -Pi, Pi}
]

SaveToRotaterFormat[ "candy.rot", %, "#ColorCode 4 used", ColorCode->4]

You can force it to export as dots by using ColorCode->n, where n is an integer and -6 <= n <= -1.

ParametricPlot3D[
	{Cos[t] (3+Cos[u]), Sin[t] (3+Cos[u]), Sin[u]},
	{t,0,2 Pi}, {u,0,2 Pi}
]

SaveToRotaterFormat[ "torus.rot", %, ColorCode->-2]

If ColorCode->n and n is a positive integer 1 <= n <= 6, a different color is used for the wireframe.

ParametricPlot3D[
	{ Log[x] Sin[t] , Cos[x] , t},
	{x,0.001,  2 Pi}, {t,  0.001,  2 Pi}
]

SaveToRotaterFormat[ "sSlider", %, ColorCode->3]

Other examples.

ParametricPlot3D[
	{ Sin[i] + Cos[j], Cos[i]+Sin[j] , i},
	{i,0,2 Pi},{j, -Pi, Pi}
]

SaveToRotaterFormat[ "spring", %, ColorCode->-5, BoxRatios->{1,1,2}]

(* award cup *)
ParametricPlot3D[
	{ Log[t] Sin[x] , Cos[x] , t},
	{x,0.001,  2 Pi}, {t,  0.001,  2 Pi}
]

SaveToRotaterFormat[ "awardcup", %, ColorCode->6]

Arbitrary Graphics3D data

Polyhedra

SaveToRotaterFormat will export arbitrary graphics data in Mathematica as long as they are legal Mathematica Graphic Primitives. Here are some examples using the package Polyhedra.

Needs["Graphics`Polyhedra`"]

?*Polyhedra`*

SaveToRotaterFormat["Icosahedron.rot", Graphics3D[Icosahedron[]], "#Icosahedron"]

SaveToRotaterFormat["stellatedDodeSphere.rot",
	Graphics3D[{ Stellate[ Dodecahedron[],4],
		Geodesate[Dodecahedron[],2]}
	],""
]

SaveToRotaterFormat["GreatDodecahedron.rot",
	Graphics3D[GreatDodecahedron[]]
]

SaveToRotaterFormat["Geo2GreatDodecahedron",
	Graphics3D[{Geodesate[ GreatDodecahedron[],2]}]
]

SaveToRotaterFormat["Geo4GreatDodecahedron",
	Graphics3D[{Geodesate[ GreatDodecahedron[],4]}]
]

OrthoSculpture

SaveToRotaterFormat can also export Cuboid graphic primitives. Let's use OrthoSculpture to demonstrate. (OrthoSculpture is a model that is to be looked through three perpendicular axis)

modelData[ planeGrid1_List, planeGrid2_List, planeGrid3_List] :=
	Module[{universe, model1, model2, model3, x, y, z, i, n},
		n = Max[planeGrid1, planeGrid2, planeGrid3];
		model1  = Table[ planeGrid1 /. {x_,y_}->{i,x,y}, {i,0,n}];
		model2  = Table[ planeGrid2 /. {x_,y_}->{x,i,y}, {i,0,n}];
		model3  = Table[ planeGrid3 /. {x_,y_}->{x,y,i}, {i,0,n}];
		model1 = Partition[ Flatten[model1],3];
		model2 = Partition[ Flatten[model2],3];
		model3 = Partition[ Flatten[model3],3];
		Intersection[ model1, model2, model3]
(*		universe = Table[{x,y,z},{x,0,n},{y,0,n},{z,0,n}];*)
(*		universe = Partition[ Flatten[universe],3]; *)
	]

Clear[ letterA, letterE, letterG, letterB , n ];
n = 10;

letterB =
	Union[
		Table[ {i,0}, {i, 0, n}],
		Table[ {i,n/2}, {i, 0, n}],
		Table[ {i,n}, {i ,0, n}],
		Table[ {0,i}, {i, 0, n}],
		Table[ {n,i}, {i, 0, n}]
	];

letterE = 
	Union[
		Table[ {i,0}, {i, 0, n}],
		Table[ {i,n/2}, {i, 0, n}],
		Table[ {i,n}, {i ,0, n}],
		Table[ {0,i}, {i, 0, n}]
	];

letterG =
	Union[
		Table[ {i,0}, {i, 0, n}],
		Table[ {i,n/2}, {i, Floor[n/2], n}],
		Table[ {i,n}, {i ,0, n}],
		Table[ {0,i}, {i, 0, n}],
		Table[ {n,i}, {i, 0, Floor[n/2] }]
	];

Show[ Graphics3D[ Cuboid/@ modelData[ letterE, letterG, letterB] ]]

SaveToRotaterFormat["GBE.rot", %, "#Godel, Bach, Echer Orthosculpture"]

Multi-Colors in Rotater

Rotater support six colors. (see the readme file in Rotater)
To generate one graphics with multi-color, you may convert your graphics 
to different files with different color, then combine them using ConcatenateFiles.

Graphics3D@ Plot3D[ Sin[x] Cos[y], 
	{x,-Pi .5, Pi .5},{y,-Pi .5, Pi .5} ]

SaveToRotaterFormat[ "waveRed.rot", %, ColorCode->1]

Graphics3D@ Plot3D[ Sin[y] Cos[x], 
	{x,-Pi .5, Pi .5},{y,-Pi .5, Pi .5} ]

SaveToRotaterFormat[ "waveBlue.rot", %, ColorCode->3]


ConcatenateFiles[{"waveRed.rot", "waveBlue.rot"}, "waveNew.rot" ]