| 1 |
|
|---|
| 2 | int XY_to_RD (double *ra, double *dec, double x, double y, psProjection *proj) {
|
|---|
| 3 |
|
|---|
| 4 | double sphi, cphi, stht, ctht;
|
|---|
| 5 | double alpha, delta;
|
|---|
| 6 |
|
|---|
| 7 | double Ro = proj->R;
|
|---|
| 8 | double Do = proj->D;
|
|---|
| 9 |
|
|---|
| 10 | double L = x * proj->Xs;
|
|---|
| 11 | double M = y * proj->Ys;
|
|---|
| 12 |
|
|---|
| 13 | PseudoCyl = (proj->type == PS_PROJ_AIT) || (proj->type == PS_PROJ_PAR) || (proj->type == PS_PROJ_GLS);
|
|---|
| 14 | Zenith1 = (proj->type == PS_PROJ_TAN);
|
|---|
| 15 | Zenith2 = (proj->type == PS_PROJ_SIN);
|
|---|
| 16 | Zenithal = Zenith1 || Zenith2;
|
|---|
| 17 | if (!Zenithal && !PseudoCyl) return (FALSE);
|
|---|
| 18 |
|
|---|
| 19 | /**** Zenithal Projections ****/
|
|---|
| 20 | if (Zenithal) {
|
|---|
| 21 | double R = hypot (L,M);
|
|---|
| 22 | if ((L == 0) && (M == 0)) {
|
|---|
| 23 | sphi = 0;
|
|---|
| 24 | cphi = 1;
|
|---|
| 25 | } else {
|
|---|
| 26 | sphi = L / R;
|
|---|
| 27 | cphi = -M / R;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | if (Zenith1) {
|
|---|
| 31 | if (R == 0) {
|
|---|
| 32 | stht = 1.0;
|
|---|
| 33 | ctht = 0.0;
|
|---|
| 34 | } else {
|
|---|
| 35 | double T = 1.0 / R;
|
|---|
| 36 | stht = T / sqrt ( 1.0 + T*T);
|
|---|
| 37 | ctht = 1.0 / sqrt ( 1.0 + T*T);
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 | if (Zenith2) {
|
|---|
| 41 | ctht = R;
|
|---|
| 42 | stht = sqrt (1 - ctht*ctht);
|
|---|
| 43 | }
|
|---|
| 44 | if (!strcmp(type, "-ZEA")) {
|
|---|
| 45 | stht = 1 - 0.5*SQ(R);
|
|---|
| 46 | ctht = sqrt (1 - stht*stht);
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | double sdp = sin(Do);
|
|---|
| 50 | double cdp = cos(Do);
|
|---|
| 51 |
|
|---|
| 52 | double sdel = stht*sdp - ctht*cphi*cdp;
|
|---|
| 53 | double salp = ctht*sphi;
|
|---|
| 54 | double calp = stht*cdp + ctht*cphi*sdp;
|
|---|
| 55 | alpha = atan2 (salp, calp);
|
|---|
| 56 | delta = asin (sdel);
|
|---|
| 57 |
|
|---|
| 58 | *ra = alpha + Ro;
|
|---|
| 59 | *dec = delta;
|
|---|
| 60 | return (TRUE);
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | /**** Other Conventional Projections ****/
|
|---|
| 64 | if (PseudoCyl) {
|
|---|
| 65 | if (proj->type === PS_PROJ_AIT) {
|
|---|
| 66 | double Z2 = (1.0 - SQ(0.25*L) - SQ(0.5*M));
|
|---|
| 67 | if (Z2 < 0) return (FALSE);
|
|---|
| 68 |
|
|---|
| 69 | double Z = sqrt (Z2);
|
|---|
| 70 | alpha = 2.0 * atan2 (0.5*Z*L, 2.0*Z2 - 1.0);
|
|---|
| 71 | delta = asin (M*Z);
|
|---|
| 72 | }
|
|---|
| 73 | if (proj->type === PS_PROJ_GLS) {
|
|---|
| 74 | alpha = L / cos (M);
|
|---|
| 75 | delta = M;
|
|---|
| 76 | }
|
|---|
| 77 | if (proj->type === PS_PROJ_PAR) {
|
|---|
| 78 | alpha = L / (1.0 - SQ(2.0*M/M_PI));
|
|---|
| 79 | delta = 3 * asin (M/M_PI);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | *ra = alpha + Ro;
|
|---|
| 83 | *dec = delta + Do;
|
|---|
| 84 | return (TRUE);
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|