Changeset 4540 for trunk/psLib/src/astronomy
- Timestamp:
- Jul 12, 2005, 9:12:01 AM (21 years ago)
- Location:
- trunk/psLib/src/astronomy
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astronomy/psCoord.c
r4401 r4540 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1.7 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-0 6-27 20:38:11$12 * @version $Revision: 1.79 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-07-12 19:12:00 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 30 30 #include <math.h> 31 31 #include <float.h> 32 /******************************************************************************/33 /* DEFINE STATEMENTS */34 /******************************************************************************/35 32 36 33 // Modified Julian Day 01/01/1900 00:00:00 … … 40 37 #define JULIAN_CENTURY 36525.0 41 38 42 /******************************************************************************/43 /* TYPE DEFINITIONS */44 /******************************************************************************/45 46 // None47 48 /*****************************************************************************/49 /* GLOBAL VARIABLES */50 /*****************************************************************************/51 52 // None53 54 /*****************************************************************************/55 /* FILE STATIC VARIABLES */56 /*****************************************************************************/57 58 // None59 60 /*****************************************************************************/61 /* FUNCTION IMPLEMENTATION - LOCAL */62 /*****************************************************************************/63 64 /*****************************************************************************/65 /* FUNCTION IMPLEMENTATION - PUBLIC */66 /*****************************************************************************/67 39 static void planeFree(psPlane *p) 68 40 { 69 41 // There are non dynamic allocated items 42 } 43 44 static void sphereFree(psSphere *s) 45 { 46 // There are non dynamic allocated items 47 } 48 49 static void planeTransformFree(psPlaneTransform *pt) 50 { 51 psFree(pt->x); 52 psFree(pt->y); 53 } 54 55 static void planeDistortFree(psPlaneDistort *pt) 56 { 57 psFree(pt->x); 58 psFree(pt->y); 59 } 60 61 static void projectionFree(psProjection *p) 62 { 63 // There are no dynamically allocated items 70 64 } 71 65 … … 201 195 } 202 196 203 204 static void sphereFree(psSphere *s)205 {206 // There are non dynamic allocated items207 }208 209 197 psSphere* psSphereAlloc(void) 210 198 { … … 215 203 } 216 204 217 static void planeTransformFree(psPlaneTransform *pt) 218 { 219 psFree(pt->x); 220 psFree(pt->y); 205 psSphereRot* 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 228 psSphereRot* 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; 221 242 } 222 243 … … 260 281 261 282 return (out); 262 }263 264 static void planeDistortFree(psPlaneDistort *pt)265 {266 psFree(pt->x);267 psFree(pt->y);268 283 } 269 284 … … 319 334 320 335 /****************************************************************************** 321 alpha is LONGITUDE322 delta is LATITUDE323 324 alphaP: Take the target pole in the source system; calculate its LONGITUDE325 in the target system. That longitude is alphaP.326 DeltaP: Take the target pole in the source system; calculate its LATITUDE327 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 /******************************************************************************362 336 XXX: We convert Right Ascension angles to the range 0:PI. Is that acceptable? 363 337 XXX: Should we do something for Declination as well? 364 338 *****************************************************************************/ 365 psSphere* psSphere TransformApply(psSphere* out,366 const psSphereTransform* transform,367 const psSphere* coord)339 psSphere* psSphereRotApply(psSphere* out, 340 const psSphereRot* transform, 341 const psSphere* coord) 368 342 { 369 343 PS_ASSERT_PTR_NON_NULL(transform, NULL); … … 371 345 372 346 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 365 psSphereRot* 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 394 psSphereRot *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 406 psSphereRot* psSphereRotICRSToEcliptic(const psTime *time) 395 407 { 396 408 psF64 T; … … 421 433 422 434 // Don't neglect the minus sign on deltaP (bug 244): 423 return (psSphere TransformAlloc(alphaP, deltaP, phiP));424 } 425 426 427 psSphere Transform* psSphereTransformEclipticToICRS(psTime *time)435 return (psSphereRotAlloc(alphaP, deltaP, phiP)); 436 } 437 438 439 psSphereRot* psSphereRotEclipticToICRS(const psTime *time) 428 440 { 429 441 psF64 T; … … 453 465 psF64 phiP = 0.0; 454 466 455 return (psSphere TransformAlloc(alphaP, -deltaP, phiP));467 return (psSphereRotAlloc(alphaP, -deltaP, phiP)); 456 468 } 457 469 458 470 // XXX: This is bug 245: alphaP swaps with phiP from psSphereTransformGalacticToICRS() 459 psSphere Transform* psSphereTransformGalacticToICRS(void)471 psSphereRot* psSphereRotGalacticToICRS(void) 460 472 { 461 473 psF64 alphaP = DEG_TO_RAD(32.93192); … … 463 475 psF64 phiP = DEG_TO_RAD(282.85948); 464 476 465 return (psSphere TransformAlloc(alphaP, deltaP, phiP));466 } 467 468 psSphere Transform* psSphereTransformICRSToGalactic(void)477 return (psSphereRotAlloc(alphaP, deltaP, phiP)); 478 } 479 480 psSphereRot* psSphereRotICRSToGalactic(void) 469 481 { 470 482 psF64 alphaP = DEG_TO_RAD(282.85948); … … 472 484 psF64 phiP = DEG_TO_RAD(32.93192); 473 485 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)); 480 487 } 481 488 … … 837 844 838 845 // Create transform with proper constants 839 psSphere Transform *tmpST = psSphereTransformAlloc(alphaP, deltaP, phiP);846 psSphereRot* tmpST = psSphereRotAlloc(alphaP, deltaP, phiP); 840 847 841 848 // Apply transform to coordinates 842 psSphere *out = psSphere TransformApply(NULL, tmpST, coords);849 psSphere *out = psSphereRotApply(NULL, tmpST, coords); 843 850 844 851 psFree(tmpST); -
trunk/psLib/src/astronomy/psCoord.h
r4401 r4540 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1.3 7$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-0 6-27 20:38:11$12 * @version $Revision: 1.38 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-07-12 19:12:00 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 24 24 #include "psList.h" 25 25 #include "psFunctions.h" 26 #include "psTime.h" 26 // N.B. inclusion of psTime.h was done to after the typedefs to handle cross-dependency of typedefs 27 27 28 28 /// @addtogroup CoordinateTransform … … 38 38 typedef struct 39 39 { 40 double x; ///< x position41 double y; ///< y position42 double xErr; ///< Error in x position43 double yErr; ///< Error in y position40 double x; ///< x position 41 double y; ///< y position 42 double xErr; ///< Error in x position 43 double yErr; ///< Error in y position 44 44 } 45 45 psPlane; … … 52 52 * 53 53 */ 54 typedef struct psSphere55 { 56 double r; ///< RA57 double d; ///< Dec58 double rErr; ///< Error in RA59 double dErr; ///< Error in Dec54 typedef struct 55 { 56 double r; ///< RA 57 double d; ///< Dec 58 double rErr; ///< Error in RA 59 double dErr; ///< Error in Dec 60 60 } 61 61 psSphere; 62 63 /** Cubic Coordinate System 64 * 65 */ 66 typedef struct 67 { 68 double x; ///< cos (DEC) cos (RA) 69 double y; ///< cos (DEC) sic (RA) 70 double z; ///< sin (DEC) 71 double xErr; ///< Error in x 72 double yErr; ///< Error in y 73 double zErr; ///< Error in z 74 } 75 psCube; 76 77 /** Spherical rotations represent coordinate transformation in 3-D, as well as 78 * the effects of precession and nutation. The structure contains the 79 * elements of a quaternion to represent the spherical rotational. 80 * 81 */ 82 typedef struct 83 { 84 double q0; ///< first element of the quaternion 85 double q1; ///< second element of the quaternion 86 double q2; ///< third element of the quaternion 87 double q3; ///< fourth element of the quaternion 88 } 89 psSphereRot; 62 90 63 91 /** 2D Polynomial Transform … … 94 122 } 95 123 psPlaneDistort; 96 97 /** Spherical Transform Definition98 *99 * We need to be able to convert between ICRS, Galactic and Ecliptic100 * coordinates, and potentially between arbitrary spherical coordinate101 * systems. All of these basic spherical transformations represent rotations102 * of the spherical coordinate reference. We specify a general103 * transformation function which takes a structure, psSphereTransform,104 * defining the transformation between two spherical coordinate systems105 *106 */107 typedef struct108 {109 double alphaP; ///< Longitude of the target system pole in the source system110 double cosDeltaP; ///< Cosine of target pole latitude in the source system111 double sinDeltaP; ///< Sine of target pole latitude in the source system112 double phiP; ///< Longitude of the ascending node in the target system113 }114 psSphereTransform;115 124 116 125 /** Projection type for projection/deprojection … … 167 176 } psSphereOffsetUnit; 168 177 178 #include "psTime.h" 179 169 180 /** Allocates a psPlane 170 181 * … … 178 189 * @return psSphere* resulting sphere structure. 179 190 */ 180 181 191 psSphere* psSphereAlloc(void); 182 192 193 /** psSphereRot allocator which defines the rotation in terms of the coordinate 194 * of the pole and the rotation about that pole. 195 * 196 * @return psSphereRot* Newly allocated psSphereRot object 197 */ 198 psSphereRot* psSphereRotAlloc( 199 double alphaP, 200 double deltaP, 201 double phiP 202 ); 203 204 /** psSphereRot allocator which defines the rotation from the elements of the 205 * quaternion. 206 * 207 * @return psSphereRot* Newly allocated psSphereRot object 208 */ 209 psSphereRot* psSphereRotQuat( 210 double q0, 211 double q1, 212 double q2, 213 double q3 214 ); 183 215 184 216 /** Allocates a psPlaneTransform transform. … … 186 218 * @return psPlaneTransform* resulting plane transform 187 219 */ 188 189 220 psPlaneTransform* psPlaneTransformAlloc( 190 221 int n1, ///< The order of the x term in the transform. … … 227 258 ); 228 259 229 /** Allocator for psSphereTransform 230 * 231 * @return psSphereTransform* newly allocated struct 232 */ 233 234 psSphereTransform* psSphereTransformAlloc( 235 double alphaP, ///< north pole latitude 236 double deltaP, ///< north pole longitude? 237 double phiP ///< defines the longitude in the input system of the equatorial intersection between the two systems (e.g, the first point of Ares). 238 ); 239 240 /** Applies the psSphereTransform transform for a specified coordinate 260 261 /** Applies the psSphereRot transform for a specified coordinate 241 262 * 242 263 * @return psSphere* resulting coordinate based on transform 243 264 */ 244 psSphere* psSphere TransformApply(265 psSphere* psSphereRotApply( 245 266 psSphere* out, ///< a psSphere to recycle. If NULL, a new one is generated. 246 const psSphere Transform* transform,///< the transform to apply267 const psSphereRot* transform, ///< the transform to apply 247 268 const psSphere* coord ///< the coordinate to apply the transform above.x 269 ); 270 271 /** Combines two rotations to produce a single rotation which is equivalent of 272 * applying the first rotation and then the second. 273 * 274 * @return psSphereRot* new psSphereRot transform 275 */ 276 psSphereRot* psSphereRotCombine( 277 psSphereRot* out, 278 const psSphereRot* rot1, 279 const psSphereRot* rot2 280 ); 281 282 /** Inverts a psSphereRot's rotation. 283 * 284 * @return psSphereRot* The inverted psSphereRot 285 */ 286 psSphereRot* psSphereRotInvert( 287 psSphereRot* rot ///< the psSphereRot to invert 248 288 ); 249 289 … … 251 291 * coordinate systems. 252 292 * 253 * @return psSphere Transform*transform for ICRS->Ecliptic coordinate systems254 */ 255 psSphere Transform* psSphereTransformICRSToEcliptic(256 psTime *time///< the time for which the resulting transform will be valid293 * @return psSphereRot* transform for ICRS->Ecliptic coordinate systems 294 */ 295 psSphereRot* psSphereRotICRSToEcliptic( 296 const psTime* time ///< the time for which the resulting transform will be valid 257 297 ); 258 298 … … 260 300 * coordinate systems. 261 301 * 262 * @return psSphere Transform*transform for Ecliptic->ICRS coordinate systems263 */ 264 psSphere Transform* psSphereTransformEclipticToICRS(265 psTime *time///< the time for which the resulting transform will be valid302 * @return psSphereRot* transform for Ecliptic->ICRS coordinate systems 303 */ 304 psSphereRot* psSphereRotEclipticToICRS( 305 const psTime* time ///< the time for which the resulting transform will be valid 266 306 ); 267 307 … … 270 310 * 271 311 */ 272 psSphere Transform* psSphereTransformICRSToGalactic(void);312 psSphereRot* psSphereRotICRSToGalactic(void); 273 313 274 314 /** Creates the appropriate transform for converting from Galactic to ICRS … … 276 316 * 277 317 */ 278 psSphere Transform* psSphereTransformGalacticToICRS(void);318 psSphereRot* psSphereRotGalacticToICRS(void); 279 319 280 320 /** Allocates memory for a psProjection structure -
trunk/psLib/src/astronomy/psTime.c
r4409 r4540 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1.6 5$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-0 6-28 20:17:52$12 * @version $Revision: 1.66 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-07-12 19:12:00 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 887 887 } 888 888 889 structpsSphere* p_psTimeGetPoleCoords(const psTime* time)889 psSphere* p_psTimeGetPoleCoords(const psTime* time) 890 890 { 891 891 psU32 nTables = 3; … … 896 896 psF64 c = 0.0; 897 897 psF64 mjdPred = 0.0; 898 structpsSphere* output = NULL;898 psSphere* output = NULL; 899 899 psLookupStatusType xStatus = PS_LOOKUP_SUCCESS; 900 900 psLookupStatusType yStatus = PS_LOOKUP_SUCCESS; … … 908 908 PS_ASSERT_INT_WITHIN_RANGE(time->nsec,0,(psU32)((1e9)-1),NULL); 909 909 910 if(time->type != PS_TIME_TAI) 911 { 910 if(time->type != PS_TIME_TAI) { 912 911 psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_TYPE_INCORRECT, time->type); 913 912 return NULL; … … 922 921 923 922 // Value could not be found through table lookup and interpolation 924 if(xStatus==PS_LOOKUP_PAST_TOP && yStatus==PS_LOOKUP_PAST_TOP) 925 { 923 if(xStatus==PS_LOOKUP_PAST_TOP && yStatus==PS_LOOKUP_PAST_TOP) { 926 924 927 925 // Date too earlier for tables. Get default polar coodinate values from metadata, and issue warning. … … 942 940 y = tableMetadataItem->data.F64; 943 941 944 } else if(xStatus==PS_LOOKUP_PAST_BOTTOM && yStatus==PS_LOOKUP_PAST_BOTTOM) 945 { 942 } else if(xStatus==PS_LOOKUP_PAST_BOTTOM && yStatus==PS_LOOKUP_PAST_BOTTOM) { 946 943 947 944 /* Date too late for tables. Issue warning and use following formulae for predicting … … 1000 997 yp->data.F64[4]*sin(c); 1001 998 1002 } else if(xStatus!=PS_LOOKUP_SUCCESS || yStatus!=PS_LOOKUP_SUCCESS) 1003 { 999 } else if(xStatus!=PS_LOOKUP_SUCCESS || yStatus!=PS_LOOKUP_SUCCESS) { 1004 1000 psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_INTERPOLATION_FAILED); 1005 1001 return NULL; -
trunk/psLib/src/astronomy/psTime.h
r4409 r4540 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.3 3$ $Name: not supported by cvs2svn $14 * @date $Date: 2005-0 6-28 20:17:52$13 * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2005-07-12 19:12:00 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 25 25 26 26 #include "psType.h" 27 #include "psImage.h" 28 29 struct psSphere; 27 // N.B. inclusion of psCoord.h was done to after the typedefs to handle cross-dependency of typedefs 30 28 31 29 /// @addtogroup Time 32 30 /// @{ 33 34 31 35 32 /** Time type. … … 69 66 psTime; 70 67 68 #include "psCoord.h" 69 #include "psImage.h" 71 70 72 71 /** Initialize time data. … … 161 160 * @return psSphere*: Spherical coordinates of Earth's polar axias. 162 161 */ 163 structpsSphere* p_psTimeGetPoleCoords(164 const psTime *time ///< psTime determine polar orientation.165 );162 psSphere* p_psTimeGetPoleCoords( 163 const psTime *time ///< psTime determine polar orientation. 164 ); 166 165 167 166 /** Calculate the number of leapseconds between two times.
Note:
See TracChangeset
for help on using the changeset viewer.
