IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 23, 2004, 4:46:45 PM (22 years ago)
Author:
gusciora
Message:

...

File:
1 edited

Legend:

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

    r1287 r1293  
    1010 *  @author George Gusciora, MHPCC
    1111 *
    12  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-07-23 03:13:39 $
     12 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-07-24 02:42:59 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2222#include "psCoord.h"
    2323#include "psMemory.h"
    24 
     24#include "psAbort.h"
     25#include <math.h>
     26#include <float.h>
    2527
    2628psPlane *psPlaneTransformApply(psPlane *out,
     
    127129}
    128130
     131// XXX: Is this the correct way to calculate this?
     132float cot(float x)
     133{
     134    return(1.0 / atan(x));
     135}
     136
     137float arg(float x, float y)
     138{
     139    if (x > 0) {
     140        return(atan(y/x));
     141    } else if ((x==0) && (y==0)) {
     142        return(0.5 * M_PI);
     143    } else if ((x==0) && (y==0)) {
     144        return(-0.5 * M_PI);
     145    } else if ((x==0) && (y==0)) {
     146        return(M_PI + atan(y/x));
     147    } else if ((x==0) && (y==0)) {
     148        return(-M_PI + atan(y/x));
     149    }
     150
     151    psAbort(__func__, "Unacceptable range for (arg(%f, %f).\n", x, y);
     152    return(0.0);
     153}
     154
     155
     156psPlane *psProject(const psSphere *coord,
     157                   const psProjection *projection)
     158{
     159    float R = 0.0;
     160    float alpha = 0.0;
     161    psPlane *tmp= (psPlane *) psAlloc(sizeof(psPlane));
     162
     163    if (projection->type == PS_PROJ_TAN) {
     164        R = cot(coord->r) * (180.0 / M_PI);
     165        tmp->x = R * sin(coord->d);
     166        tmp->y = R * cos(coord->d);
     167
     168    } else if (projection->type == PS_PROJ_SIN) {
     169        R = cos(coord->r) * (180.0 / M_PI);
     170        tmp->x = R * sin(coord->d);
     171        tmp->y = R * cos(coord->d);
     172
     173    } else if (projection->type == PS_PROJ_CAR) {
     174        tmp->x = coord->d;
     175        tmp->y = coord->r;
     176
     177    } else if (projection->type == PS_PROJ_MER) {
     178        tmp->x = coord->d;
     179        tmp->y = log(tan(45.0 + (0.5 * coord->r))) * 180.0/M_PI;
     180
     181    } else if (projection->type == PS_PROJ_AIT) {
     182        alpha = 1.0 / ((180.0 / M_PI) *
     183                       sqrt(1.0 + (cos(coord->r) * cos(0.5 * coord->d) * 0.5)));
     184
     185        tmp->x = 2.0 * alpha * cos(coord->r) * sin(0.5 * coord->d);
     186        tmp->y = alpha * sin(coord->d);
     187
     188    } else if (projection->type == PS_PROJ_PAR) {
     189        psAbort(__func__, "The projection type PS_PROJ_PAR is undefined.\n");
     190
     191    } else if (projection->type == PS_PROJ_GLS) {
     192        psAbort(__func__, "The projection type PS_PROJ_GLG is undefined.\n");
     193    }
     194
     195    return(tmp);
     196}
     197
     198psSphere *psDeproject(const psPlane *coord,
     199                      const psProjection *projection)
     200{
     201    float R = 0.0;
     202    float chu = 0.0;
     203    float chu1 = 0.0;
     204    float chu2 = 0.0;
     205    psSphere *tmp= (psSphere *) psAlloc(sizeof(psSphere));
     206
     207    if (projection->type == PS_PROJ_TAN) {
     208        R = sqrt((coord->x * coord->x) + (coord->y * coord->y));
     209        tmp->d = arg(-coord->y, coord->x);
     210        tmp->r = atan(180.0 / (R * M_PI));
     211
     212    } else if (projection->type == PS_PROJ_SIN) {
     213        R = sqrt((coord->x * coord->x) + (coord->y * coord->y));
     214        tmp->d = arg(-coord->y, coord->x);
     215        tmp->r = acos((R * M_PI) / 180.0);
     216
     217    } else if (projection->type == PS_PROJ_CAR) {
     218        tmp->d = coord->x;
     219        tmp->r = coord->y;
     220
     221    } else if (projection->type == PS_PROJ_MER) {
     222        tmp->d = coord->x;
     223        tmp->r = (2.0 * atan(exp((coord->y * M_PI/180.0)))) - 180.0;
     224
     225    } else if (projection->type == PS_PROJ_AIT) {
     226        chu1 = (coord->x * M_PI) / 720.0;
     227        chu1*= chu1;
     228        chu2 = (coord->y * M_PI) / 360.0;
     229        chu2*= chu2;
     230        chu = sqrt(1.0 - chu1 - chu2);
     231        tmp->d = 2.0 * arg((2.0 * chu * chu) - 1.0,
     232                           (coord->x * chu * M_PI)/360.0);
     233        tmp->r = asin((coord->y * chu * M_PI) / 180.0);
     234
     235    } else if (projection->type == PS_PROJ_PAR) {
     236        psAbort(__func__, "The projection type PS_PROJ_PAR is undefined.\n");
     237
     238    } else if (projection->type == PS_PROJ_GLS) {
     239        psAbort(__func__, "The projection type PS_PROJ_GLG is undefined.\n");
     240    }
     241
     242    return(tmp);
     243}
    129244
    130245psSphere *psSphereGetOffset(const psSphere *restrict position1,
     
    133248                            psSphereOffsetUnit unit)
    134249{
    135     return(NULL);
    136 }
    137 
    138 
     250    psAbort(__func__, "This function has not be dedfined.\n");
     251    return(NULL);
     252}
     253
     254
     255// XXX: I copied the algorithm from the ADD exactly.  Arguments mode and unit
     256// are ignored.
    139257psSphere *psSphereSetOffset(const psSphere *restrict position,
    140258                            const psSphere *restrict offset,
     
    142260                            psSphereOffsetUnit unit)
    143261{
    144     return(NULL);
    145 }
     262    psPlane lin;
     263    psSphere *tmp;
     264    psProjection proj;
     265
     266    if (mode == PS_LINEAR) {
     267        proj.R = position->r;
     268        proj.D = position->d;
     269        proj.Xs = 0.0;
     270        proj.Ys = 0.0;
     271        proj.type = PS_PROJ_TAN;
     272
     273        lin.x = offset->r;
     274        lin.y = offset->d;
     275
     276        tmp = psDeproject(&lin, &proj);
     277        return(tmp);
     278    } else if (mode == PS_SPHERICAL) {
     279        psAbort(__func__, "Sperical offset modes are not defined.\n");
     280    }
     281    psAbort(__func__, "Unrecognized offset mode\n");
     282    return(NULL);
     283}
Note: See TracChangeset for help on using the changeset viewer.