 # Griding Spherical 3D Data

QUESTION: My non-gridded, 3D data is specified by three equal-length vectors describing each point's location in spherical coordinates. I would like to grid this data to a regularly-space Cartesian coordinate system so that I can view the data with the SLICER program. How can I do this in IDL? ANSWER: You can convert your 3D data from spherical to rectangular coordinates with the CV_COORD command. Once in rectangular coordinates, you can grid the data with the GRID3 command. The resulting regularly-spaced data can be used as input to the SLICER program.

Here is an example program to show you how it is done. You can download the example by clicking here.

```   PRO EXAMPLE

; Create random data in spherical coordinates.

omega = !RaDeg * ASIN(-1.0 + 2.0*RANDOMU(seed, 100))
rho = RANDOMU(seed, 100) * 360.0
radius = RANDOMU(seed, 100)
value = COS(omega)^2/SIN(rho)^2

; Convert to retangular coordinates.

sphericalCoords = FLTARR(3,100)
sphericalCoords(0,*) = rho
sphericalCoords(1,*) = omega
sphericalCoords(2,*) = radius
rectCoords = CV_COORD(From_Sphere=sphericalCoords, /To_Rect, /Degrees)

; Grid the rectangular coordinates.

gridded = GRID3(rectCoords(0,*), rectCoords(1,*), rectCoords(2,*), value)
COMMON Volume_Data, xx
xx = gridded
SLICER
END
``` [Return to IDL Programming Tips]