Changeset 4540 for trunk/psLib/src/astronomy/psCoord.c
- Timestamp:
- Jul 12, 2005, 9:12:01 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/astronomy/psCoord.c (modified) (13 diffs)
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);
Note:
See TracChangeset
for help on using the changeset viewer.
