IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 26, 2004, 7:28:05 PM (22 years ago)
Author:
gusciora
Message:

...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astronomy/psCoord.c

    r1293 r1296  
    1010 *  @author George Gusciora, MHPCC
    1111 *
    12  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-07-24 02:42:59 $
     12 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-07-27 05:28:05 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2626#include <float.h>
    2727
     28// This is the only function in this file which I understand.
    2829psPlane *psPlaneTransformApply(psPlane *out,
    2930                               const psPlaneTransform *transform,
     
    7273
    7374
    74 psSphereTransform *psSphereTransformAlloc(double NPlon,
    75         double NPlat,
    76         double ZP)
     75psSphereTransform *psSphereTransformAlloc(double NPlat,
     76        double Xo,
     77        double xo)
    7778{
    7879    psSphereTransform *tmp = (psSphereTransform *) psAlloc(sizeof(psSphereTransform));
    7980
    80     tmp->sinNPlon = sin(NPlon);
    81     tmp->cosNPlon = cos(NPlon);
    82     tmp->sinNPlat = sin(NPlat);
    83     tmp->cosNPlat = cos(NPlat);
    84     tmp->sinZP = sin(ZP);
    85     tmp->cosZP = cos(ZP);
     81    tmp->sinPhi = sin(NPlat);
     82    tmp->cosPhi = cos(NPlat);
     83    tmp->Xo = Xo;
     84    tmp->xo = xo;
    8685
    8786    return(tmp);
    8887}
    8988
    90 
     89// I understand this one too.
    9190void p_psSphereTransformFree(psSphereTransform *trans)
    9291{
     
    9594
    9695
    97 
     96// XXX: I have no idea how this works.  This algorithm comes from an email
     97// from Gene.  I assume (x,y) corresponds to (r,d) in the sphere coordinates.
     98
     99// XXX: In Gene's email, there are different variables with similar names
     100// (y and Y) and in the code, there's cos_y, cos_Y, and cos(y).  Verify that
     101// there are no typo's.
    98102
    99103psSphere *psSphereTransformApply(psSphere *out,
     
    101105                                 const psSphere *coord)
    102106{
    103     return(NULL);
    104 }
    105 
    106 
     107    double sinY = 0.0;
     108    ;
     109    double cosY = 0.0;
     110    ;
     111    double sinX = 0.0;
     112    ;
     113    double cosX = 0.0;
     114    ;
     115    double x = 0.0;
     116    double y = 0.0;
     117    double dx = 0.0;
     118
     119    if (out == NULL) {
     120        out = (psSphere *) psAlloc(sizeof(psSphere));
     121    }
     122
     123    x = coord->r;
     124    y = coord->d;
     125    dx    = x - transform->xo;
     126    sinY = cos(y)*sin(dx)*transform->sinPhi + sin(y)*transform->cosPhi;
     127    cosY = sqrt(1.0 - sinY*sinY);
     128    sinX = (cos(y)*sin(dx)*transform->cosPhi - sin(y)*transform->sinPhi) /
     129           cos(y);
     130    cosX = cos(y)*cos(dx) / cos(y);
     131
     132    out->r = atan2(sinX, cosX) + transform->Xo;
     133    out->d = atan2(sinY, cosY);
     134
     135    return(out);
     136}
     137
     138// XXX: Add a date argument to determine the correct year.
    107139psSphereTransform *psSphereTransformICRStoEcliptic(void)
    108140{
    109     // sla_EQECL();
    110     return(NULL);
    111 }
    112 
     141    double year = 2004.0;
     142    double T = year / 100.0;
     143    double phi = -23.452294 + 0.013013*T + 0.000001639*T*T - 0.000000503*T*T*T;
     144    double Xo = 0.0;
     145    double xo = 0.0;
     146
     147    return(psSphereTransformAlloc(phi, Xo, xo));
     148}
     149
     150// XXX: Add a date argument to determine the correct year.
    113151psSphereTransform *psSphereTransformEcliptictoICRS(void)
    114152{
    115     // sla_ECLEQ();
    116     return(NULL);
     153    double year = 2004.0;
     154    double T = year / 100.0;
     155    double phi = +23.452294 - 0.013013*T - 0.000001639*T*T + 0.000000503*T*T*T;
     156    double Xo = 0.0;
     157    double xo = 0.0;
     158
     159    return(psSphereTransformAlloc(phi, Xo, xo));
    117160}
    118161
    119162psSphereTransform *psSphereTransformICRStoGalatic(void)
    120163{
    121     // sla_EQGAL();
    122     return(NULL);
     164    return(psSphereTransformAlloc(62.6, 282.25, 33.0));
    123165}
    124166
    125167psSphereTransform *psSphereTransformGalatictoICRS(void)
    126168{
    127     // sla_GALEQL();
    128     return(NULL);
     169    return(psSphereTransformAlloc(-62.6, 33.0, 282.25));
    129170}
    130171
     
    135176}
    136177
     178// This is some kind of arc tan function.
    137179float arg(float x, float y)
    138180{
     
    153195}
    154196
    155 
     197// XXX: Waiting for the definition of the PS_PROJ_PAR projection.
     198// XXX: Waiting for the definition of the PS_PROJ_GLS projection.
    156199psPlane *psProject(const psSphere *coord,
    157200                   const psProjection *projection)
     
    190233
    191234    } else if (projection->type == PS_PROJ_GLS) {
    192         psAbort(__func__, "The projection type PS_PROJ_GLG is undefined.\n");
     235        psAbort(__func__, "The projection type PS_PROJ_GLS is undefined.\n");
    193236    }
    194237
     
    196239}
    197240
     241// XXX: Waiting for the definition of the PS_PROJ_PAR projection.
     242// XXX: Waiting for the definition of the PS_PROJ_GLS projection.
    198243psSphere *psDeproject(const psPlane *coord,
    199244                      const psProjection *projection)
     
    248293                            psSphereOffsetUnit unit)
    249294{
    250     psAbort(__func__, "This function has not be dedfined.\n");
     295    //    psPlane lin;
     296    psSphere *tmp;
     297    //    psProjection proj;
     298    double tmpR = 0.0;
     299    double tmpD = 0.0;
     300
     301    if (mode == PS_LINEAR) {
     302        // XXX: I have no idea how to construct this.
     303        return(NULL);
     304    } else if (mode == PS_SPHERICAL) {
     305        tmpR = position2->r - position1->r;
     306        tmpD = position2->d - position1->d;
     307
     308        if (unit == PS_ARCSEC) {
     309            tmpR = (tmpR * 180.0 * 60.0 * 60.0) / M_PI;
     310            tmpD = (tmpR * 180.0 * 60.0 * 60.0) / M_PI;
     311        } else if (unit == PS_ARCMIN) {
     312            tmpR = (tmpR * 180.0 * 60.0) / M_PI;
     313            tmpD = (tmpR * 180.0 * 60.0) / M_PI;
     314        } else if (unit == PS_DEGREE) {
     315            tmpR = (tmpR * 180.0) / M_PI;
     316            tmpD = (tmpR * 180.0) / M_PI;
     317        } else if (unit == PS_RADIAN) {}
     318        else {
     319            psAbort(__func__, "Unknow offset unit: 0x%x\n", unit);
     320        }
     321
     322        tmp = (psSphere *) psAlloc(sizeof(psSphere));
     323        tmp->r = tmpR;
     324        tmp->d = tmpD;
     325        tmp->rErr = 0.0;
     326        tmp->dErr = 0.0;
     327        // XXX: Do we need to wrap these to an acceptable range?
     328        return(tmp);
     329    }
     330    psAbort(__func__, "Unrecognized offset mode\n");
    251331    return(NULL);
    252332}
    253333
    254334
    255 // XXX: I copied the algorithm from the ADD exactly.  Arguments mode and unit
    256 // are ignored.
     335// XXX: I copied the algorithm from the ADD exactly.
    257336psSphere *psSphereSetOffset(const psSphere *restrict position,
    258337                            const psSphere *restrict offset,
     
    263342    psSphere *tmp;
    264343    psProjection proj;
     344    double tmpR = 0.0;
     345    double tmpD = 0.0;
    265346
    266347    if (mode == PS_LINEAR) {
    267348        proj.R = position->r;
    268349        proj.D = position->d;
    269         proj.Xs = 0.0;
    270         proj.Ys = 0.0;
     350        proj.Xs = 1.0;
     351        proj.Ys = 1.0;
    271352        proj.type = PS_PROJ_TAN;
    272353
     
    276357        tmp = psDeproject(&lin, &proj);
    277358        return(tmp);
     359
    278360    } else if (mode == PS_SPHERICAL) {
    279         psAbort(__func__, "Sperical offset modes are not defined.\n");
     361        if (unit == PS_ARCSEC) {
     362            tmpR = (M_PI * offset->r) / (180.0 * 60.0 * 60.0);
     363            tmpD = (M_PI * offset->d) / (180.0 * 60.0 * 60.0);
     364        } else if (unit == PS_ARCMIN) {
     365            tmpR = (M_PI * offset->r) / (180.0 * 60.0);
     366            tmpD = (M_PI * offset->d) / (180.0 * 60.0);
     367        } else if (unit == PS_DEGREE) {
     368            tmpR = (M_PI * offset->r) / (180.0);
     369            tmpD = (M_PI * offset->d) / (180.0);
     370        } else if (unit == PS_RADIAN) {
     371            tmpR = offset->r;
     372            tmpD = offset->d;
     373        } else {
     374            psAbort(__func__, "Unknow offset unit: 0x%x\n", unit);
     375        }
     376
     377        tmp = (psSphere *) psAlloc(sizeof(psSphere));
     378        tmp->r = position->r + tmpR;
     379        tmp->r = position->d + tmpD;
     380        tmp->rErr = 0.0;
     381        tmp->dErr = 0.0;
     382
     383        // XXX: wrap tmp->r and tmp->d to the allowed range (-PI to PI)
     384        // and (0 to 2*PI).
     385        return(tmp);
    280386    }
    281387    psAbort(__func__, "Unrecognized offset mode\n");
Note: See TracChangeset for help on using the changeset viewer.