IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 13, 2005, 12:45:40 PM (22 years ago)
Author:
gusciora
Message:

...

File:
1 edited

Legend:

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

    r2941 r2983  
    1010*  @author GLG, MHPCC
    1111*
    12 *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2005-01-10 19:47:10 $
     12*  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2005-01-13 22:45:28 $
    1414*
    1515*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2424#include "psConstants.h"
    2525#include "psError.h"
     26#include "psLogMsg.h"
    2627#include "psAstronomyErrors.h"
    2728#include <math.h>
     
    183184
    184185/******************************************************************************
     186XXX: Private Function.
     187 
     188piNormalize(): take an input angle in radians and convert it to the range 0:PI.
     189 *****************************************************************************/
     190psF32 piNormalize(psF32 angle)
     191{
     192    while (angle < FLT_EPSILON) {
     193        angle+=M_PI;
     194    }
     195
     196    while (angle >= M_PI) {
     197        angle-=M_PI;
     198    }
     199    return(angle);
     200}
     201
     202/******************************************************************************
     203XXX: We convert Right Ascension angles to the range 0:PI.  Is that acceptable?
     204XXX: Should we do something for Declination as well?
    185205 *****************************************************************************/
    186206psSphere* psSphereTransformApply(psSphere* out,
     
    210230    psF64 phi = atan2(eq56, eq57) + transform->alphaP;
    211231
    212     out->r = phi;
     232
     233    out->r = piNormalize(phi);
    213234    out->d = theta;
    214235
     
    281302XXX: Waiting for the definition of the PS_PROJ_PAR projection.
    282303XXX: Waiting for the definition of the PS_PROJ_GLS projection.
     304XXX: Must apply scaling at the end.
    283305 *****************************************************************************/
    284306psPlane* psProject(const psSphere* coord,
     
    288310    PS_PTR_CHECK_NULL(projection, NULL);
    289311
    290     //    float R = 0.0;
    291     //    float alpha = 0.0;
    292312    psPlane* tmp = (psPlane* ) psAlloc(sizeof(psPlane));
    293 
    294313    if (projection->type == PS_PROJ_TAN) {
    295         tmp->x = cos(coord->r) * sin(coord->d) / sin(coord->r);
    296         tmp->y = -cos(coord->r) * cos(coord->d) / sin(coord->r);
     314
     315        /*
     316                // ********************************************
     317                // From the ADD
     318                // ********************************************
     319                // psLogMsg(__func__, PS_LOG_WARN, "WARNING: psProject(): These projections don't work.");
     320                // return(NULL);
     321                psF32 sinTheta;
     322                psF32 cosThetaCosPhi;
     323                psF32 cosThetaSinPhi;
     324         
     325                sinTheta = (sin(coord->d) * sin(projection->D)) +
     326                           (cos(coord->d) * cos(projection->D) * (cos(coord->r - projection->R)));
     327                cosThetaCosPhi = (sin(coord->d) * cos(projection->D)) -
     328                                 (cos(coord->d) * sin(projection->D) * (cos(coord->r - projection->R)));
     329                cosThetaSinPhi = - cos(coord->d) * sin(coord->r - projection->R);
     330         
     331                tmp->x =  -cosThetaSinPhi / sinTheta;
     332                tmp->y = cosThetaCosPhi / sinTheta;
     333         
     334        */
     335
     336        // ********************************************
     337        // From the mathworks: http://mathworld.wolfram.com/GnomonicProjection.html
     338        // delta_0 and phi_1 are the projection centers, not the point being projected.
     339        // (delta_0, phi_1) == (projection->R, projection->D)
     340        // ********************************************
     341        psF32 cosC = (sin(projection->D) * sin(coord->d)) +
     342                     (cos(projection->D) * cos(coord->d) * cos(coord->r - projection->R));
     343        tmp->x = (cos(coord->d) * sin(coord->r - projection->R)) / cosC;
     344        tmp->y = ((cos(projection->D) * sin(coord->d)) -
     345                  (sin(projection->D) * cos(coord->d) * cos(coord->r - projection->R))) /
     346                 cosC;
    297347
    298348    } else if (projection->type == PS_PROJ_SIN) {
     349        // psLogMsg(__func__, PS_LOG_WARN, "WARNING: psProject(): These projections don't work.");
     350        // return(NULL);
     351
    299352        tmp->x = cos(coord->d) * sin(coord->d);
    300353        tmp->y = -cos(coord->d) * cos(coord->d);
     
    332385
    333386/******************************************************************************
     387XXX: Waiting for algorithms.
    334388XXX: Waiting for the definition of the PS_PROJ_PAR projection.
    335389XXX: Waiting for the definition of the PS_PROJ_GLS projection.
     390XXX: Must apply scaling at the beginning.
    336391 *****************************************************************************/
    337392psSphere* psDeproject(const psPlane* coord,
     
    340395    PS_PTR_CHECK_NULL(coord, NULL);
    341396    PS_PTR_CHECK_NULL(projection, NULL);
    342 
     397    //    psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): These projections don't work.");
     398    //    return(NULL);
    343399    float R = 0.0;
    344400    float chu = 0.0;
     
    348404
    349405    if (projection->type == PS_PROJ_TAN) {
    350         tmp->r = atan2(-coord->y, coord->x);
    351         R = PS_SQRT_F32((coord->x * coord->x) + (coord->y * coord->y));
    352         tmp->d = atan(1.0 / R);
     406        /*
     407                // ********************************************
     408                // From the ADD
     409                // ********************************************
     410                psF32 phi;
     411                psF32 theta;
     412                psF32 sinDelta;
     413                psF32 cosDeltaCosAlphaMinusAlphaP;
     414                psF32 cosDeltaSinAlphaMinusAlphaP;
     415         
     416                phi = atan2(-coord->y, coord->x);
     417                R = PS_SQRT_F32((coord->x * coord->x) + (coord->y * coord->y));
     418                theta = atan(1.0 / R);
     419         
     420                sinDelta = (sin(theta) * sin(projection->D)) +
     421                           (cos(theta) * cos(projection->D) * cos(phi));
     422                cosDeltaCosAlphaMinusAlphaP =
     423                           (sin(theta) * cos(projection->D)) -
     424                           (cos(theta) * sin(projection->D) * cos(phi));
     425                cosDeltaSinAlphaMinusAlphaP = -cos(theta) * sin(phi);
     426                tmp->d = asin(sinDelta);
     427                tmp->r = atan2(cosDeltaSinAlphaMinusAlphaP, cosDeltaCosAlphaMinusAlphaP) + projection->R;
     428        */
     429        // ********************************************
     430        // From the mathworks: http://mathworld.wolfram.com/GnomonicProjection.html
     431        // delta_0 and phi_1 are the projection centers, not the point being projected.
     432        // (delta_0, phi_1) == (projection->R, projection->D)
     433        // ********************************************
     434        psF32 row = PS_SQRT_F32((coord->x * coord->x) + (coord->y * coord->y));
     435        psF32 C = atan(row);
     436        tmp->d = asin((cos(C) * sin(projection->D)) + ((coord->y * sin(C) * cos(projection->D)) / row));
     437        psF32 tmpAtan = atan((coord->x * sin(C)) /
     438                             ((row * cos(projection->D) * cos(C)) - (coord->y * sin(projection->D) * sin(C))));
     439        tmp->r = projection->R + tmpAtan;
     440
    353441
    354442    } else if (projection->type == PS_PROJ_SIN) {
     
    415503    PS_PTR_CHECK_NULL(position2, NULL);
    416504
     505    if (position1->d >= DEG_TO_RAD(90.0)) {
     506        psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): position1->d is larger than 90 degrees.  Returning NULL.\n");
     507        return(NULL);
     508    }
     509    if (position2->d >= DEG_TO_RAD(90.0)) {
     510        psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): position2->d is larger than 90 degrees.  Returning NULL.\n");
     511        return(NULL);
     512    }
     513
    417514    psPlane* lin;
    418515    psProjection proj;
     
    426523        proj.type = PS_PROJ_TAN;
    427524
    428         printf("------------ position 1 is (%f, %f)\n", position1->r, position1->d);
    429         printf("------------ position 2 is (%f, %f)\n", position2->r, position2->d);
    430525        lin = psProject(position1, &proj);
    431         printf("------------ projected position 1 is (%f, %f)\n", lin->y, lin->x);
    432526        lin = psProject(position2, &proj);
    433         printf("------------ projected position 2 is (%f, %f)\n", lin->y, lin->x);
    434527        tmp = psDeproject(lin, &proj);
    435         printf("------------ deprojected position 2 is (%f, %f)\n", tmp->r, tmp->d);
    436 
    437528        psFree(lin);
    438 
    439529        // XXX: Do we need to convert units in tmp?
    440530        return (tmp);
Note: See TracChangeset for help on using the changeset viewer.