Changeset 5483
- Timestamp:
- Nov 7, 2005, 10:52:43 AM (21 years ago)
- Location:
- trunk/psLib
- Files:
-
- 6 edited
-
src/astro/psEarthOrientation.c (modified) (10 diffs)
-
src/astro/psEarthOrientation.h (modified) (2 diffs)
-
src/astro/psSphereOps.h (modified) (5 diffs)
-
test/astro/tst_psEarthOrientation.c (modified) (3 diffs)
-
test/astro/verified/tst_psEarthOrientation.stderr (modified) (2 diffs)
-
test/astro/verified/tst_psEarthOrientation.stdout (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psEarthOrientation.c
r5466 r5483 9 9 * @author Robert Daniel DeSonia, MHPCC 10 10 * 11 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-11-0 3 04:31:22$11 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-11-07 20:52:43 $ 13 13 * 14 14 * Copyright 2005 Maui High Performance Computing Center, University of Hawaii … … 52 52 static bool eocInitialized = false; 53 53 54 static psSphereRot *rotMatrix_To_Quat(double A[3][3]); 55 56 static void earthPoleFree(psEarthPole *pole) 57 { 58 // There are non dynamic allocated items 59 } 60 61 psEarthPole *psEarthPoleAlloc(void) 62 { 63 psEarthPole* pole = psAlloc(sizeof(psEarthPole)); 64 psMemSetDeallocator(pole, (psFreeFunc) earthPoleFree); 65 return pole; 66 } 67 54 68 static bool eocInit() 55 69 { … … 139 153 psFree(xTable); 140 154 psFree(yTable); 141 psFree(sTable); 155 psFree(sTable); // There are non dynamic allocated items 156 142 157 143 158 xTable = NULL; … … 179 194 apparent->dErr = 0.0; 180 195 } 181 psSphere *rp = psSphereAlloc(); 182 psSphere *r_p = psSphereAlloc(); 196 // psSphere *rp = psSphereAlloc(); 197 psCube *rp = psCubeAlloc(); 198 // psSphere *r_p = psSphereAlloc(); 199 psCube *r_p = psCubeAlloc(); 183 200 double mu = 0.0; 184 201 double mu_p = 0.0; … … 188 205 // mu = apparent->r * direction->r + apparent->d * direction->d; 189 206 psCube* directionVector = psSphereToCube(direction); 207 if (directionVector == NULL) 208 printf("directionVector is null\n"); 190 209 psCube* actualVector = psSphereToCube(actual); 210 if (directionVector == NULL) 211 printf("actualVector is null\n"); 191 212 mu = acos(directionVector->x*actualVector->x + 192 213 directionVector->y*actualVector->y + … … 194 215 195 216 //rp = apparent - mu * direction; 196 rp->r = actual->r - mu * direction->r; 197 rp->d = actual->d - mu * direction->d; 217 // rp->r = actual->r - mu * direction->r; 218 // rp->d = actual->d - mu * direction->d; 219 rp->x = actualVector->x - mu * directionVector->x; 220 rp->y = actualVector->y - mu * directionVector->y; 221 rp->z = actualVector->z - mu * directionVector->z; 198 222 199 223 mu_p = mu + speed * ((mu * mu - 1.0) / (1.0 - speed * mu)); 200 224 201 225 //Not sure if this is right. ADD gets a scalar from division of rp (a vector) 202 psCube* rpVector = psSphereToCube(rp); 203 a = sqrt( (1.0 - mu_p * mu_p) / 204 (sqrt(rpVector->x*rpVector->x 205 + rpVector->y*rpVector->y 206 + rpVector->z*rpVector->z)) ); 207 226 //Paul claims rp is the modulus or square of the vector components 227 /* psCube* rpVector = psSphereToCube(rp); 228 a = sqrt( (1.0 - mu_p * mu_p) / ( rpVector->x*rpVector->x + 229 rpVector->y*rpVector->y + rpVector->z*rpVector->z) ); 230 */ 231 a = (1.0 - mu_p * mu_p) / (rp->x * rp->x + rp->y * rp->y + rp->z * rp->z); 232 if (a < 0.0) { 233 printf("a is negative\n"); 234 psFree(rp); 235 psFree(r_p); 236 psFree(directionVector); 237 psFree(actualVector); 238 psFree(apparent) 239 return NULL; 240 } else 241 a = sqrt(a); 208 242 //r_p = mu_p * direction + a * rp; 209 r_p->r = mu_p * direction->r + a * rp->r; 210 r_p->d = mu_p * direction->d + a * rp->d; 211 212 *apparent = *r_p; 243 // r_p->r = mu_p * direction->r + a * rp->r; 244 // r_p->d = mu_p * direction->d + a * rp->d; 245 r_p->x = mu_p * directionVector->x + a * rp->x; 246 r_p->y = mu_p * directionVector->y + a * rp->y; 247 r_p->z = mu_p * directionVector->z + a * rp->z; 248 249 psSphere *r_pSphere = psCubeToSphere(r_p); 250 if (r_pSphere == NULL) 251 printf("r_pSphere is null\n"); 252 253 *apparent = *r_pSphere; 213 254 /* 214 255 psSphereRot *rot = NULL; … … 223 264 psFree(rp); 224 265 psFree(r_p); 266 psFree(r_pSphere) 225 267 psFree(directionVector); 226 268 psFree(actualVector); 227 psFree(rpVector);269 // psFree(rpVector); 228 270 return apparent; 229 271 } … … 280 322 deflection = SEC_TO_RAD(deflection); 281 323 theta = atan(r0/PS_AU) * tan(deflection); 282 phi = sqrt( deflection*deflection - theta*theta ); 324 // phi = sqrt( deflection*deflection - theta*theta ); 325 phi = deflection * cos(asin(theta/deflection)); 283 326 apparent->r = theta; 284 327 apparent->d = phi; … … 447 490 } 448 491 492 static psSphereRot *rotMatrix_To_Quat(double A[3][3]) 493 { 494 int i; 495 psSphereRot *new = (psSphereRot*)psAlloc(sizeof(psSphereRot)); 496 // psMemSetDeallocator(new, (psFreeFunc)sphereRotFree); 497 //Convert rotation matrix to quaternions 498 double diag_sum[3]; 499 int maxi; 500 double recip; 501 diag_sum[0] = 1.0 + A[0][0] - A[1][1] - A[2][2]; 502 diag_sum[1] = 1.0 - A[0][0] + A[1][1] - A[2][2]; 503 diag_sum[2] = 1.0 - A[0][0] - A[1][1] + A[2][2]; 504 diag_sum[3] = 1.0 + A[0][0] + A[1][1] + A[2][2]; 505 506 maxi = 0; 507 for (i = 1; i < 4; ++i) { 508 if (diag_sum[i] > diag_sum[maxi]) { 509 maxi = i; 510 } 511 } 512 513 double p = 0.5 * sqrt(diag_sum[maxi]); 514 recip = 1.0 / (4.0 * p); 515 516 if (maxi == 0) { 517 new->q0 = p; 518 new->q1 = recip * (A[0][1] + A[1][0]); 519 new->q2 = recip * (A[2][0] + A[0][2]); 520 new->q3 = recip * (A[1][2] - A[2][1]); 521 } else if (maxi == 1) { 522 new->q0 = recip * (A[0][1] + A[1][0]); 523 new->q1 = p; 524 new->q2 = recip * (A[1][2] + A[2][1]); 525 new->q3 = recip * (A[2][0] - A[0][2]); 526 } else if (maxi == 2) { 527 new->q0 = recip * (A[2][0] + A[0][2]); 528 new->q1 = recip * (A[1][2] + A[2][1]); 529 new->q2 = p; 530 new->q3 = recip * (A[0][1] - A[1][0]); 531 } else if (maxi == 3) { 532 new->q0 = recip * (A[1][2] - A[2][1]); 533 new->q1 = recip * (A[2][0] - A[0][2]); 534 new->q2 = recip * (A[0][1] - A[1][0]); 535 new->q3 = p; 536 } 537 return new; 538 } 449 539 450 540 psSphereRot* psSphereRot_CEOtoGCRS(const psEarthPole *pole) 451 541 { 452 return NULL; 542 PS_ASSERT_PTR_NON_NULL(pole,NULL); 543 double A[3][3]; 544 psSphereRot *out = NULL; 545 546 //Setup the rotation matrix and scalar value, a, as outlined by the ADD 547 //XXX: Used formula for rotation matrix D from mathworld for z-axis rotation 548 double a = 1.0 / (1.0 + sqrt(1.0 - (pole->x*pole->x + pole->y*pole->y) ) ); 549 A[0][0] = (1.0 - a*pole->x*pole->x)*cos(pole->s) - a*pole->x*pole->y*sin(pole->s); 550 A[0][1] = -a*pole->x*pole->y*cos(pole->s) + (1.0 - a*pole->y*pole->y)*sin(pole->s); 551 A[0][2] = pole->x*cos(pole->s) + pole->y*sin(pole->s); 552 A[1][0] = -(1.0 - a*pole->x*pole->x)*sin(pole->s) - a*pole->x*pole->y*cos(pole->s); 553 A[1][1] = a*pole->x*pole->y*sin(pole->s) + (1.0 - a*pole->y*pole->y)*cos(pole->s); 554 A[1][2] = -pole->x*sin(pole->s) + pole->y*cos(pole->s); 555 A[2][0] = -pole->x; 556 A[2][1] = -pole->y; 557 A[2][2] = 1.0 - a*(pole->x*pole->x + pole->y*pole->y); 558 559 out = rotMatrix_To_Quat(A); 560 561 return out; 453 562 } 454 563 … … 495 604 psSphereRot* psSphereRot_ITRStoTEO(const psEarthPole* motion) 496 605 { 497 return NULL; 498 } 606 PS_ASSERT_PTR_NON_NULL(motion,NULL); 607 double A[3][3]; 608 psSphereRot *out = NULL; 609 610 //Setup Rotation Matrix for transformation (x,y,z rotation) 611 //XXX: May need to be (z,y,x as in Mathworld?) 612 A[0][0] = cos(motion->x)*cos(-motion->s); 613 A[0][1] = sin(motion->y)*sin(motion->x)*cos(-motion->s) + cos(motion->y)*sin(-motion->s); 614 A[0][2] = -cos(motion->y)*sin(motion->x)*cos(-motion->s) + sin(motion->y)*sin(-motion->s); 615 A[1][0] = -cos(motion->x)*sin(-motion->s); 616 A[1][1] = -sin(motion->y)*sin(motion->x)*sin(-motion->s) + cos(motion->y)*cos(-motion->s); 617 A[1][2] = cos(motion->y)*sin(motion->x)*sin(-motion->s) + sin(motion->y)*cos(-motion->s); 618 A[2][0] = sin(motion->x); 619 A[2][1] = -sin(motion->y)*cos(motion->x); 620 A[2][2] = cos(motion->y)*cos(motion->x); 621 622 //Convert rotation matrix to quaternions 623 double diag_sum[3]; 624 int maxi; 625 double recip; 626 diag_sum[0] = 1.0 + A[0][0] - A[1][1] - A[2][2]; 627 diag_sum[1] = 1.0 - A[0][0] + A[1][1] - A[2][2]; 628 diag_sum[2] = 1.0 - A[0][0] - A[1][1] + A[2][2]; 629 diag_sum[3] = 1.0 + A[0][0] + A[1][1] + A[2][2]; 630 631 maxi = 0; 632 for (int i = 1; i < 4; ++i) { 633 if (diag_sum[i] > diag_sum[maxi]) { 634 maxi = i; 635 } 636 } 637 638 double p = 0.5 * sqrt(diag_sum[maxi]); 639 recip = 1.0 / (4.0 * p); 640 641 if (maxi == 0) { 642 out->q0 = p; 643 out->q1 = recip * (A[0][1] + A[1][0]); 644 out->q2 = recip * (A[2][0] + A[0][2]); 645 out->q3 = recip * (A[1][2] - A[2][1]); 646 } else if (maxi == 1) { 647 out->q0 = recip * (A[0][1] + A[1][0]); 648 out->q1 = p; 649 out->q2 = recip * (A[1][2] + A[2][1]); 650 out->q3 = recip * (A[2][0] - A[0][2]); 651 } else if (maxi == 2) { 652 out->q0 = recip * (A[2][0] + A[0][2]); 653 out->q1 = recip * (A[1][2] + A[2][1]); 654 out->q2 = p; 655 out->q3 = recip * (A[0][1] - A[1][0]); 656 } else if (maxi == 3) { 657 out->q0 = recip * (A[1][2] - A[2][1]); 658 out->q1 = recip * (A[2][0] - A[0][2]); 659 out->q2 = recip * (A[0][1] - A[1][0]); 660 out->q3 = p; 661 } 662 663 return out; 664 } -
trunk/psLib/src/astro/psEarthOrientation.h
r5466 r5483 9 9 * @author Robert Daniel DeSonia, MHPCC 10 10 * 11 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-11-0 3 04:31:22$11 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-11-07 20:52:43 $ 13 13 * 14 14 * Copyright 2005 Maui High Performance Computing Center, University of Hawaii … … 44 44 } 45 45 psPrecessMethod; 46 47 /** Allocates a new psEarthPole structure. */ 48 psEarthPole *psEarthPoleAlloc(void); 46 49 47 50 /** Calculates the actual position of a star, given its apparent position and the -
trunk/psLib/src/astro/psSphereOps.h
r5444 r5483 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-1 0-25 00:38:00$9 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-11-07 20:52:43 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 186 186 * coordinate systems. 187 187 * 188 * @return psSphere Transform* transform for ICRS->Ecliptic coordinate systems188 * @return psSphereRot* transform for ICRS->Ecliptic coordinate systems 189 189 */ 190 190 psSphereRot* psSphereRotICRSToEcliptic( … … 195 195 * coordinate systems. 196 196 * 197 * @return psSphere Transform* transform for Ecliptic->ICRS coordinate systems197 * @return psSphereRot* transform for Ecliptic->ICRS coordinate systems 198 198 */ 199 199 psSphereRot* psSphereRotEclipticToICRS( … … 204 204 * coordinate systems. 205 205 * 206 * @return psSphereRot* new sphere rotation for ICRS to Galactic transformations. 206 207 */ 207 208 psSphereRot* psSphereRotICRSToGalactic(void); … … 210 211 * coordinate systems. 211 212 * 213 * @return psSphereRot* new sphere rotation for Galactic to ICRS transformations. 212 214 */ 213 215 psSphereRot* psSphereRotGalacticToICRS(void); -
trunk/psLib/test/astro/tst_psEarthOrientation.c
r5466 r5483 5 5 * @author d-Rob, MHPCC 6 6 * 7 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $8 * @date $Date: 2005-11-0 3 04:31:22$7 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-11-07 20:52:43 $ 9 9 * 10 10 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 63 63 psSphere *empty = NULL; 64 64 65 actual->r = 0.2; 66 actual->d = 0.2; 67 direction->r = 0.2035; 68 direction->d = 0.2035; 65 // actual->r = 0.2; 66 // actual->d = 0.2; 67 actual->r = DEG_TO_RAD(45.0); 68 actual->d = DEG_TO_RAD(30.0); 69 // direction->r = 0.2035; 70 // direction->d = 0.2035; 71 direction->r = DEG_TO_RAD(48.0); 72 direction->d = DEG_TO_RAD(20.7072); 69 73 70 74 empty = psAberration(empty, apparent, direction, 0.1); … … 82 86 83 87 apparent = psAberration(apparent, actual, direction, 0.4); 84 printf("\napparent = r,d = %.8g, %.8g\n", apparent->r, apparent->d); 88 if (apparent == NULL) 89 printf("\nApparent is NULL\n"); 90 else 91 printf("\napparent = r,d = %.8g, %.8g\n", apparent->r, apparent->d); 85 92 86 93 psFree(apparent); -
trunk/psLib/test/astro/verified/tst_psEarthOrientation.stderr
r5455 r5483 24 24 25 25 ---> TESTPOINT PASSED (psEarthOrientation{psGravityDeflect()} | tst_psEarthOrientation.c) 26 27 /***************************** TESTPOINT ******************************************\28 * TestFile: tst_psEarthOrientation.c *29 * TestPoint: psEarthOrientation{psEOCParallax()} *30 * TestType: Positive *31 \**********************************************************************************/32 33 34 ---> TESTPOINT PASSED (psEarthOrientation{psEOCParallax()} | tst_psEarthOrientation.c)35 26 36 27 /***************************** TESTPOINT ******************************************\ … … 63 54 /***************************** TESTPOINT ******************************************\ 64 55 * TestFile: tst_psEarthOrientation.c * 65 * TestPoint: psEarthOrientation{psSphereRot Transforms()}*56 * TestPoint: psEarthOrientation{psSphereRot_TEOtoCEO()} * 66 57 * TestType: Positive * 67 58 \**********************************************************************************/ 68 59 69 60 70 ---> TESTPOINT PASSED (psEarthOrientation{psSphereRot Transforms()} | tst_psEarthOrientation.c)61 ---> TESTPOINT PASSED (psEarthOrientation{psSphereRot_TEOtoCEO()} | tst_psEarthOrientation.c) 71 62 63 /***************************** TESTPOINT ******************************************\ 64 * TestFile: tst_psEarthOrientation.c * 65 * TestPoint: psEarthOrientation{psSphereRot_CEOtoGCRS()} * 66 * TestType: Positive * 67 \**********************************************************************************/ 68 69 70 ---> TESTPOINT PASSED (psEarthOrientation{psSphereRot_CEOtoGCRS()} | tst_psEarthOrientation.c) 71 72 /***************************** TESTPOINT ******************************************\ 73 * TestFile: tst_psEarthOrientation.c * 74 * TestPoint: psEarthOrientation{psSphereRRot_ITRStoTEO()} * 75 * TestType: Positive * 76 \**********************************************************************************/ 77 78 79 ---> TESTPOINT PASSED (psEarthOrientation{psSphereRRot_ITRStoTEO()} | tst_psEarthOrientation.c) 80 -
trunk/psLib/test/astro/verified/tst_psEarthOrientation.stdout
r5455 r5483 1 1 2 apparent = r,d = 0.10218436, 0.102184362 apparent = r,d = 1.2163241, 1.0535409 3 3 4 4 Actual r,d = 0.2035,0.2035 Apparent r,d = 0.2035000000002, 0.2035000000391 5 6 The Value of T is = 1128530000.931 7 8 The Value of T is = 1126078455.931 9 Output sphere rotation = 0.000000,0.000000,0.770554,0.637375
Note:
See TracChangeset
for help on using the changeset viewer.
