(*:Version: Mathematica 2.0 *) (*:Name: ListToArray` *) (*:Title: ListToArray *) (*:Author: Jason F. Harris *) (*:Keywords: Array, 3D graphics, ListSurfacePlot3D, ListPlot3D, ListShadowPlot3D, BarChart3D, ListContourPlot, ListDensityPlot, Interfaciing, GENPLOT *) (*:Requirements: *) (*:Warnings: For further use of the output of ListToArray the input points must lie on a regular rectangular grid in the x-y plane, otherwise the Mathematica functions requiring arrays will not work with this output. *) (*:Source: motivated by questions from John Lane, Motorola DSP Division PCMedia Operation jlane@what.sps.mot.com *) (*:Limitations: none. *) (*:Discussion: This function is useful for 3D graphics interfacing. Certain Mathematica graphing functions require their data to be in the form of a array of 3D points. ListToArray will transform a list of 3D points in any order into a sorted structured array of 3D points valid for ListSurfacePlot3D, ListPlot3D, ListShadowPlot3D, BarChart3D, ListContourPlot, ListDensityPlot and other Mathematica Graphing functions. If the points do not lie on a regular rectangular grid one may use the function TriangularSurfacePlot in the package DiscreteMath`ComputationalGeometry` but this is MUCH MUCH slower. *) (* :Implementation: ListToArray first sorts the points into the right order. It then reforms the List of points into the List of Lists of points that is the array. *) (* :Examples: This example assumes that the datafile contains data in the form x1 y1 z1 x2 y2 z2 x3 y3 z3 etc ... with no particular ordering on the xi's or yi's and returns anywhere. ReadList["datafile",{Number,Number,Number}]; arrayData = ListToArray[data]; ListSurfacePlot3D[arrayData]; *) BeginPackage["ListToArray`"]; ListToArray::usage = "ListToArray[{{x1,y1,z1},{x2,y2,z2},...}] will transform a list of 3D points into a sorted structured array needed for certain 3D graphing functions in Mathematica."; Begin["`Private`"]; ListToArray[a_List]:= reform[gridSort[a]] (*-------------------------------*) (* These two functions will sort the list into the order of an array *) myPredicate[{x1_,y1_,z1_},{x2_,y2_,z2_}]:= (x1x]]]; Print[xValues]; Map[(Cases[a,{#,y_,z_}])&,xValues]] (*-------------------------------*) End[]; (* ListToArray`Private` *) Protect[ListToArray]; EndPackage[]; (* ListToArray` *)