- #1

FiberOptix

- 12

- 0

Code:

```
typedef struct _galaxy{
char Name[12];
double RA, DE;
double D;
} galaxy;
double separation (galaxy gal1, galaxy gal2)
{
// convert from eq coords to Cartesian
double x1 = gal1.D * cos(gal1.DE * DEG_TO_RAD) * cos(gal1.RA * DEG_TO_RAD);
double x2 = gal2.D * cos(gal2.DE * DEG_TO_RAD) * cos(gal2.RA * DEG_TO_RAD);
double y1 = gal1.D * cos(gal1.DE * DEG_TO_RAD) * sin(gal1.RA * DEG_TO_RAD);
double y2 = gal2.D * cos(gal2.DE * DEG_TO_RAD) * sin(gal2.RA * DEG_TO_RAD);
double z1 = gal1.D * sin(gal1.DE * DEG_TO_RAD);
double z2 = gal2.D * sin(gal2.DE * DEG_TO_RAD);
// compute 3d separation
double out = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1) );
return out;
}
double proj_separation(galaxy gal1, galaxy gal2)
{
double dDE = ( gal1.DE - gal2.DE ) * DEG_TO_RAD;
double dRA = ( gal1.RA - gal2.RA ) * DEG_TO_RAD;
// calculate projected separation of galaxy 2 at the distance of galaxy 1 (Haversine)
double out = gal1.D * ( 2.0 * asin(
sqrt( ( sin( dDE/2.0 ) * sin( dDE/2.0 ) )
+ ( cos( gal1.DE * DEG_TO_RAD )
* cos( gal2.DE * DEG_TO_RAD )
* sin( dRA / 2.0 )
* sin( dRA / 2.0 )
) ) ) ) ;
return out;
}
```