Changeset 2983 for trunk/psLib/test/astronomy/tst_psCoord.c
- Timestamp:
- Jan 13, 2005, 12:45:40 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/astronomy/tst_psCoord.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/astronomy/tst_psCoord.c
r2932 r2983 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-01- 08 00:12:44$8 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-01-13 22:45:40 $ 10 10 * 11 11 * XXX: Must test psSpherePrecess. … … 18 18 #include "psTest.h" 19 19 #include "pslib.h" 20 /* 20 21 static psS32 test1( void ); 21 22 static psS32 test1b( void ); … … 24 25 static psS32 test3( void ); 25 26 static psS32 test4( void ); 27 static psS32 test4b( void ); 26 28 static psS32 test5( void ); 27 29 static psS32 test6( void ); … … 32 34 static psS32 test40( void ); 33 35 static psS32 test41( void ); 36 static psS32 test43( void ); 37 */ 38 static psS32 test42( void ); 34 39 testDescription tests[] = { 35 {test1, 0000, "psSphereTransformAlloc()", 0, false}, 36 {test1b, 0000, "psPlaneTransformAlloc()", 0, false}, 37 {test1c, 0000, "psPlaneDistortAlloc()", 0, false}, 38 {test2, 0000, "psPlaneTransformApply()", 0, false}, 39 {test3, 0000, "psPlaneDistortApply()", 0, false}, 40 {test4, 0000, "psPSphereTransformApply()", 0, false}, 41 {test5, 0000, "psSphereTransformICRSToEcliptic()", 0, false}, 42 {test6, 0000, "psSphereTransformEclipticToICRS()", 0, false}, 43 {test7, 0000, "psSphereTransformICRSToGalatic()", 0, false}, 44 {test8, 0000, "psSphereTransformGalaticToICRS()", 0, false}, 45 {test20, 0000, "psProject()", 0, false}, 46 {test21, 0000, "psDeProject()", 0, false}, 47 {test40, 0000, "psSphereGetOffset()", 0, false}, 48 {test41, 0000, "psSphereSetOffset()", 0, false}, 40 /* 41 {test1, 0000, "psSphereTransformAlloc()", 0, false}, 42 {test1b, 0000, "psPlaneTransformAlloc()", 0, false}, 43 {test1c, 0000, "psPlaneDistortAlloc()", 0, false}, 44 {test2, 0000, "psPlaneTransformApply()", 0, false}, 45 {test3, 0000, "psPlaneDistortApply()", 0, false}, 46 {test4, 0000, "psPSphereTransformApply()", 0, false}, 47 {test4b, 0000, "psPSphereTransformApply()", 0, false}, 48 {test5, 0000, "psSphereTransformICRSToEcliptic()", 0, false}, 49 {test6, 0000, "psSphereTransformEclipticToICRS()", 0, false}, 50 {test7, 0000, "psSphereTransformICRSToGalatic()", 0, false}, 51 {test8, 0000, "psSphereTransformGalaticToICRS()", 0, false}, 52 {test20, 0000, "psProject()", 0, false}, 53 {test21, 0000, "psDeProject()", 0, false}, 54 {test40, 0000, "psSphereGetOffset()", 0, false}, 55 {test41, 0000, "psSphereSetOffset()", 0, false}, 56 {test43, 0000, "psProject(), psDeproject", 0, false}, 57 */ 58 {test42, 0000, "psProject(), psDeproject", 0, false}, 49 59 {NULL} 50 60 }; … … 436 446 psSphereTransform *myST = psSphereTransformAlloc(0.0, 0.0, 0.0); 437 447 438 in.r = 45.0 * MY_DEG_TO_RAD;439 in.d = 30.0 * MY_DEG_TO_RAD;448 in.r = DEG_TO_RAD(45.0); 449 in.d = DEG_TO_RAD(30.0); 440 450 in.rErr = 0.0; 441 451 in.dErr = 0.0; … … 443 453 for (float r=0.0;r<180.0;r+=DEG_INC) { 444 454 for (float d=0.0;d<90.0;d+=DEG_INC) { 445 in.r = r * MY_DEG_TO_RAD;446 in.d = d * MY_DEG_TO_RAD;455 in.r = DEG_TO_RAD(r); 456 in.d = DEG_TO_RAD(d); 447 457 in.rErr = 0.0; 448 458 in.dErr = 0.0; … … 483 493 printf("-------------------------------------------------------------------\n"); 484 494 psFree(myST); 495 return(testStatus); 496 } 497 498 /****************************************************************************** 499 test4b(): This test verifies that psSphereTransformApply() works properly. We 500 create two psSphereTransforms: a forward transform and a reverse transform 501 (which is the mathematical inverse of the forward transform). We apply both 502 transforms to several spherical coordinates and ensure that the original input 503 coordinate is obtained after applying both transforms. 504 505 XXX: We currently test the alpha and delta offsets independently. Attempts to 506 test them both concurrently failed. Determine why this is. Are the following 507 spherical transforms not mathematical inverses? 508 psSphereTransformAlloc(X, Y, 0.0) 509 psSphereTransformAlloc(-X, -Y, 0.0) 510 *****************************************************************************/ 511 #define ERROR_PERCENT 0.01 512 psS32 test4b( void ) 513 { 514 psS32 testStatus = 0; 515 psSphere in; 516 psSphere out; 517 psSphere out2; 518 psSphereTransform *mySphereTransformForward = NULL; 519 psSphereTransform *mySphereTransformReverse = NULL; 520 521 522 mySphereTransformForward = psSphereTransformAlloc(DEG_TO_RAD(22.0), 523 0.0, 524 0.0); 525 mySphereTransformReverse = psSphereTransformAlloc(DEG_TO_RAD(-22.0), 526 0.0, 527 0.0); 528 529 for (float r=0.1;r<180.0;r+=(DEG_INC/5.0)) { 530 for (float d=0.1;d<90.0;d+=(DEG_INC/5.0)) { 531 in.r = DEG_TO_RAD(r); 532 in.d = DEG_TO_RAD(d); 533 in.rErr = 0.0; 534 in.dErr = 0.0; 535 536 psSphereTransformApply(&out, mySphereTransformForward, &in); 537 psSphereTransformApply(&out2, mySphereTransformReverse, &out); 538 539 if ((fabs((in.r - out2.r) / in.r) > ERROR_PERCENT) || 540 (fabs((in.d - out2.d) / in.d) > ERROR_PERCENT)) { 541 printf("ERROR: \n"); 542 printf("Input coords (R, D) are (%f, %f)\n", in.r, in.d); 543 printf("Output coords (R, D) are (%f, %f)\n", out2.r, out2.d); 544 testStatus = 4; 545 } 546 } 547 } 548 psFree(mySphereTransformForward); 549 psFree(mySphereTransformReverse); 550 551 mySphereTransformForward = psSphereTransformAlloc(0.0, 552 DEG_TO_RAD(33.0), 553 0.0); 554 mySphereTransformReverse = psSphereTransformAlloc(0.0, 555 DEG_TO_RAD(-33.0), 556 0.0); 557 for (float r=0.1;r<180.0;r+=(DEG_INC/5.0)) { 558 for (float d=0.1;d<90.0;d+=(DEG_INC/5.0)) { 559 in.r = DEG_TO_RAD(r); 560 in.d = DEG_TO_RAD(d); 561 in.rErr = 0.0; 562 in.dErr = 0.0; 563 564 psSphereTransformApply(&out, mySphereTransformForward, &in); 565 psSphereTransformApply(&out2, mySphereTransformReverse, &out); 566 567 if ((fabs((in.r - out2.r) / in.r) > ERROR_PERCENT) || 568 (fabs((in.d - out2.d) / in.d) > ERROR_PERCENT)) { 569 printf("ERROR: \n"); 570 printf("Input coords (R, D) are (%f, %f)\n", in.r, in.d); 571 printf("Output coords (R, D) are (%f, %f)\n", out2.r, out2.d); 572 testStatus = 4; 573 } 574 } 575 } 576 psFree(mySphereTransformForward); 577 psFree(mySphereTransformReverse); 578 485 579 return(testStatus); 486 580 } … … 677 771 psPlane *out; 678 772 psProjection myProjection; 679 myProjection.R = 20.0 * MY_DEG_TO_RAD;680 myProjection.D = 10.0 * MY_DEG_TO_RAD;773 myProjection.R = DEG_TO_RAD(20.0); 774 myProjection.D = DEG_TO_RAD(10.0); 681 775 myProjection.Xs = 1.0; 682 776 myProjection.Ys = 1.0; … … 684 778 for (float r=0.0;r<180.0;r+=DEG_INC) { 685 779 for (float d=0.0;d<90.0;d+=DEG_INC) { 686 in.r = r * MY_DEG_TO_RAD;687 in.d = d * MY_DEG_TO_RAD;780 in.r = DEG_TO_RAD(r); 781 in.d = DEG_TO_RAD(d); 688 782 in.rErr = 0.0; 689 783 in.dErr = 0.0; … … 789 883 psSphere *out; 790 884 psProjection myProjection; 791 myProjection.R = 20.0 * MY_DEG_TO_RAD;792 myProjection.D = 10.0 * MY_DEG_TO_RAD;885 myProjection.R = DEG_TO_RAD(20.0); 886 myProjection.D = DEG_TO_RAD(10.0); 793 887 myProjection.Xs = 1.0; 794 888 myProjection.Ys = 1.0; … … 904 998 psSphere *offset = NULL; 905 999 906 position1.r = 90.0 * MY_DEG_TO_RAD;907 position1.d = 45.0 * MY_DEG_TO_RAD;1000 position1.r = DEG_TO_RAD(90.0); 1001 position1.d = DEG_TO_RAD(45.0); 908 1002 position1.rErr = 0.0; 909 1003 position1.dErr = 0.0; … … 911 1005 for (float r=0.0;r<180.0;r+=DEG_INC) { 912 1006 for (float d=0.0;d<90.0;d+=DEG_INC) { 913 position2.r = r * MY_DEG_TO_RAD;914 position2.d = d * MY_DEG_TO_RAD;1007 position2.r = DEG_TO_RAD(r); 1008 position2.d = DEG_TO_RAD(d); 915 1009 position2.rErr = 0.0; 916 1010 position2.dErr = 0.0; … … 924 1018 offset = psSphereGetOffset(&position1, &position2, 925 1019 PS_SPHERICAL, PS_DEGREE); 926 offset->r = offset->r * MY_DEG_TO_RAD;927 offset->d = offset->d * MY_DEG_TO_RAD;1020 offset->r = DEG_TO_RAD(offset->r); 1021 offset->d = DEG_TO_RAD(offset->d); 928 1022 PS_COMPARE_TINY_THEN_PRINT_ERROR(offset->r, (position2.r - position1.r), 2); 929 1023 PS_COMPARE_TINY_THEN_PRINT_ERROR(offset->d, (position2.d - position1.d), 3); … … 946 1040 psFree(offset); 947 1041 948 / * XXX: This code does not work correctly.949 offset = psSphereGetOffset(&position1, &position2,950 PS_LINEAR, 0);951 printf("--------------- (%f, %f) to (%f, %f) is (%f, %f) ---------------\n",952 position1.r, position1.d, position2.r, position2.d,953 offset->r, offset->d);1042 //HEY /* XXX: This code does not work correctly. 1043 printf("--------------- (%f, %f) to (%f, %f) is (%f, %f) ---------------\n", 1044 position1.r, position1.d, position2.r, position2.d, 1045 offset->r, offset->d); 1046 /* 1047 offset = psSphereGetOffset(&position1, &position2, PS_LINEAR, 0); 954 1048 PS_COMPARE_TINY_THEN_PRINT_ERROR(offset->r, (position2.r - position1.r), 1); 955 1049 PS_COMPARE_TINY_THEN_PRINT_ERROR(offset->d, (position2.d - position1.d), 1); 956 psFree(offset);957 1050 */ 1051 psFree(offset); 1052 // */ 958 1053 } 959 1054 } … … 1007 1102 psSphere tmpOffset; 1008 1103 1009 position1.r = 90.0 * MY_DEG_TO_RAD;1010 position1.d = 45.0 * MY_DEG_TO_RAD;1104 position1.r = DEG_TO_RAD(90.0); 1105 position1.d = DEG_TO_RAD(45.0); 1011 1106 position1.rErr = 0.0; 1012 1107 position1.dErr = 0.0; … … 1014 1109 for (float r=0.0;r<180.0;r+=DEG_INC) { 1015 1110 for (float d=0.0;d<90.0;d+=DEG_INC) { 1016 offset.r = r * MY_DEG_TO_RAD;1017 offset.d = d * MY_DEG_TO_RAD;1111 offset.r = DEG_TO_RAD(offset.r); 1112 offset.d = DEG_TO_RAD(offset.d); 1018 1113 offset.rErr = 0.0; 1019 1114 offset.dErr = 0.0; … … 1025 1120 psFree(position2); 1026 1121 1027 tmpOffset.r = offset.r * MY_RAD_TO_DEG;1028 tmpOffset.d = offset.d * MY_RAD_TO_DEG;1122 tmpOffset.r = DEG_TO_RAD(offset.r); 1123 tmpOffset.d = DEG_TO_RAD(offset.d); 1029 1124 tmpOffset.rErr = 0.0; 1030 1125 tmpOffset.dErr = 0.0; … … 1108 1203 } 1109 1204 1205 /****************************************************************************** 1206 test43(): Not really a test. We simply project many points and print the 1207 results. 1208 *****************************************************************************/ 1209 psS32 test43( void ) 1210 { 1211 psS32 testStatus = 0; 1212 psSphere projCenter; 1213 psSphere startCoords; 1214 psPlane *planeCoords; 1215 1216 projCenter.r = DEG_TO_RAD(33.0); 1217 projCenter.d = DEG_TO_RAD(22.0); 1218 projCenter.r = 0.0; 1219 projCenter.d = 0.0; 1220 // Create the psProjection plane: 1221 psProjection myProj; 1222 myProj.R = projCenter.r; 1223 myProj.D = projCenter.d; 1224 myProj.Xs = 1.0; 1225 myProj.Ys = 1.0; 1226 myProj.type = PS_PROJ_TAN; 1227 1228 printf(" projCenter is (%f, %f)\n", projCenter.r, projCenter.d); 1229 for (float r=-90.0;r<90.0;r+=DEG_INC/5.0) { 1230 for (float d=-90.0;d<90.0;d+=DEG_INC/5.0) { 1231 printf("----------------------------------------------------------\n"); 1232 printf("Angles (R, D) are (%.2f, %.2f)\n", r, d); 1233 startCoords.r = DEG_TO_RAD(r); 1234 startCoords.d = DEG_TO_RAD(d); 1235 1236 planeCoords = psProject(&startCoords, &myProj); 1237 printf(" startCoords (R, D) is (%f, %f)\n", startCoords.r, startCoords.d); 1238 printf(" plane Coords (X, Y) is (%f, %f)\n", planeCoords->x, planeCoords->y); 1239 psFree(planeCoords); 1240 } 1241 } 1242 printf("----------------------------------------------------------\n"); 1243 return(testStatus); 1244 } 1245 1246 #define NUM_DEGREES 5 1247 /****************************************************************************** 1248 test42(): This test attempts to verify the psProject() and psDeproject() 1249 functions. We create an arbitrary psProjection. We then project several 1250 spherical coordinates onto the plane and then immediately deproject them; we 1251 ensure that the resulting spherical coordinates are identical to the start 1252 coordinates. 1253 *****************************************************************************/ 1254 psS32 test42( void ) 1255 { 1256 psS32 testStatus = 0; 1257 psSphere projCenter; 1258 psSphere startCoords; 1259 psSphere *endCoords; 1260 psPlane *planeCoords; 1261 1262 #define PROG_CENTER_R_DEG 20.0 1263 #define PROG_CENTER_D_DEG 20.0 1264 1265 projCenter.r = DEG_TO_RAD(PROG_CENTER_R_DEG); 1266 projCenter.d = DEG_TO_RAD(PROG_CENTER_D_DEG); 1267 // Create the psProjection plane: 1268 psProjection myProj; 1269 myProj.R = projCenter.r; 1270 myProj.D = projCenter.d; 1271 myProj.Xs = 1.0; 1272 myProj.Ys = 1.0; 1273 myProj.type = PS_PROJ_TAN; 1274 1275 #define RADIUS_DEG 30.0 1276 #define NUM_ANGLES 20 1277 #define MY_DEG_INC ((2.0 * RADIUS_DEG) / NUM_ANGLES) 1278 1279 for (float r= (PROG_CENTER_R_DEG - RADIUS_DEG); 1280 r<=(PROG_CENTER_R_DEG + RADIUS_DEG); 1281 r+=MY_DEG_INC) { 1282 printf("------------------------ r is %.1f ------------------------\n", r); 1283 for (float d= (PROG_CENTER_D_DEG - RADIUS_DEG); 1284 d<=(PROG_CENTER_D_DEG + RADIUS_DEG); 1285 d+=MY_DEG_INC) { 1286 startCoords.r = DEG_TO_RAD(r); 1287 startCoords.d = DEG_TO_RAD(d); 1288 printf("----- startCoords (R, D) is (%f, %f) is deg (%.1f, %.1f) -----\n", startCoords.r, startCoords.d, r, d); 1289 1290 planeCoords = psProject(&startCoords, &myProj); 1291 endCoords = psDeproject(planeCoords, &myProj); 1292 1293 if ((fabs((endCoords->r - startCoords.r) / startCoords.r) > ERROR_PERCENT) || 1294 (fabs((endCoords->d - startCoords.d) / startCoords.d) > ERROR_PERCENT)) { 1295 printf("ERROR: \n"); 1296 printf(" startCoords (R, D) is (%f, %f)\n", startCoords.r, startCoords.d); 1297 // printf(" plane Coords is (%f, %f)\n", planeCoords->x, planeCoords->y); 1298 printf(" endCoords (R, D) is (%f, %f)\n", endCoords->r, endCoords->d); 1299 } 1300 1301 psFree(planeCoords); 1302 psFree(endCoords); 1303 } 1304 } 1305 return(testStatus); 1306 } 1307 1110 1308 // This code will ...
Note:
See TracChangeset
for help on using the changeset viewer.
