IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 4, 2004, 1:37:39 PM (22 years ago)
Author:
desonia
Message:

found the server astyle upgrade was faulty, so the format was reset.

File:
1 edited

Legend:

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

    r1374 r1385  
    1010*  @author George Gusciora, MHPCC
    1111*
    12 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-08-04 00:55:17 $
     12*  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2004-08-04 23:37:39 $
    1414*
    1515*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3333{
    3434    if ( out == NULL ) {
    35             out = ( psPlane * ) psAlloc( sizeof( psPlane ) );
    36         }
     35        out = ( psPlane * ) psAlloc( sizeof( psPlane ) );
     36    }
    3737    out->x = transform->x->coeff[ 0 ][ 0 ] +
    3838             ( transform->x->coeff[ 1 ][ 0 ] * coords->x ) +
    3939             ( transform->x->coeff[ 0 ][ 1 ] * coords->y );
    40              
     40
    4141    out->y = transform->y->coeff[ 0 ][ 0 ] +
    4242             ( transform->y->coeff[ 1 ][ 0 ] * coords->x ) +
    4343             ( transform->y->coeff[ 0 ][ 1 ] * coords->y );
    44              
     44
    4545    return ( out );
    4646}
     
    5656{
    5757    if ( out == NULL ) {
    58             out = ( psPlane * ) psAlloc( sizeof( psPlane ) );
    59         }
    60        
     58        out = ( psPlane * ) psAlloc( sizeof( psPlane ) );
     59    }
     60
    6161    out->x = transform->x->coeff[ 0 ][ 0 ][ 0 ][ 0 ] +
    6262             ( transform->x->coeff[ 1 ][ 0 ][ 0 ][ 0 ] * coords->x ) +
     
    6464             ( transform->x->coeff[ 0 ][ 0 ][ 1 ][ 0 ] * term3 ) +
    6565             ( transform->x->coeff[ 0 ][ 0 ][ 0 ][ 1 ] * term4 );
    66              
     66
    6767    out->y = transform->y->coeff[ 0 ][ 0 ][ 0 ][ 0 ] +
    6868             ( transform->y->coeff[ 1 ][ 0 ][ 0 ][ 0 ] * coords->x ) +
     
    7070             ( transform->y->coeff[ 0 ][ 0 ][ 1 ][ 0 ] * term3 ) +
    7171             ( transform->y->coeff[ 0 ][ 0 ][ 0 ][ 1 ] * term4 );
    72              
     72
    7373    return ( out );
    7474}
     
    8181{
    8282    psSphereTransform * tmp = ( psSphereTransform * ) psAlloc( sizeof( psSphereTransform ) );
    83    
     83
    8484    tmp->sinPhi = sin( NPlat );
    8585    tmp->cosPhi = cos( NPlat );
    8686    tmp->Xo = Xo;
    8787    tmp->xo = xo;
    88    
     88
    8989    return ( tmp );
    9090}
     
    114114    double y = 0.0;
    115115    double dx = 0.0;
    116    
     116
    117117    if ( out == NULL ) {
    118             out = ( psSphere * ) psAlloc( sizeof( psSphere ) );
    119         }
    120        
     118        out = ( psSphere * ) psAlloc( sizeof( psSphere ) );
     119    }
     120
    121121    x = coord->r;
    122122    y = coord->d;
     
    127127           cos( y );
    128128    cosX = cos( y ) * cos( dx ) / cos( y );
    129    
     129
    130130    out->r = atan2( sinX, cosX ) + transform->Xo;
    131131    out->d = atan2( sinY, cosY );
    132    
     132
    133133    return ( out );
    134134}
     
    142142    double Xo = 0.0;
    143143    double xo = 0.0;
    144    
     144
    145145    return ( psSphereTransformAlloc( phi, Xo, xo ) );
    146146}
     
    154154    double Xo = 0.0;
    155155    double xo = 0.0;
    156    
     156
    157157    return ( psSphereTransformAlloc( phi, Xo, xo ) );
    158158}
     
    178178{
    179179    if ( x > 0 ) {
    180             return ( atan( y / x ) );
    181         } else if ( ( x == 0 ) && ( y == 0 ) ) {
     180        return ( atan( y / x ) );
     181    } else
     182        if ( ( x == 0 ) && ( y == 0 ) ) {
    182183            return ( 0.5 * M_PI );
    183         } else if ( ( x == 0 ) && ( y == 0 ) ) {
    184             return ( -0.5 * M_PI );
    185         } else if ( ( x == 0 ) && ( y == 0 ) ) {
    186             return ( M_PI + atan( y / x ) );
    187         } else if ( ( x == 0 ) && ( y == 0 ) ) {
    188             return ( -M_PI + atan( y / x ) );
    189         }
    190        
     184        } else
     185            if ( ( x == 0 ) && ( y == 0 ) ) {
     186                return ( -0.5 * M_PI );
     187            } else
     188                if ( ( x == 0 ) && ( y == 0 ) ) {
     189                    return ( M_PI + atan( y / x ) );
     190                } else
     191                    if ( ( x == 0 ) && ( y == 0 ) ) {
     192                        return ( -M_PI + atan( y / x ) );
     193                    }
     194
    191195    psAbort( __func__, "Unacceptable range for (arg(%f, %f).\n", x, y );
    192196    return ( 0.0 );
     
    201205    float alpha = 0.0;
    202206    psPlane *tmp = ( psPlane * ) psAlloc( sizeof( psPlane ) );
    203    
     207
    204208    if ( projection->type == PS_PROJ_TAN ) {
    205             R = cot( coord->r ) * ( 180.0 / M_PI );
    206             tmp->x = R * sin( coord->d );
    207             tmp->y = R * cos( coord->d );
    208            
    209         } else if ( projection->type == PS_PROJ_SIN ) {
     209        R = cot( coord->r ) * ( 180.0 / M_PI );
     210        tmp->x = R * sin( coord->d );
     211        tmp->y = R * cos( coord->d );
     212
     213    } else
     214        if ( projection->type == PS_PROJ_SIN ) {
    210215            R = cos( coord->r ) * ( 180.0 / M_PI );
    211216            tmp->x = R * sin( coord->d );
    212217            tmp->y = R * cos( coord->d );
    213            
    214         } else if ( projection->type == PS_PROJ_CAR ) {
    215             tmp->x = coord->d;
    216             tmp->y = coord->r;
    217            
    218         } else if ( projection->type == PS_PROJ_MER ) {
    219             tmp->x = coord->d;
    220             tmp->y = log( tan( 45.0 + ( 0.5 * coord->r ) ) ) * 180.0 / M_PI;
    221            
    222         } else if ( projection->type == PS_PROJ_AIT ) {
    223             alpha = 1.0 / ( ( 180.0 / M_PI ) *
    224                             sqrt( 1.0 + ( cos( coord->r ) * cos( 0.5 * coord->d ) * 0.5 ) ) );
    225                            
    226             tmp->x = 2.0 * alpha * cos( coord->r ) * sin( 0.5 * coord->d );
    227             tmp->y = alpha * sin( coord->d );
    228            
    229         } else if ( projection->type == PS_PROJ_PAR ) {
    230             psAbort( __func__, "The projection type PS_PROJ_PAR is undefined.\n" );
    231            
    232         } else if ( projection->type == PS_PROJ_GLS ) {
    233             psAbort( __func__, "The projection type PS_PROJ_GLS is undefined.\n" );
    234         }
    235        
     218
     219        } else
     220            if ( projection->type == PS_PROJ_CAR ) {
     221                tmp->x = coord->d;
     222                tmp->y = coord->r;
     223
     224            } else
     225                if ( projection->type == PS_PROJ_MER ) {
     226                    tmp->x = coord->d;
     227                    tmp->y = log( tan( 45.0 + ( 0.5 * coord->r ) ) ) * 180.0 / M_PI;
     228
     229                } else
     230                    if ( projection->type == PS_PROJ_AIT ) {
     231                        alpha = 1.0 / ( ( 180.0 / M_PI ) *
     232                                        sqrt( 1.0 + ( cos( coord->r ) * cos( 0.5 * coord->d ) * 0.5 ) ) );
     233
     234                        tmp->x = 2.0 * alpha * cos( coord->r ) * sin( 0.5 * coord->d );
     235                        tmp->y = alpha * sin( coord->d );
     236
     237                    } else
     238                        if ( projection->type == PS_PROJ_PAR ) {
     239                            psAbort( __func__, "The projection type PS_PROJ_PAR is undefined.\n" );
     240
     241                        } else
     242                            if ( projection->type == PS_PROJ_GLS ) {
     243                                psAbort( __func__, "The projection type PS_PROJ_GLS is undefined.\n" );
     244                            }
     245
    236246    return ( tmp );
    237247}
     
    247257    float chu2 = 0.0;
    248258    psSphere *tmp = ( psSphere * ) psAlloc( sizeof( psSphere ) );
    249    
     259
    250260    if ( projection->type == PS_PROJ_TAN ) {
    251             R = sqrt( ( coord->x * coord->x ) + ( coord->y * coord->y ) );
    252             tmp->d = arg( -coord->y, coord->x );
    253             tmp->r = atan( 180.0 / ( R * M_PI ) );
    254            
    255         } else if ( projection->type == PS_PROJ_SIN ) {
     261        R = sqrt( ( coord->x * coord->x ) + ( coord->y * coord->y ) );
     262        tmp->d = arg( -coord->y, coord->x );
     263        tmp->r = atan( 180.0 / ( R * M_PI ) );
     264
     265    } else
     266        if ( projection->type == PS_PROJ_SIN ) {
    256267            R = sqrt( ( coord->x * coord->x ) + ( coord->y * coord->y ) );
    257268            tmp->d = arg( -coord->y, coord->x );
    258269            tmp->r = acos( ( R * M_PI ) / 180.0 );
    259            
    260         } else if ( projection->type == PS_PROJ_CAR ) {
    261             tmp->d = coord->x;
    262             tmp->r = coord->y;
    263            
    264         } else if ( projection->type == PS_PROJ_MER ) {
    265             tmp->d = coord->x;
    266             tmp->r = ( 2.0 * atan( exp( ( coord->y * M_PI / 180.0 ) ) ) ) - 180.0;
    267            
    268         } else if ( projection->type == PS_PROJ_AIT ) {
    269             chu1 = ( coord->x * M_PI ) / 720.0;
    270             chu1 *= chu1;
    271             chu2 = ( coord->y * M_PI ) / 360.0;
    272             chu2 *= chu2;
    273             chu = sqrt( 1.0 - chu1 - chu2 );
    274             tmp->d = 2.0 * arg( ( 2.0 * chu * chu ) - 1.0,
    275                                 ( coord->x * chu * M_PI ) / 360.0 );
    276             tmp->r = asin( ( coord->y * chu * M_PI ) / 180.0 );
    277            
    278         } else if ( projection->type == PS_PROJ_PAR ) {
    279             psAbort( __func__, "The projection type PS_PROJ_PAR is undefined.\n" );
    280            
    281         } else if ( projection->type == PS_PROJ_GLS ) {
    282             psAbort( __func__, "The projection type PS_PROJ_GLG is undefined.\n" );
    283         }
    284        
     270
     271        } else
     272            if ( projection->type == PS_PROJ_CAR ) {
     273                tmp->d = coord->x;
     274                tmp->r = coord->y;
     275
     276            } else
     277                if ( projection->type == PS_PROJ_MER ) {
     278                    tmp->d = coord->x;
     279                    tmp->r = ( 2.0 * atan( exp( ( coord->y * M_PI / 180.0 ) ) ) ) - 180.0;
     280
     281                } else
     282                    if ( projection->type == PS_PROJ_AIT ) {
     283                        chu1 = ( coord->x * M_PI ) / 720.0;
     284                        chu1 *= chu1;
     285                        chu2 = ( coord->y * M_PI ) / 360.0;
     286                        chu2 *= chu2;
     287                        chu = sqrt( 1.0 - chu1 - chu2 );
     288                        tmp->d = 2.0 * arg( ( 2.0 * chu * chu ) - 1.0,
     289                                            ( coord->x * chu * M_PI ) / 360.0 );
     290                        tmp->r = asin( ( coord->y * chu * M_PI ) / 180.0 );
     291
     292                    } else
     293                        if ( projection->type == PS_PROJ_PAR ) {
     294                            psAbort( __func__, "The projection type PS_PROJ_PAR is undefined.\n" );
     295
     296                        } else
     297                            if ( projection->type == PS_PROJ_GLS ) {
     298                                psAbort( __func__, "The projection type PS_PROJ_GLG is undefined.\n" );
     299                            }
     300
    285301    return ( tmp );
    286302}
     
    298314    double tmpR = 0.0;
    299315    double tmpD = 0.0;
    300    
     316
    301317    if ( mode == PS_LINEAR ) {
    302             // XXX: I have no idea how to construct this.  Maybe project both
    303             // sperical positions onto the plane, set the origin at one of the
    304             // points on the plane, then deproject?
    305            
    306             // XXX: Do I need to somehow scale this projection?
    307             // project position1?  Will it project to (0.0, 0.0)?
    308             proj.R = position1->r;
    309             proj.D = position1->d;
    310             proj.Xs = 1.0;
    311             proj.Ys = 1.0;
    312             proj.type = PS_PROJ_TAN;
    313            
    314             //        lin = psProject(position2, proj);
    315             //        tmp = psDeproject(lin, proj);
    316            
    317             // XXX: Do we need to convert units in tmp?
    318             return ( tmp );
    319         } else if ( mode == PS_SPHERICAL ) {
     318        // XXX: I have no idea how to construct this.  Maybe project both
     319        // sperical positions onto the plane, set the origin at one of the
     320        // points on the plane, then deproject?
     321
     322        // XXX: Do I need to somehow scale this projection?
     323        // project position1?  Will it project to (0.0, 0.0)?
     324        proj.R = position1->r;
     325        proj.D = position1->d;
     326        proj.Xs = 1.0;
     327        proj.Ys = 1.0;
     328        proj.type = PS_PROJ_TAN;
     329
     330        //        lin = psProject(position2, proj);
     331        //        tmp = psDeproject(lin, proj);
     332
     333        // XXX: Do we need to convert units in tmp?
     334        return ( tmp );
     335    } else
     336        if ( mode == PS_SPHERICAL ) {
    320337            tmpR = position2->r - position1->r;
    321338            tmpD = position2->d - position1->d;
    322            
     339
    323340            if ( unit == PS_ARCSEC ) {
    324                     tmpR = ( tmpR * 180.0 * 60.0 * 60.0 ) / M_PI;
    325                     tmpD = ( tmpR * 180.0 * 60.0 * 60.0 ) / M_PI;
    326                 } else if ( unit == PS_ARCMIN ) {
     341                tmpR = ( tmpR * 180.0 * 60.0 * 60.0 ) / M_PI;
     342                tmpD = ( tmpR * 180.0 * 60.0 * 60.0 ) / M_PI;
     343            } else
     344                if ( unit == PS_ARCMIN ) {
    327345                    tmpR = ( tmpR * 180.0 * 60.0 ) / M_PI;
    328346                    tmpD = ( tmpR * 180.0 * 60.0 ) / M_PI;
    329                 } else if ( unit == PS_DEGREE ) {
    330                     tmpR = ( tmpR * 180.0 ) / M_PI;
    331                     tmpD = ( tmpR * 180.0 ) / M_PI;
    332                 } else if ( unit == PS_RADIAN ) {}
    333             else {
    334                     psAbort( __func__, "Unknown offset unit: 0x%x\n", unit );
    335                 }
    336                
     347                } else
     348                    if ( unit == PS_DEGREE ) {
     349                        tmpR = ( tmpR * 180.0 ) / M_PI;
     350                        tmpD = ( tmpR * 180.0 ) / M_PI;
     351                    } else
     352                    if ( unit == PS_RADIAN ) {}
     353                        else {
     354                            psAbort( __func__, "Unknown offset unit: 0x%x\n", unit );
     355                        }
     356
    337357            tmp = ( psSphere * ) psAlloc( sizeof( psSphere ) );
    338358            tmp->r = tmpR;
     
    361381    double tmpR = 0.0;
    362382    double tmpD = 0.0;
    363    
     383
    364384    if ( mode == PS_LINEAR ) {
    365             proj.R = position->r;
    366             proj.D = position->d;
    367             proj.Xs = 1.0;
    368             proj.Ys = 1.0;
    369             proj.type = PS_PROJ_TAN;
    370            
    371             lin.x = offset->r;
    372             lin.y = offset->d;
    373            
    374             tmp = psDeproject( &lin, &proj );
    375             return ( tmp );
    376            
    377         } else if ( mode == PS_SPHERICAL ) {
     385        proj.R = position->r;
     386        proj.D = position->d;
     387        proj.Xs = 1.0;
     388        proj.Ys = 1.0;
     389        proj.type = PS_PROJ_TAN;
     390
     391        lin.x = offset->r;
     392        lin.y = offset->d;
     393
     394        tmp = psDeproject( &lin, &proj );
     395        return ( tmp );
     396
     397    } else
     398        if ( mode == PS_SPHERICAL ) {
    378399            if ( unit == PS_ARCSEC ) {
    379                     tmpR = ( M_PI * offset->r ) / ( 180.0 * 60.0 * 60.0 );
    380                     tmpD = ( M_PI * offset->d ) / ( 180.0 * 60.0 * 60.0 );
    381                 } else if ( unit == PS_ARCMIN ) {
     400                tmpR = ( M_PI * offset->r ) / ( 180.0 * 60.0 * 60.0 );
     401                tmpD = ( M_PI * offset->d ) / ( 180.0 * 60.0 * 60.0 );
     402            } else
     403                if ( unit == PS_ARCMIN ) {
    382404                    tmpR = ( M_PI * offset->r ) / ( 180.0 * 60.0 );
    383405                    tmpD = ( M_PI * offset->d ) / ( 180.0 * 60.0 );
    384                 } else if ( unit == PS_DEGREE ) {
    385                     tmpR = ( M_PI * offset->r ) / ( 180.0 );
    386                     tmpD = ( M_PI * offset->d ) / ( 180.0 );
    387                 } else if ( unit == PS_RADIAN ) {
    388                     tmpR = offset->r;
    389                     tmpD = offset->d;
    390                 } else {
    391                     psAbort( __func__, "Unknown offset unit: 0x%x\n", unit );
    392                 }
    393                
     406                } else
     407                    if ( unit == PS_DEGREE ) {
     408                        tmpR = ( M_PI * offset->r ) / ( 180.0 );
     409                        tmpD = ( M_PI * offset->d ) / ( 180.0 );
     410                    } else
     411                        if ( unit == PS_RADIAN ) {
     412                            tmpR = offset->r;
     413                            tmpD = offset->d;
     414                        } else {
     415                            psAbort( __func__, "Unknown offset unit: 0x%x\n", unit );
     416                        }
     417
    394418            tmp = ( psSphere * ) psAlloc( sizeof( psSphere ) );
    395419            tmp->r = position->r + tmpR;
     
    397421            tmp->rErr = 0.0;
    398422            tmp->dErr = 0.0;
    399            
     423
    400424            // XXX: wrap tmp->r and tmp->d to the allowed range (-PI to PI)
    401425            // and (0 to 2*PI).
Note: See TracChangeset for help on using the changeset viewer.