IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 21, 2005, 3:35:49 PM (21 years ago)
Author:
evanalst
Message:

Updates for psSphereGetOffset and psSphereSetOffset.

File:
1 edited

Legend:

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

    r3450 r3470  
    1010*  @author GLG, MHPCC
    1111*
    12 *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2005-03-18 21:34:43 $
     12*  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2005-03-22 01:35:49 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    396396void projectionFree(psProjection *p)
    397397{
    398     psFree(p);
     398    // There are no dynamically allocated items
    399399}
    400400
     
    413413    p->type = type;
    414414
    415     p_psMemSetDeallocator(p, (psFreeFcn) planeFree);
     415    p_psMemSetDeallocator(p, (psFreeFcn) projectionFree);
    416416    return(p);
    417417}
     
    547547    PS_PTR_CHECK_NULL(position2, NULL);
    548548
     549    // Check positions near 90 degree and issue warnings if necessary
    549550    if (position1->d >= DEG_TO_RAD(90.0)) {
    550         psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): position1->d is larger than 90 degrees.  Returning NULL.\n");
    551         return(NULL);
     551        psLogMsg(__func__, PS_LOG_WARN,
     552                 "WARNING: psDeproject(): position1->d is larger than 90 degrees.  Returning NULL.");
     553        return NULL;
    552554    }
    553555    if (position2->d >= DEG_TO_RAD(90.0)) {
    554         psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): position2->d is larger than 90 degrees.  Returning NULL.\n");
    555         return(NULL);
    556     }
    557 
    558     psPlane* lin;
    559     psProjection proj;
    560     psSphere* tmp;
    561 
     556        psLogMsg(__func__, PS_LOG_WARN,
     557                 "WARNING: psDeproject(): position2->d is larger than 90 degrees.  Returning NULL.");
     558        return NULL;
     559    }
     560
     561    // Allocate return structure
     562    psSphere* tmp = psSphereAlloc();
     563
     564    // Mode is LINEAR - Use first position as projection center and project second point
     565    // onto tangent plane, set point projected into psSphere structure x->r y->d
    562566    if (mode == PS_LINEAR) {
    563         proj.R = position1->r;
    564         proj.D = position1->d;
    565         proj.Xs = 1.0;
    566         proj.Ys = 1.0;
    567         proj.type = PS_PROJ_TAN;
    568 
    569         lin = psProject(position1, &proj);
    570         lin = psProject(position2, &proj);
    571         tmp = psDeproject(lin, &proj);
     567        psProjection* proj = psProjectionAlloc(position1->r,
     568                                               position1->d,
     569                                               1.0,
     570                                               1.0,
     571                                               PS_PROJ_TAN);
     572
     573        // Perform projection onto tangent plane
     574        psPlane* lin = psProject(position2, proj);
     575
     576        // Set return values
     577        tmp->r = lin->x;
     578        tmp->d = lin->y;
     579
     580        // Free data structures allocated
     581        psFree(proj);
    572582        psFree(lin);
    573         // XXX: Do we need to convert units in tmp?
    574         return (tmp);
     583
     584        // Mode is SPHERICAL - Get difference between positiion 1 and position 2 and convert
     585        // offset value from radians to desired units and return
    575586    } else if (mode == PS_SPHERICAL) {
    576         tmp = (psSphere* ) psAlloc(sizeof(psSphere));
    577587        tmp->r = position2->r - position1->r;
    578588        tmp->d = position2->d - position1->d;
     
    585595        tmp->dErr = 0.0;
    586596
     597        // Convert to desired units
    587598        if (unit == PS_ARCSEC) {
    588599            tmp->r = RAD_TO_SEC(tmp->r);
     
    600611                    unit);
    601612            psFree(tmp);
    602             return(NULL);
     613            return NULL;
    603614        }
    604 
    605         return (tmp);
    606     }
    607 
    608     psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    609             PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN,
    610             mode);
    611     return (NULL);
     615        // Invalid mode
     616    } else {
     617
     618        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     619                PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN,
     620                mode);
     621        psFree(tmp);
     622        return NULL;
     623    }
     624
     625    // Return value
     626    return tmp;
    612627}
    613628
     
    631646    PS_PTR_CHECK_NULL(offset, NULL);
    632647
    633     psPlane lin;
    634648    psSphere* tmp;
    635     psProjection proj;
    636649    psF64 tmpR = 0.0;
    637650    psF64 tmpD = 0.0;
    638651
     652    // If mode is linear then set position to projection center
     653    // and offset to linear coordinate then deproject to obtain
     654    // new sphere coordinate
    639655    if (mode == PS_LINEAR) {
    640         proj.R = position->r;
    641         proj.D = position->d;
    642         proj.Xs = 1.0;
    643         proj.Ys = 1.0;
    644         proj.type = PS_PROJ_TAN;
    645 
    646         lin.x = offset->r;
    647         lin.y = offset->d;
    648 
    649         tmp = psDeproject(&lin, &proj);
    650         return (tmp);
     656
     657        // Allocate plane coordinate and set coordinate
     658        psPlane*  lin = psPlaneAlloc();
     659        lin->x = offset->r;
     660        lin->y = offset->d;
     661
     662        // Allocate and set projection structure
     663        psProjection* proj = psProjectionAlloc(position->r,
     664                                               position->d,
     665                                               1.0,
     666                                               1.0,
     667                                               PS_PROJ_TAN);
     668
     669        // Project tangent plane coord to spherical coord
     670        tmp = psDeproject(lin, proj);
     671
     672        // Free data structures used
     673        psFree(proj);
     674        psFree(lin);
     675
     676        // If mode is spherical then convert offset to radians, add the offset
     677        // to the position and wrap to 0 to 2pi
    651678    } else if (mode == PS_SPHERICAL) {
     679
     680        // Convert offset unit to radians
    652681        if (unit == PS_ARCSEC) {
    653682            tmpR = SEC_TO_RAD(offset->r);
     
    666695                    PS_ERRORTEXT_psCoord_UNITS_UNKNOWN,
    667696                    unit);
    668             return(NULL);
     697            return NULL;
    669698        }
    670699
    671         tmp = (psSphere* ) psAlloc(sizeof(psSphere));
     700        // Allocate sphere structure to return
     701        tmp = psSphereAlloc();
     702
     703        // Add offset and wrap to 0 to 2PI if necessary
    672704        tmp->r = position->r + tmpR;
    673705        tmp->r = fmod(tmp->r, 2.0*PS_PI);
     
    677709        tmp->dErr = 0.0;
    678710
    679         return (tmp);
    680     }
    681 
    682     psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    683             PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN,
    684             mode);
    685 
    686     return (NULL);
     711        // Invalid mode report error
     712    } else {
     713
     714        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     715                PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN,
     716                mode);
     717        return NULL;
     718    }
     719
     720    return tmp;
    687721}
    688722
Note: See TracChangeset for help on using the changeset viewer.