Index: /trunk/psLib/src/astro/psCoord.c
===================================================================
--- /trunk/psLib/src/astro/psCoord.c	(revision 4612)
+++ /trunk/psLib/src/astro/psCoord.c	(revision 4613)
@@ -10,6 +10,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.80 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-07-20 01:21:13 $
+*  @version $Revision: 1.81 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-27 00:36:01 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -212,4 +212,17 @@
     psMemSetDeallocator(s, (psFreeFunc) sphereFree);
     return(s);
+}
+
+static void cubeFree(psCube *c)
+{
+    // There are non dynamic allocated items
+}
+
+psCube* psCubeAlloc(void)
+{
+    psCube *c = psAlloc(sizeof(psCube));
+
+    psMemSetDeallocator(c, (psFreeFunc) cubeFree);
+    return(c);
 }
 
@@ -1256,2 +1269,43 @@
     return(NULL);
 }
+
+psCube *psSphereToCube(const psSphere *sphere)
+{
+    if(sphere == NULL) {
+        //        psError();
+        return NULL;
+    }
+
+    psCube *cube = NULL;
+
+    cube = psCubeAlloc();
+    cube->x = cos(sphere->d) * cos(sphere->r);
+    cube->y = cos(sphere->d) * sin(sphere->r);
+    cube->z = sin(sphere->d);
+    cube->xErr = cos(sphere->dErr) * cos(sphere->rErr);
+    cube->yErr = cos(sphere->dErr) * sin(sphere->rErr);
+    cube->zErr = sin(sphere->dErr);
+
+    return(cube);
+}
+
+psSphere *psCubeToSphere(const psCube *cube)
+{
+    if(cube == NULL) {
+        //        psError();
+        return NULL;
+    }
+
+    psSphere *sphere = NULL;
+    sphere = psSphereAlloc();
+    //    sphere->r = arctan(cube->x/cube->y);
+    //    sphere->d = arctan(sqrt(cube->x*cube->x + cube->y*cube->y)/cube->z);
+    //    sphere->rErr = arctan(cube->xErr/cube->yErr);
+    //    sphere->dErr = arctan(sqrt(cube->xErr*cube->xErr + cube->yErr*cube->yErr)/cube->zErr);
+    sphere->r = 1 / (atan(cube->x/cube->y));
+    sphere->d = 1 / (atan(sqrt(cube->x*cube->x + cube->y*cube->y)/cube->z));
+    sphere->rErr = 1 / (atan(cube->xErr/cube->yErr));
+    sphere->dErr = 1 / (atan(sqrt(cube->xErr*cube->xErr + cube->yErr*cube->yErr)/cube->zErr));
+
+    return(sphere);
+}
Index: /trunk/psLib/src/astro/psCoord.h
===================================================================
--- /trunk/psLib/src/astro/psCoord.h	(revision 4612)
+++ /trunk/psLib/src/astro/psCoord.h	(revision 4613)
@@ -10,6 +10,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-07-20 01:21:13 $
+*  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-27 00:36:01 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -38,8 +38,8 @@
 typedef struct
 {
-    double x;                   ///< x position
-    double y;                   ///< y position
-    double xErr;                ///< Error in x position
-    double yErr;                ///< Error in y position
+    double x;                          ///< x position
+    double y;                          ///< y position
+    double xErr;                       ///< Error in x position
+    double yErr;                       ///< Error in y position
 }
 psPlane;
@@ -54,10 +54,28 @@
 typedef struct psSphere
 {
-    double r;                   ///< RA
-    double d;                   ///< Dec
-    double rErr;                ///< Error in RA
-    double dErr;                ///< Error in Dec
+    double r;                          ///< RA
+    double d;                          ///< Dec
+    double rErr;                       ///< Error in RA
+    double dErr;                       ///< Error in Dec
 }
 psSphere;
+
+/** 3-Dimensional Euclidean Coordinate System
+ *
+ *  Both detector and sky positions will be used extensively in the IPP. One
+ *  coordinate system to be used is cubic coordinates for which additional
+ *  care must often be taken in comparison to an angular coordinate system.
+ *
+ */
+typedef struct
+{
+    double x;                          ///< cos (DEC) cos (RA)
+    double y;                          ///< cos (DEC) sin (RA)
+    double z;                          ///< sin (DEC)
+    double xErr;                       ///< Error in x
+    double yErr;                       ///< Error in y
+    double zErr;                       ///< Error in z
+}
+psCube;
 
 /** 2D Polynomial Transform
@@ -71,6 +89,6 @@
 typedef struct
 {
-    psPolynomial2D* x;         ///< 2D polynomial transform of X coordinates
-    psPolynomial2D* y;         ///< 2D polynomial transform of Y coordinates
+    psPolynomial2D* x;                 ///< 2D polynomial transform of X coordinates
+    psPolynomial2D* y;                 ///< 2D polynomial transform of Y coordinates
 }
 psPlaneTransform;
@@ -90,6 +108,6 @@
 typedef struct
 {
-    psPolynomial4D* x;         ///< 4D polynomial transform of X coordinates
-    psPolynomial4D* y;         ///< 4D polynomial transform of Y coordinates
+    psPolynomial4D* x;                 ///< 4D polynomial transform of X coordinates
+    psPolynomial4D* y;                 ///< 4D polynomial transform of Y coordinates
 }
 psPlaneDistort;
@@ -120,12 +138,12 @@
  */
 typedef enum {
-    PS_PROJ_TAN,                ///< Tangent projection
-    PS_PROJ_SIN,                ///< Sine projection
-    PS_PROJ_AIT,                ///< Aitoff projection
-    PS_PROJ_PAR,                ///< Par projection
+    PS_PROJ_TAN,                       ///< Tangent projection
+    PS_PROJ_SIN,                       ///< Sine projection
+    PS_PROJ_AIT,                       ///< Aitoff projection
+    PS_PROJ_PAR,                       ///< Par projection
     //    PS_PROJ_GLS,                ///< GLS projection
     //    PS_PROJ_CAR,                ///< CAR projection
     //    PS_PROJ_MER,                ///< MER projection
-    PS_PROJ_NTYPE               ///< Number of types; must be last.
+    PS_PROJ_NTYPE                      ///< Number of types; must be last.
 } psProjectionType;
 
