IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 12, 2005, 9:12:01 AM (21 years ago)
Author:
desonia
Message:

massive restructuring of codebase.

File:
1 edited

Legend:

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

    r4401 r4540  
    1010*  @author GLG, MHPCC
    1111*
    12 *  @version $Revision: 1.78 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2005-06-27 20:38:11 $
     12*  @version $Revision: 1.79 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2005-07-12 19:12:00 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3030#include <math.h>
    3131#include <float.h>
    32 /******************************************************************************/
    33 /*  DEFINE STATEMENTS                                                         */
    34 /******************************************************************************/
    3532
    3633// Modified Julian Day 01/01/1900 00:00:00
     
    4037#define JULIAN_CENTURY 36525.0
    4138
    42 /******************************************************************************/
    43 /*  TYPE DEFINITIONS                                                          */
    44 /******************************************************************************/
    45 
    46 // None
    47 
    48 /*****************************************************************************/
    49 /*  GLOBAL VARIABLES                                                         */
    50 /*****************************************************************************/
    51 
    52 // None
    53 
    54 /*****************************************************************************/
    55 /*  FILE STATIC VARIABLES                                                    */
    56 /*****************************************************************************/
    57 
    58 // None
    59 
    60 /*****************************************************************************/
    61 /*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    62 /*****************************************************************************/
    63 
    64 /*****************************************************************************/
    65 /* FUNCTION IMPLEMENTATION - PUBLIC                                          */
    66 /*****************************************************************************/
    6739static void planeFree(psPlane *p)
    6840{
    6941    // There are non dynamic allocated items
     42}
     43
     44static void sphereFree(psSphere *s)
     45{
     46    // There are non dynamic allocated items
     47}
     48
     49static void planeTransformFree(psPlaneTransform *pt)
     50{
     51    psFree(pt->x);
     52    psFree(pt->y);
     53}
     54
     55static void planeDistortFree(psPlaneDistort *pt)
     56{
     57    psFree(pt->x);
     58    psFree(pt->y);
     59}
     60
     61static void projectionFree(psProjection *p)
     62{
     63    // There are no dynamically allocated items
    7064}
    7165
     
    201195}
    202196
    203 
    204 static void sphereFree(psSphere *s)
    205 {
    206     // There are non dynamic allocated items
    207 }
    208 
    209197psSphere* psSphereAlloc(void)
    210198{
     
    215203}
    216204
    217 static void planeTransformFree(psPlaneTransform *pt)
    218 {
    219     psFree(pt->x);
    220     psFree(pt->y);
     205psSphereRot* psSphereRotAlloc(double alphaP,
     206                              double deltaP,
     207                              double phiP)
     208{
     209    psSphereRot* rot = psAlloc(sizeof(psSphereRot));
     210
     211    double cosDelta = cos(deltaP);
     212    double halfPhi = phiP / 2.0;
     213    double sinHalfPhi = sin(halfPhi);
     214
     215    // equations are directly from ADD
     216    double vx = cosDelta*cos(alphaP);
     217    double vy = cosDelta*sin(alphaP);
     218    double vz = sin(deltaP);
     219
     220    rot->q0 = vx*sinHalfPhi;
     221    rot->q1 = vy*sinHalfPhi;
     222    rot->q2 = vz*sinHalfPhi;
     223    rot->q3 = cos(halfPhi);
     224
     225    return rot;
     226}
     227
     228psSphereRot* psSphereRotQuat(double q0,
     229                             double q1,
     230                             double q2,
     231                             double q3)
     232{
     233    psSphereRot* rot = psAlloc(sizeof(psSphereRot));
     234
     235    double len = sqrt(q0*q0 + q1*q1 + q2*q2 + q3*q3);
     236    rot->q0 = q0 / len;
     237    rot->q1 = q1 / len;
     238    rot->q2 = q2 / len;
     239    rot->q3 = q3 / len;
     240
     241    return rot;
    221242}
    222243
     
    260281
    261282    return (out);
    262 }
    263 
    264 static void planeDistortFree(psPlaneDistort *pt)
    265 {
    266     psFree(pt->x);
    267     psFree(pt->y);
    268283}
    269284
     
    319334
    320335/******************************************************************************
    321 alpha is LONGITUDE
    322 delta is LATITUDE
    323  
    324     alphaP: Take the target pole in the source system; calculate its LONGITUDE
    325      in the target system.  That longitude is alphaP.
    326     DeltaP: Take the target pole in the source system; calculate its LATITUDE
    327      in the target system.  That longitude is deltaP.
    328     phiP:   This is the LONGITUDE of the ascending node in the target system.
    329  *****************************************************************************/
    330 psSphereTransform* psSphereTransformAlloc(psF64 alphaP,
    331         psF64 deltaP,
    332         psF64 phiP)
    333 {
    334     psSphereTransform* tmp = (psSphereTransform* ) psAlloc(sizeof(psSphereTransform));
    335 
    336     tmp->cosDeltaP = cos(deltaP);
    337     tmp->sinDeltaP = sin(deltaP);
    338     tmp->alphaP = alphaP;
    339     tmp->phiP = phiP;
    340 
    341     return (tmp);
    342 }
    343 
    344 /******************************************************************************
    345 XXX: Private Function.
    346  
    347 piNormalize(): take an input angle in radians and convert it to the range 0:2*PI.
    348  *****************************************************************************/
    349 psF32 piNormalize(psF32 angle)
    350 {
    351     while (angle < FLT_EPSILON) {
    352         angle+=M_PI*2;
    353     }
    354 
    355     while (angle >= (M_PI*2)) {
    356         angle-=M_PI*2;
    357     }
    358     return(angle);
    359 }
    360 
    361 /******************************************************************************
    362336XXX: We convert Right Ascension angles to the range 0:PI.  Is that acceptable?
    363337XXX: Should we do something for Declination as well?
    364338 *****************************************************************************/
    365 psSphere* psSphereTransformApply(psSphere* out,
    366                                  const psSphereTransform* transform,
    367                                  const psSphere* coord)
     339psSphere* psSphereRotApply(psSphere* out,
     340                           const psSphereRot* transform,
     341                           const psSphere* coord)
    368342{
    369343    PS_ASSERT_PTR_NON_NULL(transform, NULL);
     
    371345
    372346    if (out == NULL) {
    373         out = (psSphere* ) psAlloc(sizeof(psSphere));
    374     }
    375 
    376     psF64 alpha = coord->r;
    377     psF64 delta = coord->d;
    378     psF64 alphaMinusAlphaP = alpha - transform->alphaP;
    379 
    380     psF64 eq55 = (sin(delta) * transform->cosDeltaP) -
    381                  (cos(delta) * transform->sinDeltaP * sin(alphaMinusAlphaP));
    382     psF64 eq56 = (cos(delta) * transform->cosDeltaP * sin(alphaMinusAlphaP)) +
    383                  (sin(delta) * transform->sinDeltaP);
    384     psF64 eq57 = cos(delta) * cos(alphaMinusAlphaP);
    385 
    386     psF64 theta = asin(eq55);
    387     psF64 phi = atan2(eq56, eq57) + transform->phiP;
    388     out->r = piNormalize(phi);
    389     out->d = theta;
    390 
    391     return(out);
    392 }
    393 
    394 psSphereTransform* psSphereTransformICRSToEcliptic(psTime *time)
     347        out = psSphereAlloc();
     348    }
     349
     350
     351    // apply the transform by creating a new psSphereRot from the input coord
     352    // and combining it with the input transform (see ADD)
     353    psSphereRot* coordRot = psSphereRotAlloc(coord->r, coord->d, 0);
     354    coordRot->q3 = 0.0;
     355    coordRot = psSphereRotCombine(coordRot, transform, coordRot);
     356    // N.B., we can recycle coordRot right away due to the implementation of
     357    // psSphereRotCombine puts the values of coordRot in a local variable first
     358
     359    out->r = atan2(coordRot->q1,coordRot->q0);
     360    out->d = atan2(coordRot->q2,sqrt(coordRot->q1*coordRot->q1+coordRot->q0*coordRot->q0));
     361
     362    return out;
     363}
     364
     365psSphereRot* psSphereRotCombine(psSphereRot* out,
     366                                const psSphereRot* rot1,
     367                                const psSphereRot* rot2)
     368{
     369    PS_ASSERT_PTR_NON_NULL(rot1, NULL);
     370    PS_ASSERT_PTR_NON_NULL(rot2, NULL);
     371
     372    if (out == NULL) {
     373        out = (psSphereRot* ) psAlloc(sizeof(psSphereRot));
     374    }
     375
     376    double a0 = rot1->q0;
     377    double a1 = rot1->q1;
     378    double a2 = rot1->q2;
     379    double a3 = rot1->q3;
     380    double b0 = rot2->q0;
     381    double b1 = rot2->q1;
     382    double b2 = rot2->q2;
     383    double b3 = rot2->q3;
     384
     385    // following came from ADD
     386    out->q0 = b3*a0 + b2*a1 - b1*a2 + b0*a3;
     387    out->q1 = b3*a1 - b2*a0 + b1*a3 + b0*a2;
     388    out->q2 = b3*a2 + b2*a3 + b1*a0 - b0*a1;
     389    out->q3 = b3*a3 - b3*a2 - b1*a1 - b0*a0;
     390
     391    return out;
     392}
     393
     394psSphereRot *psSphereRotInvert(psSphereRot *rot)
     395{
     396    PS_ASSERT_PTR_NON_NULL(rot, NULL);
     397
     398    double norm = sqrt(rot->q0*rot->q0 + rot->q1*rot->q1 + rot->q2*rot->q2 + rot->q3*rot->q3);
     399    rot->q1 = -rot->q1 / norm;
     400    rot->q2 = -rot->q2 / norm;
     401    rot->q3 = -rot->q3 / norm;
     402
     403    return rot;
     404}
     405
     406psSphereRot* psSphereRotICRSToEcliptic(const psTime *time)
    395407{
    396408    psF64 T;
     
    421433
    422434    // Don't neglect the minus sign on deltaP (bug 244):
    423     return (psSphereTransformAlloc(alphaP, deltaP, phiP));
    424 }
    425 
    426 
    427 psSphereTransform* psSphereTransformEclipticToICRS(psTime *time)
     435    return (psSphereRotAlloc(alphaP, deltaP, phiP));
     436}
     437
     438
     439psSphereRot* psSphereRotEclipticToICRS(const psTime *time)
    428440{
    429441    psF64 T;
     
    453465    psF64 phiP = 0.0;
    454466
    455     return (psSphereTransformAlloc(alphaP, -deltaP, phiP));
     467    return (psSphereRotAlloc(alphaP, -deltaP, phiP));
    456468}
    457469
    458470// XXX: This is bug 245: alphaP swaps with phiP from psSphereTransformGalacticToICRS()
    459 psSphereTransform* psSphereTransformGalacticToICRS(void)
     471psSphereRot* psSphereRotGalacticToICRS(void)
    460472{
    461473    psF64 alphaP = DEG_TO_RAD(32.93192);
     
    463475    psF64 phiP = DEG_TO_RAD(282.85948);
    464476
    465     return (psSphereTransformAlloc(alphaP, deltaP, phiP));
    466 }
    467 
    468 psSphereTransform* psSphereTransformICRSToGalactic(void)
     477    return (psSphereRotAlloc(alphaP, deltaP, phiP));
     478}
     479
     480psSphereRot* psSphereRotICRSToGalactic(void)
    469481{
    470482    psF64 alphaP = DEG_TO_RAD(282.85948);
     
    472484    psF64 phiP = DEG_TO_RAD(32.93192);
    473485
    474     return (psSphereTransformAlloc(alphaP, deltaP, phiP));
    475 }
    476 
    477 void projectionFree(psProjection *p)
    478 {
    479     // There are no dynamically allocated items
     486    return (psSphereRotAlloc(alphaP, deltaP, phiP));
    480487}
    481488
     
    837844
    838845    // Create transform with proper constants
    839     psSphereTransform *tmpST = psSphereTransformAlloc(alphaP, deltaP, phiP);
     846    psSphereRot* tmpST = psSphereRotAlloc(alphaP, deltaP, phiP);
    840847
    841848    // Apply transform to coordinates
    842     psSphere *out = psSphereTransformApply(NULL, tmpST, coords);
     849    psSphere *out = psSphereRotApply(NULL, tmpST, coords);
    843850
    844851    psFree(tmpST);
Note: See TracChangeset for help on using the changeset viewer.