IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ticket #593: coords2.c

File coords2.c, 1.9 KB (added by eugene, 21 years ago)

example for psProject

Line 
1
2int RD_to_XY (double *x, double *y, double ra, double dec, psProjection *proj) {
3
4 char *type;
5 int i, status, Polynomial, Zenith1, Zenith2, Zenithal, Cartesian, PseudoCyl;
6 double phi, theta;
7 double determ;
8 double X, Y, L, M, Lo, Mo, dL, dM;
9 double sphi, cphi, stht;
10 double salp, calp, sdel, cdel, sdp, cdp;
11 double P, A, Rc;
12
13 double Ro = proj->R;
14 double Do = proj->D;
15
16 PseudoCyl = (proj->type == PS_PROJ_AIT) || (proj->type == PS_PROJ_PAR) || (proj->type == PS_PROJ_GLS);
17 Zenith1 = (proj->type == PS_PROJ_TAN);
18 Zenith2 = (proj->type == PS_PROJ_SIN);
19 Zenithal = Zenith1 || Zenith2;
20 if (!Zenithal && !PseudoCyl) return (FALSE);
21
22 /**** Zenithal Projections ****/
23 if (Zenithal) {
24 sdp = sin(Do);
25 cdp = cos(Do);
26 salp = sin(ra - Ro);
27 calp = cos(ra - Ro);
28 sdel = sin(dec);
29 cdel = cos(dec);
30
31 stht = sdel*sdp + cdel*cdp*calp; /* sin(theta) */
32 sphi = cdel*salp; /* = cos(theta)*sin(phi) */
33 cphi = cdel*sdp*calp - sdel*cdp; /* = cos(theta)*cos(phi) */
34 if (stht < 0) status = FALSE;
35
36 if (Zenith1) {
37 L = sphi / stht;
38 M = -cphi / stht;
39 }
40 if (Zenith2) {
41 L = sphi;
42 M = -cphi;
43 }
44 }
45
46 /**** Other Standard Projections ****/
47 if (PseudoCyl) {
48 if (proj->type === PS_PROJ_AIT) {
49 phi = (ra - coords[0].crval1);
50 theta = (dec - coords[0].crval2);
51 P = 1.0 + cos (theta) * cos (0.5*phi);
52 if (P != 0.0) {
53 A = sqrt (2.0 / P);
54 L = 2.0 * A * cos (theta) * sin (0.5*phi);
55 M = A * sin (theta);
56 } else {
57 L = 0.0;
58 M = 0.0;
59 }
60 }
61 if (proj->type === PS_PROJ_GLS) {
62 phi = ra - Ro;
63 theta = dec - Do;
64 L = phi * cos(theta);
65 M = theta;
66 }
67 if (proj->type === PS_PROJ_PAR) {
68 phi = ra - Ro;
69 theta = dec - Do;
70 L = phi * (2.0*cos(2*theta/3.0) - 1);
71 M = 180.0 * sin (theta/3.0);
72 }
73 }
74
75 *x = X / proj->Xs;
76 *y = Y / proj->Ys;
77
78 return (status);
79}
80