@@ -137,9 +155,9 @@
 typedef struct
 {
-    double R;                   ///< Coordinates of projection center
-    double D;                   ///< Coordinates of projection center
-    double Xs;                  ///< plate-scale in X direction
-    double Ys;                  ///< plate-scale in Y direction
-    psProjectionType type;      ///< Projection type
+    double R;                          ///< Coordinates of projection center
+    double D;                          ///< Coordinates of projection center
+    double Xs;                         ///< plate-scale in X direction
+    double Ys;                         ///< plate-scale in Y direction
+    psProjectionType type;             ///< Projection type
 }
 psProjection;
@@ -151,6 +169,6 @@
  */
 typedef enum {
-    PS_SPHERICAL,               ///< offset corresponds to an angular offset
-    PS_LINEAR                   ///< offset corresponds to a linear offset
+    PS_SPHERICAL,                      ///< offset corresponds to an angular offset
+    PS_LINEAR                          ///< offset corresponds to a linear offset
 } psSphereOffsetMode;
 
@@ -161,8 +179,8 @@
  */
 typedef enum {
-    PS_ARCSEC,                  ///< Arcseconds
-    PS_ARCMIN,                  ///< Arcminutes
-    PS_DEGREE,                  ///< Degrees
-    PS_RADIAN                   ///< Radians
+    PS_ARCSEC,                         ///< Arcseconds
+    PS_ARCMIN,                         ///< Arcminutes
+    PS_DEGREE,                         ///< Degrees
+    PS_RADIAN                          ///< Radians
 } psSphereOffsetUnit;
 
@@ -181,4 +199,9 @@
 psSphere* psSphereAlloc(void);
 
+/** Allocates a psCube
+ *
+ *  @return psCube*       resulting cube structure.
+ */
+psCube* psCubeAlloc(void);
 
 /** Allocates a psPlaneTransform transform.
@@ -233,7 +256,7 @@
 
 psSphereTransform* psSphereTransformAlloc(
-    double alphaP,                      ///< north pole latitude
-    double deltaP,                      ///< north pole longitude?
-    double phiP                         ///< defines the longitude in the input system of the equatorial intersection between the two systems (e.g, the first point of Ares).
+    double alphaP,                     ///< north pole latitude
+    double deltaP,                     ///< north pole longitude?
+    double phiP                        ///< defines the longitude in the input system of the equatorial intersection between the two systems (e.g, the first point of Ares).
 );
 
@@ -254,5 +277,5 @@
  */
 psSphereTransform* psSphereTransformICRSToEcliptic(
-    psTime *time                        ///< the time for which the resulting transform will be valid
+    psTime *time                       ///< the time for which the resulting transform will be valid
 );
 
@@ -263,5 +286,5 @@
  */
 psSphereTransform* psSphereTransformEclipticToICRS(
-    psTime *time                        ///< the time for which the resulting transform will be valid
+    psTime *time                       ///< the time for which the resulting transform will be valid
 );
 
@@ -283,8 +306,8 @@
  */
 psProjection* psProjectionAlloc(
-    double R,                   ///< Right-ascension of projection center.
-    double D,                   ///< Declination of projection center.
-    double Xs,                  ///< Scale in x-dimension
-    double Ys,                  ///< Scale in y-dimension
+    double R,                          ///< Right-ascension of projection center.
+    double D,                          ///< Declination of projection center.
+    double Xs,                         ///< Scale in x-dimension
+    double Ys,                         ///< Scale in y-dimension
     psProjectionType type
 );
@@ -361,5 +384,5 @@
 */
 psPlaneTransform *p_psPlaneTransformLinearInvert(
-    psPlaneTransform *transform        ///<    transform to invert
+    psPlaneTransform *transform        ///< transform to invert
 );
 
@@ -371,5 +394,5 @@
 */
 psS32 p_psIsProjectionLinear(
-    psPlaneTransform *transform        ///<     transform to test for linearity
+    psPlaneTransform *transform        ///< transform to test for linearity
 );
 
@@ -436,12 +459,29 @@
  */
 bool psPlaneTransformFit(
-    psPlaneTransform *trans,
-    const psArray *source,
-    const psArray *dest,
-    int nRejIter,
-    float sigmaClip
+    psPlaneTransform *trans,           ///< desired order, polynomial type, & polynomial mask terms
+    const psArray *source,             ///< coordinates matching those in dest
+    const psArray *dest,               ///< coordinates matching those in source
+    int nRejIter,                      ///< number of rejection iterations to be performed
+    float sigmaClip                    ///< coordinates above this number of standard deviations will be rejected
 );
 //XXX: need to add doxygen comments on the parameters above. -rdd
 
+/** Converts from a 3-dimensional coordinate system to an angular coordinate system.
+ *
+ *  @return psSphere*       The former psCube in terms of a psSphere.
+ */
+psSphere *psCubeToSphere(
+    const psCube *cube                 ///< psCube to convert
+);
+
+/** Converts from an angular coordinate system to a 3-dimensional coordinate system.
+ *
+ *  @return psCube*         The former psSphere in terms of a psCube.
+ */
+psCube *psSphereToCube(
+    const psSphere *sphere             ///< psSphere to convert
+);
+
+
 /// @}
 
