IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 7, 2005, 10:52:43 AM (21 years ago)
Author:
drobbin
Message:

update doxygen, implemented sphereRot functions in EOC.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astro/psEarthOrientation.c

    r5466 r5483  
    99*  @author Robert Daniel DeSonia, MHPCC
    1010*
    11 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2005-11-03 04:31:22 $
     11*  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2005-11-07 20:52:43 $
    1313*
    1414*  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
     
    5252static bool eocInitialized = false;
    5353
     54static psSphereRot *rotMatrix_To_Quat(double A[3][3]);
     55
     56static void earthPoleFree(psEarthPole *pole)
     57{
     58    // There are non dynamic allocated items
     59}
     60
     61psEarthPole *psEarthPoleAlloc(void)
     62{
     63    psEarthPole* pole = psAlloc(sizeof(psEarthPole));
     64    psMemSetDeallocator(pole, (psFreeFunc) earthPoleFree);
     65    return pole;
     66}
     67
    5468static bool eocInit()
    5569{
     
    139153    psFree(xTable);
    140154    psFree(yTable);
    141     psFree(sTable);
     155    psFree(sTable);    // There are non dynamic allocated items
     156
    142157
    143158    xTable = NULL;
     
    179194        apparent->dErr = 0.0;
    180195    }
    181     psSphere *rp = psSphereAlloc();
    182     psSphere *r_p = psSphereAlloc();
     196    //    psSphere *rp = psSphereAlloc();
     197    psCube *rp = psCubeAlloc();
     198    //    psSphere *r_p = psSphereAlloc();
     199    psCube *r_p = psCubeAlloc();
    183200    double mu = 0.0;
    184201    double mu_p = 0.0;
     
    188205    //    mu = apparent->r * direction->r + apparent->d * direction->d;
    189206    psCube* directionVector = psSphereToCube(direction);
     207    if (directionVector == NULL)
     208        printf("directionVector is null\n");
    190209    psCube* actualVector = psSphereToCube(actual);
     210    if (directionVector == NULL)
     211        printf("actualVector is null\n");
    191212    mu = acos(directionVector->x*actualVector->x +
    192213              directionVector->y*actualVector->y +
     
    194215
    195216    //rp = apparent - mu * direction;
    196     rp->r = actual->r - mu * direction->r;
    197     rp->d = actual->d - mu * direction->d;
     217    //    rp->r = actual->r - mu * direction->r;
     218    //    rp->d = actual->d - mu * direction->d;
     219    rp->x = actualVector->x - mu * directionVector->x;
     220    rp->y = actualVector->y - mu * directionVector->y;
     221    rp->z = actualVector->z - mu * directionVector->z;
    198222
    199223    mu_p = mu + speed * ((mu * mu - 1.0) / (1.0 - speed * mu));
    200224
    201225    //Not sure if this is right.  ADD gets a scalar from division of rp (a vector)
    202     psCube* rpVector = psSphereToCube(rp);
    203     a = sqrt( (1.0 - mu_p * mu_p) /
    204               (sqrt(rpVector->x*rpVector->x
    205                     + rpVector->y*rpVector->y
    206                     + rpVector->z*rpVector->z)) );
    207 
     226    //Paul claims rp is the modulus or square of the vector components
     227    /*    psCube* rpVector = psSphereToCube(rp);
     228        a = sqrt( (1.0 - mu_p * mu_p) / ( rpVector->x*rpVector->x +
     229                rpVector->y*rpVector->y + rpVector->z*rpVector->z)  );
     230    */
     231    a = (1.0 - mu_p * mu_p) / (rp->x * rp->x + rp->y * rp->y + rp->z * rp->z);
     232    if (a < 0.0) {
     233        printf("a is negative\n");
     234        psFree(rp);
     235        psFree(r_p);
     236        psFree(directionVector);
     237        psFree(actualVector);
     238        psFree(apparent)
     239        return NULL;
     240    } else
     241        a = sqrt(a);
    208242    //r_p = mu_p * direction + a * rp;
    209     r_p->r = mu_p * direction->r + a * rp->r;
    210     r_p->d = mu_p * direction->d + a * rp->d;
    211 
    212     *apparent = *r_p;
     243    //    r_p->r = mu_p * direction->r + a * rp->r;
     244    //    r_p->d = mu_p * direction->d + a * rp->d;
     245    r_p->x = mu_p * directionVector->x + a * rp->x;
     246    r_p->y = mu_p * directionVector->y + a * rp->y;
     247    r_p->z = mu_p * directionVector->z + a * rp->z;
     248
     249    psSphere *r_pSphere = psCubeToSphere(r_p);
     250    if (r_pSphere == NULL)
     251        printf("r_pSphere is null\n");
     252
     253    *apparent = *r_pSphere;
    213254    /*
    214255        psSphereRot *rot = NULL;
     
    223264    psFree(rp);
    224265    psFree(r_p);
     266    psFree(r_pSphere)
    225267    psFree(directionVector);
    226268    psFree(actualVector);
    227     psFree(rpVector);
     269    //    psFree(rpVector);
    228270    return apparent;
    229271}
     
    280322    deflection = SEC_TO_RAD(deflection);
    281323    theta = atan(r0/PS_AU) * tan(deflection);
    282     phi = sqrt( deflection*deflection - theta*theta );
     324    //    phi = sqrt( deflection*deflection - theta*theta );
     325    phi = deflection * cos(asin(theta/deflection));
    283326    apparent->r = theta;
    284327    apparent->d = phi;
     
    447490}
    448491
     492static psSphereRot *rotMatrix_To_Quat(double A[3][3])
     493{
     494    int i;
     495    psSphereRot *new = (psSphereRot*)psAlloc(sizeof(psSphereRot));
     496    //    psMemSetDeallocator(new, (psFreeFunc)sphereRotFree);
     497    //Convert rotation matrix to quaternions
     498    double diag_sum[3];
     499    int maxi;
     500    double recip;
     501    diag_sum[0] = 1.0 + A[0][0] - A[1][1] - A[2][2];
     502    diag_sum[1] = 1.0 - A[0][0] + A[1][1] - A[2][2];
     503    diag_sum[2] = 1.0 - A[0][0] - A[1][1] + A[2][2];
     504    diag_sum[3] = 1.0 + A[0][0] + A[1][1] + A[2][2];
     505
     506    maxi = 0;
     507    for (i = 1; i < 4; ++i) {
     508        if (diag_sum[i] > diag_sum[maxi]) {
     509            maxi = i;
     510        }
     511    }
     512
     513    double p = 0.5 * sqrt(diag_sum[maxi]);
     514    recip = 1.0 / (4.0 * p);
     515
     516    if (maxi == 0) {
     517        new->q0 = p;
     518        new->q1 = recip * (A[0][1] + A[1][0]);
     519        new->q2 = recip * (A[2][0] + A[0][2]);
     520        new->q3 = recip * (A[1][2] - A[2][1]);
     521    } else if (maxi == 1) {
     522        new->q0 = recip * (A[0][1] + A[1][0]);
     523        new->q1 = p;
     524        new->q2 = recip * (A[1][2] + A[2][1]);
     525        new->q3 = recip * (A[2][0] - A[0][2]);
     526    } else if (maxi == 2) {
     527        new->q0 = recip * (A[2][0] + A[0][2]);
     528        new->q1 = recip * (A[1][2] + A[2][1]);
     529        new->q2 = p;
     530        new->q3 = recip * (A[0][1] - A[1][0]);
     531    } else if (maxi == 3) {
     532        new->q0 = recip * (A[1][2] - A[2][1]);
     533        new->q1 = recip * (A[2][0] - A[0][2]);
     534        new->q2 = recip * (A[0][1] - A[1][0]);
     535        new->q3 = p;
     536    }
     537    return new;
     538}
    449539
    450540psSphereRot* psSphereRot_CEOtoGCRS(const psEarthPole *pole)
    451541{
    452     return NULL;
     542    PS_ASSERT_PTR_NON_NULL(pole,NULL);
     543    double A[3][3];
     544    psSphereRot *out = NULL;
     545
     546    //Setup the rotation matrix and scalar value, a, as outlined by the ADD
     547    //XXX: Used formula for rotation matrix D from mathworld for z-axis rotation
     548    double a =  1.0 / (1.0 + sqrt(1.0 - (pole->x*pole->x + pole->y*pole->y) ) );
     549    A[0][0] = (1.0 - a*pole->x*pole->x)*cos(pole->s) - a*pole->x*pole->y*sin(pole->s);
     550    A[0][1] = -a*pole->x*pole->y*cos(pole->s) + (1.0 - a*pole->y*pole->y)*sin(pole->s);
     551    A[0][2] = pole->x*cos(pole->s) + pole->y*sin(pole->s);
     552    A[1][0] = -(1.0 - a*pole->x*pole->x)*sin(pole->s) - a*pole->x*pole->y*cos(pole->s);
     553    A[1][1] = a*pole->x*pole->y*sin(pole->s) + (1.0 - a*pole->y*pole->y)*cos(pole->s);
     554    A[1][2] = -pole->x*sin(pole->s) + pole->y*cos(pole->s);
     555    A[2][0] = -pole->x;
     556    A[2][1] = -pole->y;
     557    A[2][2] = 1.0 - a*(pole->x*pole->x + pole->y*pole->y);
     558
     559    out = rotMatrix_To_Quat(A);
     560
     561    return out;
    453562}
    454563
     
    495604psSphereRot* psSphereRot_ITRStoTEO(const psEarthPole* motion)
    496605{
    497     return NULL;
    498 }
     606    PS_ASSERT_PTR_NON_NULL(motion,NULL);
     607    double A[3][3];
     608    psSphereRot *out = NULL;
     609
     610    //Setup Rotation Matrix for transformation (x,y,z rotation)
     611    //XXX: May need to be (z,y,x as in Mathworld?)
     612    A[0][0] = cos(motion->x)*cos(-motion->s);
     613    A[0][1] = sin(motion->y)*sin(motion->x)*cos(-motion->s) + cos(motion->y)*sin(-motion->s);
     614    A[0][2] = -cos(motion->y)*sin(motion->x)*cos(-motion->s) + sin(motion->y)*sin(-motion->s);
     615    A[1][0] = -cos(motion->x)*sin(-motion->s);
     616    A[1][1] = -sin(motion->y)*sin(motion->x)*sin(-motion->s) + cos(motion->y)*cos(-motion->s);
     617    A[1][2] = cos(motion->y)*sin(motion->x)*sin(-motion->s) + sin(motion->y)*cos(-motion->s);
     618    A[2][0] = sin(motion->x);
     619    A[2][1] = -sin(motion->y)*cos(motion->x);
     620    A[2][2] = cos(motion->y)*cos(motion->x);
     621
     622    //Convert rotation matrix to quaternions
     623    double diag_sum[3];
     624    int maxi;
     625    double recip;
     626    diag_sum[0] = 1.0 + A[0][0] - A[1][1] - A[2][2];
     627    diag_sum[1] = 1.0 - A[0][0] + A[1][1] - A[2][2];
     628    diag_sum[2] = 1.0 - A[0][0] - A[1][1] + A[2][2];
     629    diag_sum[3] = 1.0 + A[0][0] + A[1][1] + A[2][2];
     630
     631    maxi = 0;
     632    for (int i = 1; i < 4; ++i) {
     633        if (diag_sum[i] > diag_sum[maxi]) {
     634            maxi = i;
     635        }
     636    }
     637
     638    double p = 0.5 * sqrt(diag_sum[maxi]);
     639    recip = 1.0 / (4.0 * p);
     640
     641    if (maxi == 0) {
     642        out->q0 = p;
     643        out->q1 = recip * (A[0][1] + A[1][0]);
     644        out->q2 = recip * (A[2][0] + A[0][2]);
     645        out->q3 = recip * (A[1][2] - A[2][1]);
     646    } else if (maxi == 1) {
     647        out->q0 = recip * (A[0][1] + A[1][0]);
     648        out->q1 = p;
     649        out->q2 = recip * (A[1][2] + A[2][1]);
     650        out->q3 = recip * (A[2][0] - A[0][2]);
     651    } else if (maxi == 2) {
     652        out->q0 = recip * (A[2][0] + A[0][2]);
     653        out->q1 = recip * (A[1][2] + A[2][1]);
     654        out->q2 = p;
     655        out->q3 = recip * (A[0][1] - A[1][0]);
     656    } else if (maxi == 3) {
     657        out->q0 = recip * (A[1][2] - A[2][1]);
     658        out->q1 = recip * (A[2][0] - A[0][2]);
     659        out->q2 = recip * (A[0][1] - A[1][0]);
     660        out->q3 = p;
     661    }
     662
     663    return out;
     664}
Note: See TracChangeset for help on using the changeset viewer.