(*********************************************************************** This file was generated automatically by the Mathematica front end. It contains Initialization cells from a Notebook file, which typically will have the same name as this file except ending in ".nb" instead of ".m". This file is intended to be loaded into the Mathematica kernel using the package loading commands Get or Needs. Doing so is equivalent to using the Evaluate Initialiation Cells menu command in the front end. DO NOT EDIT THIS FILE. This entire file is regenerated automatically each time the parent Notebook file is saved in the Mathematica front end. Any changes you make to this file will be overwritten. ***********************************************************************) (* :Context: SaveToRotaterFormat` *) (* :Title: SaveToRotaterFormat *) (* :Author: Xah Lee *) (* : Copyright 1996-1997 by Xah Lee. Permission is hereby granted to make copies of this file for nonprofit purposes, provided this copyright notice is left intact. *) (* :Summary: This package is used for converting Mathematica graphics to a format that can be used by the real-time 3D visualization program Rotater that runs on MacOS or DOS/Windows. *) (* :Keywords: graphics, geometry, visualization, rotater, rotate.com *) (* :Mathematica Version: 2.2 *) (* :Package Version: 1.2, 1997 June*) (* :History: Version 1.2 19970600. Added an optional parameter for entering comments. Version 1.1 19961000. Added function ConcatenateFiles[]. Version 1.0 19960200. First published on WWW. *) (* :Sources: Mathematica Programming: Maeder, Roman: Programming In Mathematica, 2nd ed. chapter 1-3. Smith, Cameron; Blachman, Nancy: The Mathematica Graphics Guidebook. *) (* :Warning: *) (* :Limitations: *) (* :Discussion: This package is used for converting Mathematica graphics to a format that can be used by the real-time 3D visualization program Rotater that runs on MacOS or DOS/Windows. 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. If you have any questions regarding this package, I'll be happy to help out. As of 1997/09, 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 *) BeginPackage["SaveToRotaterFormat`"] SaveToRotaterFormat::usage = "SaveToRotaterFormat[ \"fileName\", graphicsData, commentString, (options)] will convert a graphicsData to Rotater format and save the result as a text file named fileName. graphicsData can be any of SurfaceGraphics, ContourGraphics, DensityGraphics, or Graphics3D objects. commentString is a string inserted literally into the beginning of the file. Remember that comments starts with \"#\". Options include: BoxRatios, ClosePolygon, ColorCode, and ExportPrecision. Each is documented on-line. Type ?name for more information. Example: Plot3D[ Cos[x] Cos[y], {x, -Pi, Pi}, {y, -Pi, Pi}]; SaveToRotaterFormat[ \"myGraphics.txt\", %]"; ColorCode::usage = "ColorCode is an option for SaveToRotaterFormat. ColorCode->n adds the integer n to each end of line. n must be an integer from -6 to 6 inclusive. See the documentation on Rotater file format for more information."; ExportPrecision::usage = "ExportPrecision is an option for SaveToRotaterFormat. ExportPrecision->n will write to the file with precision of n digits. n must be a positive integer."; ClosePolygon::usage = "ClosePolygon is an option for SaveToRotaterFormat. ClosePolygon->False will leave the last boundary of Polygon primitive open. This is sometimes desired since boundaries of neghboring polygons overlap in most graphics."; ConcatenateFiles::usage = " ConcatenateFiles[ listOfFileNames, newFileName] will create a new text file named newFileName in your current directory. The new file is listOfFileNames text files combined in the order given. The files to be combined must be place in your current directory"; Begin["`Private`"] ConcatenateFiles[ fileNames_List, newFileName_String] := Module[{}, OpenWrite[newFileName]; WriteString[ newFileName, StringJoin[ {ReadList[#, Record, RecordSeparators->{}],"\n"}& /@ fileNames ] ]; Close[newFileName] ] CuboidByLines::usage = "CuboidByLines[{xmin, ymin, zmin}] generate a list of Polygons that represents a unit cuboid, oriented parallel to the axes. CuboidByLines[{xmin, ymin, zmin}, {xmax, ymax, zmax}] specifies a cuboid by giving the coordinates of opposite corners. Example: Show@ Graphics3D[CuboidByLines[{1,1,1}] ]"; CuboidByLines[{x_,y_,z_}] := CuboidByLines[{x,y,z},{x+1,y+1,z+1}] CuboidByLines[{x_,y_,z_},{a_,b_,c_}] := { Line[{{x,y,z},{a,y,z},{a,y,c},{x,y,c},{x,y,z},{x,b,z},{a,b,z}, {a,b,c},{x,b,c},{x,b,z} }], Line[{{a,y,z},{a,b,z}}], Line[{{a,y,c},{a,b,c}}], Line[{{x,y,c},{x,b,c}}] } Off[General::spell] Options[saveSurfaceGraphics] = { BoxRatios->Automatic, ColorCode->-1, ExportPrecision->5}; (* this module works on data with head SurfaceGraphics, DensityGraphics, or ContourGraphics *) saveSurfaceGraphics[fileName_String, data_, comment_String, opts___Rule]:= Module[{xWidth, yWidth, zWidth, colorCode, eP, boxRatios, xBR, yBR, zBR, data2, xScale, yScale}, boxRatios = BoxRatios /. {opts} /. Options[saveSurfaceGraphics]; colorCode = ColorCode /. {opts} /. Options[saveSurfaceGraphics]; eP = ExportPrecision /. {opts} /. Options[saveSurfaceGraphics]; If[ boxRatios===Automatic, {xBR, yBR, zBR} = {2,2,1}, {xBR, yBR, zBR} = boxRatios ]; data2 = First@ data /. Complex[r_,_]->r; zWidth = N[ Max@ data2 - Min@ data2]; {yWidth, xWidth} = Dimensions@ data2-{1,1}; {xScale, yScale} = N[{xBR/xWidth,yBR/yWidth} (zWidth/zBR)]; data2 = N@ Table[ {j xScale, i yScale, Part[data2,i,j]}, {i, yWidth+1}, {j, xWidth+1} ]; data2 = SetPrecision[ Chop[ Flatten[ data2,1], 10^-(eP+1)], eP]; OpenWrite[fileName]; WriteString[fileName, comment]; WriteString[fileName, "\n\n#Converted from Mathematica\n"]; WriteString[fileName, "#by SaveToRotaterFormat.m\n"]; WriteString[fileName, "#Xah Lee. (xah@best.com)\n"]; WriteString[fileName, "#http://www.best.com/~xah/\n"]; WriteString[ fileName, StringReplace[ ToString@ NumberForm[data2, ExponentFunction->(If[-Infinity<# "", "}, " ->StringJoin[ " ", ToString@ colorCode," \n"], "}}" -> StringJoin[ " ", ToString@ colorCode," "], "," -> " " } ] ]; Close[fileName] ] On[General::spell] Options[saveGraphics3D] = { BoxRatios->Automatic, ColorCode->1, ClosePolygon->False, ExportPrecision->5}; (* This module works on data with head Graphics3D. *) saveGraphics3D[fileName_String, data_Graphics3D, comment_String, opts___Rule]:= Module[{xWidth, yWidth, zWidth, eP, colorCode, closePolygon, boxRatios, xBR, yBR, zBR, data2, xScale, yScale}, boxRatios = BoxRatios /. {opts} /. Options[saveGraphics3D]; colorCode = ColorCode /. {opts} /. Options[saveGraphics3D]; closePolygon = ClosePolygon /. {opts} /. Options[saveGraphics3D]; eP = ExportPrecision /. {opts} /. Options[saveGraphics3D]; data2 = First@ data /. {Complex[r_,_]->r, Cuboid->CuboidByLines}; If[ Not[boxRatios===Automatic], {xBR, yBR, zBR}=boxRatios; {xWidth, yWidth, zWidth} = (Max@ #- Min@ #)& /@ Transpose@ Cases[data2,{x_?AtomQ,y_?AtomQ,z_?AtomQ},-1]; {xScale, yScale} = N[{xBR/xWidth,yBR/yWidth} (zWidth/zBR)] ]; data2 = If[closePolygon, Cases[ data2, Polygon[__]|Line[__]|Point[__], -1] /. {Polygon[points_List]:> Join[Append[First@ points,0], Append[#,colorCode]&/@ (Rest@ points), Append[ First@ points,1] ], Line[points_List]:> Prepend[Append[#,Mod[colorCode,6]+1]&/@ (Rest@ points), Append[First@ points,0] ], Point[point_List]:> Append[point,-Abs@ colorCode] }, Cases[ data2, Polygon[__]|Line[__]|Point[__], -1] /. {Polygon[points_List]:> Prepend[ Append[#,colorCode]&/@ (Rest@ points), Append[First@ points,0] ], Line[points_List]:> Prepend[Append[#,Mod[colorCode,6]+1]&/@ (Rest@ points), Append[First@ points,0] ], Point[point_List]:> Append[point,-Abs@ colorCode] } ]; data2 = If[ boxRatios===Automatic, Partition[Flatten@ data2, 4], Partition[Flatten@ data2, 4]/.{x_,y_,z_,c_?AtomQ}-> {x xScale,y yScale,z,c} ]; data2 = SetPrecision[ Chop[ data2, 10^-(eP)], eP]; OpenWrite[fileName]; WriteString[fileName, comment]; WriteString[fileName, "\n\n#Converted from Mathematica\n"]; WriteString[fileName, "#by SaveToRotaterFormat.m\n"]; WriteString[fileName, "#Xah Lee. (xah@best.com)\n"]; WriteString[fileName, "#http://www.best.com/~xah/\n"]; WriteString[ fileName, StringReplace[ ToString@ NumberForm[data2, ExponentFunction->(If[-Infinity<# "", "}, " ->" \n", "}}" ->" ", "," -> " " } ] ]; Close[fileName] ] Options[SaveToRotaterFormat] = Union[ Options[saveGraphics3D], Options[saveSurfaceGraphics] ]; SaveToRotaterFormat[fileName_String, data_Graphics3D, comment_String:"#Converted from Mathematica", opts___Rule]:= saveGraphics3D[fileName, data, comment, opts] SaveToRotaterFormat[ fileName_String, data:(_SurfaceGraphics|_DensityGraphics|_ContourGraphics), comment_String:"#Converted from Mathematica", opts___Rule]:= saveSurfaceGraphics[fileName, data,comment, opts] End[] Protect[SaveToRotaterFormat, ConcatenateFiles]; EndPackage[]