#include <math.h>
#include <stdio.h>

/* Running the following code produces a J2000 to supergalactic
   coordinate matrix,  which looks as follows:

 0.37502632  0.34134742  0.86188004
 0.89831685  0.09572558 -0.42879302
 0.22887626 -0.93504556  0.27074980

   Written in reply to an inquiry from Christopher Watson;  see

http://groups.yahoo.com/group/amastro/message/13964
*/

#define PI 3.141592653589793238462643383279502884197169399375105820

#define ZERO_POINT_RA (2. + 49. / 60. + 14. / 3600.) * (PI / 12.)
#define ZERO_POINT_DEC (59. + 31. / 60. + 42. / 3600.) * (PI / 180.)
#define NORTH_POLE_RA (18. + 55. / 60. + 1. / 3600.) * (PI / 12.)
#define NORTH_POLE_DEC (15. + 42. / 60. + 32. / 3600.) * (PI / 180.)

static void vector_cross_product( double *c, const double *a, const double *b)
{
   c[0] = a[1] * b[2] - a[2] * b[1];
   c[1] = a[2] * b[0] - a[0] * b[2];
   c[2] = a[0] * b[1] - a[1] * b[0];
}

void main( int argc, char **argv)
{
   double matrix[9];

            /* vector pointing toward lat=lon=0: */
   matrix[0] = cos( ZERO_POINT_RA) * cos( ZERO_POINT_DEC);
   matrix[1] = sin( ZERO_POINT_RA) * cos( ZERO_POINT_DEC);
   matrix[2] = sin( ZERO_POINT_DEC);

            /* vector pointing toward the north supergalactic pole: */
   matrix[6] = cos( NORTH_POLE_RA) * cos( NORTH_POLE_DEC);
   matrix[7] = sin( NORTH_POLE_RA) * cos( NORTH_POLE_DEC);
   matrix[8] = sin( NORTH_POLE_DEC);

            /* take their cross-product to find a vector pointing to the */
            /* point lat=0, lon=90: */
   vector_cross_product( matrix + 3, matrix, matrix + 6);

   printf( "%11.8lf %11.8lf %11.8lf\n", matrix[0], matrix[1], matrix[2]);
   printf( "%11.8lf %11.8lf %11.8lf\n", matrix[3], matrix[4], matrix[5]);
   printf( "%11.8lf %11.8lf %11.8lf\n", matrix[6], matrix[7], matrix[8]);
}

/*
from http://www.daviddarling.info/encyclopedia/S/supergalactic_plane.html:

 The supergalactic plane is the reference plane for the system of
supergalactic coordinates, denoted by L (longitude) and B
(latitude). The zero point of supergalactic latitude and
longitude is set at R.A. 2h 49m 14s, Dec. +59° 31' 42",
and the supergalactic north pole is at R.A. 18h 55m 01s,
Dec. +15° 42' 32", (epoch 2000 coordinates).

http://www.brainyencyclopedia.com/encyclopedia/s/su/supergalactic_coordinate_system.html
gives a similar result

*/
