IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 2, 2008, 8:08:31 AM (18 years ago)
Author:
eugene
Message:

replace poor code with ohana_normalize_angle

Location:
trunk/Ohana/src/libohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libohana/include/ohana.h

    r16121 r19823  
    203203double  ohana_lst              PROTO((double jd, double longitude));
    204204int     ohana_str_to_radec     PROTO((double *ra, double *dec, char *str1, char *str2));
     205double  ohana_normalize_angle  PROTO((double angle));
    205206
    206207int     hstgsc_hms_to_deg      PROTO((double *h0, double *h1, double *d0, double *d1, char *string));
  • trunk/Ohana/src/libohana/src/time.c

    r14590 r19823  
    434434  return (sid_g);
    435435}
     436
     437double ohana_normalize_angle (double angle) {
     438
     439    double result;
     440
     441    // take an input angle and force the domain to be 0.0 - 360.0
     442    // there are a few ways to do this: 
     443
     444    // option 1: This is a potentially very slow method, also subject to round off errors
     445# if (0)
     446    while (angle > 360.0) angle -= 360.0;
     447    while (angle <   0.0) angle += 360.0;
     448# endif
     449   
     450    // option 2: take sin & cos, apply atan2 (y, x)
     451# if (1)   
     452    double x, y;
     453
     454    x = cos(angle*RAD_DEG);
     455    y = sin(angle*RAD_DEG);
     456
     457    result = atan2 (y, x);
     458    if (result < 0.0) result += 360.0;
     459# endif
     460
     461# if (0)
     462    // option 3:
     463    int nCircle = angle / 360.0;
     464    result -= 360.0*nCircle;
     465    if (result < 0.0) result += 360.0;
     466# endif
     467
     468    return (result);
     469}
Note: See TracChangeset for help on using the changeset viewer.