Changeset 2983
- Timestamp:
- Jan 13, 2005, 12:45:40 PM (22 years ago)
- Location:
- trunk/psLib
- Files:
-
- 5 edited
-
src/astro/psCoord.c (modified) (11 diffs)
-
src/astronomy/psAstrometry.c (modified) (2 diffs)
-
src/astronomy/psCoord.c (modified) (11 diffs)
-
test/astronomy/tst_psAstrometry01.c (modified) (5 diffs)
-
test/astronomy/tst_psCoord.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psCoord.c
r2941 r2983 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1.4 4$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-01-1 0 19:47:10$12 * @version $Revision: 1.45 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-01-13 22:45:28 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 #include "psConstants.h" 25 25 #include "psError.h" 26 #include "psLogMsg.h" 26 27 #include "psAstronomyErrors.h" 27 28 #include <math.h> … … 183 184 184 185 /****************************************************************************** 186 XXX: Private Function. 187 188 piNormalize(): take an input angle in radians and convert it to the range 0:PI. 189 *****************************************************************************/ 190 psF32 piNormalize(psF32 angle) 191 { 192 while (angle < FLT_EPSILON) { 193 angle+=M_PI; 194 } 195 196 while (angle >= M_PI) { 197 angle-=M_PI; 198 } 199 return(angle); 200 } 201 202 /****************************************************************************** 203 XXX: We convert Right Ascension angles to the range 0:PI. Is that acceptable? 204 XXX: Should we do something for Declination as well? 185 205 *****************************************************************************/ 186 206 psSphere* psSphereTransformApply(psSphere* out, … … 210 230 psF64 phi = atan2(eq56, eq57) + transform->alphaP; 211 231 212 out->r = phi; 232 233 out->r = piNormalize(phi); 213 234 out->d = theta; 214 235 … … 281 302 XXX: Waiting for the definition of the PS_PROJ_PAR projection. 282 303 XXX: Waiting for the definition of the PS_PROJ_GLS projection. 304 XXX: Must apply scaling at the end. 283 305 *****************************************************************************/ 284 306 psPlane* psProject(const psSphere* coord, … … 288 310 PS_PTR_CHECK_NULL(projection, NULL); 289 311 290 // float R = 0.0;291 // float alpha = 0.0;292 312 psPlane* tmp = (psPlane* ) psAlloc(sizeof(psPlane)); 293 294 313 if (projection->type == PS_PROJ_TAN) { 295 tmp->x = cos(coord->r) * sin(coord->d) / sin(coord->r); 296 tmp->y = -cos(coord->r) * cos(coord->d) / sin(coord->r); 314 315 /* 316 // ******************************************** 317 // From the ADD 318 // ******************************************** 319 // psLogMsg(__func__, PS_LOG_WARN, "WARNING: psProject(): These projections don't work."); 320 // return(NULL); 321 psF32 sinTheta; 322 psF32 cosThetaCosPhi; 323 psF32 cosThetaSinPhi; 324 325 sinTheta = (sin(coord->d) * sin(projection->D)) + 326 (cos(coord->d) * cos(projection->D) * (cos(coord->r - projection->R))); 327 cosThetaCosPhi = (sin(coord->d) * cos(projection->D)) - 328 (cos(coord->d) * sin(projection->D) * (cos(coord->r - projection->R))); 329 cosThetaSinPhi = - cos(coord->d) * sin(coord->r - projection->R); 330 331 tmp->x = -cosThetaSinPhi / sinTheta; 332 tmp->y = cosThetaCosPhi / sinTheta; 333 334 */ 335 336 // ******************************************** 337 // From the mathworks: http://mathworld.wolfram.com/GnomonicProjection.html 338 // delta_0 and phi_1 are the projection centers, not the point being projected. 339 // (delta_0, phi_1) == (projection->R, projection->D) 340 // ******************************************** 341 psF32 cosC = (sin(projection->D) * sin(coord->d)) + 342 (cos(projection->D) * cos(coord->d) * cos(coord->r - projection->R)); 343 tmp->x = (cos(coord->d) * sin(coord->r - projection->R)) / cosC; 344 tmp->y = ((cos(projection->D) * sin(coord->d)) - 345 (sin(projection->D) * cos(coord->d) * cos(coord->r - projection->R))) / 346 cosC; 297 347 298 348 } else if (projection->type == PS_PROJ_SIN) { 349 // psLogMsg(__func__, PS_LOG_WARN, "WARNING: psProject(): These projections don't work."); 350 // return(NULL); 351 299 352 tmp->x = cos(coord->d) * sin(coord->d); 300 353 tmp->y = -cos(coord->d) * cos(coord->d); … … 332 385 333 386 /****************************************************************************** 387 XXX: Waiting for algorithms. 334 388 XXX: Waiting for the definition of the PS_PROJ_PAR projection. 335 389 XXX: Waiting for the definition of the PS_PROJ_GLS projection. 390 XXX: Must apply scaling at the beginning. 336 391 *****************************************************************************/ 337 392 psSphere* psDeproject(const psPlane* coord, … … 340 395 PS_PTR_CHECK_NULL(coord, NULL); 341 396 PS_PTR_CHECK_NULL(projection, NULL); 342 397 // psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): These projections don't work."); 398 // return(NULL); 343 399 float R = 0.0; 344 400 float chu = 0.0; … … 348 404 349 405 if (projection->type == PS_PROJ_TAN) { 350 tmp->r = atan2(-coord->y, coord->x); 351 R = PS_SQRT_F32((coord->x * coord->x) + (coord->y * coord->y)); 352 tmp->d = atan(1.0 / R); 406 /* 407 // ******************************************** 408 // From the ADD 409 // ******************************************** 410 psF32 phi; 411 psF32 theta; 412 psF32 sinDelta; 413 psF32 cosDeltaCosAlphaMinusAlphaP; 414 psF32 cosDeltaSinAlphaMinusAlphaP; 415 416 phi = atan2(-coord->y, coord->x); 417 R = PS_SQRT_F32((coord->x * coord->x) + (coord->y * coord->y)); 418 theta = atan(1.0 / R); 419 420 sinDelta = (sin(theta) * sin(projection->D)) + 421 (cos(theta) * cos(projection->D) * cos(phi)); 422 cosDeltaCosAlphaMinusAlphaP = 423 (sin(theta) * cos(projection->D)) - 424 (cos(theta) * sin(projection->D) * cos(phi)); 425 cosDeltaSinAlphaMinusAlphaP = -cos(theta) * sin(phi); 426 tmp->d = asin(sinDelta); 427 tmp->r = atan2(cosDeltaSinAlphaMinusAlphaP, cosDeltaCosAlphaMinusAlphaP) + projection->R; 428 */ 429 // ******************************************** 430 // From the mathworks: http://mathworld.wolfram.com/GnomonicProjection.html 431 // delta_0 and phi_1 are the projection centers, not the point being projected. 432 // (delta_0, phi_1) == (projection->R, projection->D) 433 // ******************************************** 434 psF32 row = PS_SQRT_F32((coord->x * coord->x) + (coord->y * coord->y)); 435 psF32 C = atan(row); 436 tmp->d = asin((cos(C) * sin(projection->D)) + ((coord->y * sin(C) * cos(projection->D)) / row)); 437 psF32 tmpAtan = atan((coord->x * sin(C)) / 438 ((row * cos(projection->D) * cos(C)) - (coord->y * sin(projection->D) * sin(C)))); 439 tmp->r = projection->R + tmpAtan; 440 353 441 354 442 } else if (projection->type == PS_PROJ_SIN) { … … 415 503 PS_PTR_CHECK_NULL(position2, NULL); 416 504 505 if (position1->d >= DEG_TO_RAD(90.0)) { 506 psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): position1->d is larger than 90 degrees. Returning NULL.\n"); 507 return(NULL); 508 } 509 if (position2->d >= DEG_TO_RAD(90.0)) { 510 psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): position2->d is larger than 90 degrees. Returning NULL.\n"); 511 return(NULL); 512 } 513 417 514 psPlane* lin; 418 515 psProjection proj; … … 426 523 proj.type = PS_PROJ_TAN; 427 524 428 printf("------------ position 1 is (%f, %f)\n", position1->r, position1->d);429 printf("------------ position 2 is (%f, %f)\n", position2->r, position2->d);430 525 lin = psProject(position1, &proj); 431 printf("------------ projected position 1 is (%f, %f)\n", lin->y, lin->x);432 526 lin = psProject(position2, &proj); 433 printf("------------ projected position 2 is (%f, %f)\n", lin->y, lin->x);434 527 tmp = psDeproject(lin, &proj); 435 printf("------------ deprojected position 2 is (%f, %f)\n", tmp->r, tmp->d);436 437 528 psFree(lin); 438 439 529 // XXX: Do we need to convert units in tmp? 440 530 return (tmp); -
trunk/psLib/src/astronomy/psAstrometry.c
r2931 r2983 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1.5 4$ $Name: not supported by cvs2svn $11 * @date $Date: 2005-01- 07 23:52:15$10 * @version $Revision: 1.55 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2005-01-13 22:45:28 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 566 566 } 567 567 } 568 568 printf("Hmmm, returning NULL\n"); 569 569 return (NULL); 570 570 } -
trunk/psLib/src/astronomy/psCoord.c
r2941 r2983 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1.4 4$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-01-1 0 19:47:10$12 * @version $Revision: 1.45 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-01-13 22:45:28 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 #include "psConstants.h" 25 25 #include "psError.h" 26 #include "psLogMsg.h" 26 27 #include "psAstronomyErrors.h" 27 28 #include <math.h> … … 183 184 184 185 /****************************************************************************** 186 XXX: Private Function. 187 188 piNormalize(): take an input angle in radians and convert it to the range 0:PI. 189 *****************************************************************************/ 190 psF32 piNormalize(psF32 angle) 191 { 192 while (angle < FLT_EPSILON) { 193 angle+=M_PI; 194 } 195 196 while (angle >= M_PI) { 197 angle-=M_PI; 198 } 199 return(angle); 200 } 201 202 /****************************************************************************** 203 XXX: We convert Right Ascension angles to the range 0:PI. Is that acceptable? 204 XXX: Should we do something for Declination as well? 185 205 *****************************************************************************/ 186 206 psSphere* psSphereTransformApply(psSphere* out, … … 210 230 psF64 phi = atan2(eq56, eq57) + transform->alphaP; 211 231 212 out->r = phi; 232 233 out->r = piNormalize(phi); 213 234 out->d = theta; 214 235 … … 281 302 XXX: Waiting for the definition of the PS_PROJ_PAR projection. 282 303 XXX: Waiting for the definition of the PS_PROJ_GLS projection. 304 XXX: Must apply scaling at the end. 283 305 *****************************************************************************/ 284 306 psPlane* psProject(const psSphere* coord, … … 288 310 PS_PTR_CHECK_NULL(projection, NULL); 289 311 290 // float R = 0.0;291 // float alpha = 0.0;292 312 psPlane* tmp = (psPlane* ) psAlloc(sizeof(psPlane)); 293 294 313 if (projection->type == PS_PROJ_TAN) { 295 tmp->x = cos(coord->r) * sin(coord->d) / sin(coord->r); 296 tmp->y = -cos(coord->r) * cos(coord->d) / sin(coord->r); 314 315 /* 316 // ******************************************** 317 // From the ADD 318 // ******************************************** 319 // psLogMsg(__func__, PS_LOG_WARN, "WARNING: psProject(): These projections don't work."); 320 // return(NULL); 321 psF32 sinTheta; 322 psF32 cosThetaCosPhi; 323 psF32 cosThetaSinPhi; 324 325 sinTheta = (sin(coord->d) * sin(projection->D)) + 326 (cos(coord->d) * cos(projection->D) * (cos(coord->r - projection->R))); 327 cosThetaCosPhi = (sin(coord->d) * cos(projection->D)) - 328 (cos(coord->d) * sin(projection->D) * (cos(coord->r - projection->R))); 329 cosThetaSinPhi = - cos(coord->d) * sin(coord->r - projection->R); 330 331 tmp->x = -cosThetaSinPhi / sinTheta; 332 tmp->y = cosThetaCosPhi / sinTheta; 333 334 */ 335 336 // ******************************************** 337 // From the mathworks: http://mathworld.wolfram.com/GnomonicProjection.html 338 // delta_0 and phi_1 are the projection centers, not the point being projected. 339 // (delta_0, phi_1) == (projection->R, projection->D) 340 // ******************************************** 341 psF32 cosC = (sin(projection->D) * sin(coord->d)) + 342 (cos(projection->D) * cos(coord->d) * cos(coord->r - projection->R)); 343 tmp->x = (cos(coord->d) * sin(coord->r - projection->R)) / cosC; 344 tmp->y = ((cos(projection->D) * sin(coord->d)) - 345 (sin(projection->D) * cos(coord->d) * cos(coord->r - projection->R))) / 346 cosC; 297 347 298 348 } else if (projection->type == PS_PROJ_SIN) { 349 // psLogMsg(__func__, PS_LOG_WARN, "WARNING: psProject(): These projections don't work."); 350 // return(NULL); 351 299 352 tmp->x = cos(coord->d) * sin(coord->d); 300 353 tmp->y = -cos(coord->d) * cos(coord->d); … … 332 385 333 386 /****************************************************************************** 387 XXX: Waiting for algorithms. 334 388 XXX: Waiting for the definition of the PS_PROJ_PAR projection. 335 389 XXX: Waiting for the definition of the PS_PROJ_GLS projection. 390 XXX: Must apply scaling at the beginning. 336 391 *****************************************************************************/ 337 392 psSphere* psDeproject(const psPlane* coord, … … 340 395 PS_PTR_CHECK_NULL(coord, NULL); 341 396 PS_PTR_CHECK_NULL(projection, NULL); 342 397 // psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): These projections don't work."); 398 // return(NULL); 343 399 float R = 0.0; 344 400 float chu = 0.0; … … 348 404 349 405 if (projection->type == PS_PROJ_TAN) { 350 tmp->r = atan2(-coord->y, coord->x); 351 R = PS_SQRT_F32((coord->x * coord->x) + (coord->y * coord->y)); 352 tmp->d = atan(1.0 / R); 406 /* 407 // ******************************************** 408 // From the ADD 409 // ******************************************** 410 psF32 phi; 411 psF32 theta; 412 psF32 sinDelta; 413 psF32 cosDeltaCosAlphaMinusAlphaP; 414 psF32 cosDeltaSinAlphaMinusAlphaP; 415 416 phi = atan2(-coord->y, coord->x); 417 R = PS_SQRT_F32((coord->x * coord->x) + (coord->y * coord->y)); 418 theta = atan(1.0 / R); 419 420 sinDelta = (sin(theta) * sin(projection->D)) + 421 (cos(theta) * cos(projection->D) * cos(phi)); 422 cosDeltaCosAlphaMinusAlphaP = 423 (sin(theta) * cos(projection->D)) - 424 (cos(theta) * sin(projection->D) * cos(phi)); 425 cosDeltaSinAlphaMinusAlphaP = -cos(theta) * sin(phi); 426 tmp->d = asin(sinDelta); 427 tmp->r = atan2(cosDeltaSinAlphaMinusAlphaP, cosDeltaCosAlphaMinusAlphaP) + projection->R; 428 */ 429 // ******************************************** 430 // From the mathworks: http://mathworld.wolfram.com/GnomonicProjection.html 431 // delta_0 and phi_1 are the projection centers, not the point being projected. 432 // (delta_0, phi_1) == (projection->R, projection->D) 433 // ******************************************** 434 psF32 row = PS_SQRT_F32((coord->x * coord->x) + (coord->y * coord->y)); 435 psF32 C = atan(row); 436 tmp->d = asin((cos(C) * sin(projection->D)) + ((coord->y * sin(C) * cos(projection->D)) / row)); 437 psF32 tmpAtan = atan((coord->x * sin(C)) / 438 ((row * cos(projection->D) * cos(C)) - (coord->y * sin(projection->D) * sin(C)))); 439 tmp->r = projection->R + tmpAtan; 440 353 441 354 442 } else if (projection->type == PS_PROJ_SIN) { … … 415 503 PS_PTR_CHECK_NULL(position2, NULL); 416 504 505 if (position1->d >= DEG_TO_RAD(90.0)) { 506 psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): position1->d is larger than 90 degrees. Returning NULL.\n"); 507 return(NULL); 508 } 509 if (position2->d >= DEG_TO_RAD(90.0)) { 510 psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): position2->d is larger than 90 degrees. Returning NULL.\n"); 511 return(NULL); 512 } 513 417 514 psPlane* lin; 418 515 psProjection proj; … … 426 523 proj.type = PS_PROJ_TAN; 427 524 428 printf("------------ position 1 is (%f, %f)\n", position1->r, position1->d);429 printf("------------ position 2 is (%f, %f)\n", position2->r, position2->d);430 525 lin = psProject(position1, &proj); 431 printf("------------ projected position 1 is (%f, %f)\n", lin->y, lin->x);432 526 lin = psProject(position2, &proj); 433 printf("------------ projected position 2 is (%f, %f)\n", lin->y, lin->x);434 527 tmp = psDeproject(lin, &proj); 435 printf("------------ deprojected position 2 is (%f, %f)\n", tmp->r, tmp->d);436 437 528 psFree(lin); 438 439 529 // XXX: Do we need to convert units in tmp? 440 530 return (tmp); -
trunk/psLib/test/astronomy/tst_psAstrometry01.c
r2537 r2983 5 5 * @author GLG, MHPCC 6 6 * 7 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $8 * @date $Date: 200 4-11-30 21:56:20 $7 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-01-13 22:45:40 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 21 21 {test1, 0000, "Tests psFixedPatternAlloc()", 0, false}, 22 22 {test2, 0000, "Tests psGrommitAlloc()", 0, false}, 23 {test3, 0000, " psFunctionBar", 0, false},23 {test3, 0000, "MISC", 0, false}, 24 24 {NULL} 25 25 }; … … 189 189 psLogSetLevel( PS_LOG_INFO ); 190 190 191 return ( ! runTestSuite( stderr, "ps Image", tests, argc, argv ) );191 return ( ! runTestSuite( stderr, "psAstrometry", tests, argc, argv ) ); 192 192 } 193 193 … … 440 440 441 441 if ((myCell == NULL) || (tmpChip == NULL)) { 442 printf("ERROR: NULL\n"); 442 if (myCell == NULL) { 443 printf("ERROR: myCell is NULL\n"); 444 } 445 if (tmpChip == NULL) { 446 printf("ERROR: tmpChip is NULL\n"); 447 } 443 448 } else { 444 449 psCoordFPAToChip(&chipCoord, &fpaCoord, tmpChip); … … 517 522 } 518 523 524 printf("HERE 00\n"); 519 525 psFree(myFPA); 526 printf("HERE 01\n"); 520 527 521 528 return(0); -
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.
