Changeset 2983 for trunk/psLib/src/astronomy/psCoord.c
- Timestamp:
- Jan 13, 2005, 12:45:40 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/astronomy/psCoord.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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);
Note:
See TracChangeset
for help on using the changeset viewer.
