/* Calculate geometric position of the Moon and apply * approximate corrections to find apparent position, * phase of the Moon, etc. for AA.ARC. */ int domoon() { int i, prtsav; double ra0, dec0, r; double x, y, z, lon0; double c, s, temp; double pp[3], qq[3]; double acos(); /* Compute obliquity of the ecliptic, coseps, and sineps */ epsiln(TDT); /* Run the orbit calculation twice, at two different times, * in order to find the rate of change of R.A. and Dec. */ /* Calculate for 0.001 day ago */ prtsav = prtflg; prtflg = 0; /* disable display */ moonll(TDT-0.001, moonpp, moonpol); /* lonlat( rearth, TDT, eapolar ); // precess earth to date // lonlat( rearth, TDT, eapolar, 1 ); */ ra0 = ra; dec0 = dec; lon0 = l; prtflg = prtsav; /* Calculate for present instant. */ moonll(TDT, moonpp, moonpol); /* The rates of change. These are used by altaz() to * correct the time of rising, transit, and setting. */ dradt = ra - ra0; if (dradt >= PI) dradt = dradt - 2.0 * PI; if (dradt <= -PI) dradt = dradt + 2.0 * PI; dradt = 1000.0 * dradt; ddecdt = 1000.0*(dec-dec0); /* Post the ecliptic longitude and latitude, in radians, * and the radius in au. */ obpolar[0] = l; obpolar[1] = B; r = 1.0/sin(p); /* distance in earth-radii */ ra0 = Rearth*r; /* factor is radius of earth in au */ obpolar[2] = ra0; /* Rate of change in longitude, degrees per day * used for phase of the moon */ lon0 = 1000.0*RTD*(l - lon0); /* convert to ecliptic rectangular coordinates */ z = ra0 * cos(B); x = z * cos(l); y = z * sin(l); z = ra0 * sin(B); /* convert to equatorial coordinates */ pp[0] = x; pp[1] = y * coseps - z * sineps; pp[2] = y * sineps + z * coseps; /* Find sun-moon-earth angles */ precess( rearth, TDT, -1 ); for( i=0; i<3; i++ ) qq[i] = rearth[i] + pp[i]; angles( pp, qq, rearth ); /* Display answers */ if( prtflg ) { /* Apparent ecliptic coordinates. The nutation in longitude is added to the ecliptic longitude. See AA page C2. First rotate the coordinate system about the x axis from mean equator to ecliptic. Then rotate about the z axis by the nutation in longitude. */ x = Mapp[0]; y = Mapp[1]; z = Mapp[2]; temp = coseps * y + sineps * z; z = -sineps * y + coseps * z; y = temp; c = cos(nutl); s = sin(nutl); temp = c * x - s * y; y = s * x + c * y; x = temp; Mapp[0] = zatan2( x, y ); Mapp[1] = asin( z ); Mapp[2] = Rem; printf( "Apparent geocentric longitude %.3f deg", RTD*Mapp[0] ); printf( " latitude %.3f deg\n", RTD*Mapp[1] ); printf( "Distance %.3f Earth-radii\n", r ); printf( "Horizontal parallax" ); dms( p ); printf( "Semidiameter" ); x = 0.272453 * p + 0.0799/RTS; /* AA page L6 */ dms( x ); x = RTD * acos(-ep); printf( "\nElongation from sun %.2f deg,", x ); x = 0.5 * (1.0 + pq); printf( " Illuminated fraction %.2f\n", x ); /* Find phase of the Moon by comparing Moon's longitude * with Earth's longitude. * * The number of days before or past indicated phase is * estimated by assuming the true longitudes change linearly * with time. These rates are estimated for the date, but * do not stay constant. The error can exceed 0.15 day in 4 days. */ /* Apparent longitude of sun. * Moon's longitude was already corrected for light time. */ y = eapolar[0] - 20.496/(RTS*eapolar[2]); x = obpolar[0] - y; x = modtp( x ) * RTD; /* difference in longitude */ i = x/90; /* number of quarters */ x = (x - i*90.0); /* phase angle mod 90 degrees */ /* days per degree of phase angle */ z = 1.0/(lon0 - (0.9856/eapolar[2])); if( x > 45.0 ) { y = -(x - 90.0)*z; if( y > 1.0 ) printf( "Phase %.1f days before ", y ); else printf( "Phase %.2f days before ", y ); i = (i+1) & 3; } else { y = x*z; if( y > 1.0 ) printf( "Phase %.1f days past ", y ); else printf( "Phase %.2f days past ", y ); } switch(i) { case 0: printf( "Full Moon\n" ); break; case 1: printf( "Third Quarter\n" ); break; case 2: printf( "New Moon\n" ); break; case 3: printf( "First Quarter\n" ); break; } } /* if prtflg */ printf( " Apparent: R.A." ); hms(ra); printf( "Declination" ); dms(dec); printf( "\n" ); /* Compute and display topocentric position (altaz.c) */ pp[0] = ra; pp[1] = dec; pp[2] = r * Rearth; altaz( pp, UT ); return(0); }
int fk4fk5( double *p, double *m, struct star *el ) { double a, b, c; double *u, *v; double R[6]; int i, j; //printf( "Converting to FK5 system\n" ); /* Note the direction vector and motion vector * are already supplied by rstar.c. */ a = 0.0; b = 0.0; for( i=0; i<3; i++ ) { m[i] *= RTS; /* motion must be in arc seconds per century */ a += A[i] * p[i]; b += Ad[i] * p[i]; } /* Remove E terms of aberration from FK4 */ for( i=0; i<3; i++ ) { R[i] = p[i] - A[i] + a * p[i]; R[i+3] = m[i] - Ad[i] + b * p[i]; } /* Perform matrix multiplication */ v = &Mat[0]; for( i=0; i<6; i++ ) { a = 0.0; u = &R[0]; for( j=0; j<6; j++ ) a += *u++ * *v++; if( i < 3 ) p[i] = a; else m[i-3] = a; } /* Transform the answers into J2000 catalogue entries * in radian measure. */ b = p[0]*p[0] + p[1]*p[1]; a = b + p[2]*p[2]; c = a; a = sqrt(a); el->ra = zatan2( p[0], p[1] ); el->dec = asin( p[2]/a ); /* Note motion converted back to radians per (Julian) century */ el->mura = (p[0]*m[1] - p[1]*m[0])/(RTS*b); el->mudec = (m[2]*b - p[2]*(p[0]*m[0] + p[1]*m[1]) )/(RTS*c*sqrt(b)); if( el->px > 0.0 ) { c = 0.0; for( i=0; i<3; i++ ) c += p[i] * m[i]; /* divide by RTS to deconvert m (and therefore c) * from arc seconds back to radians */ el->v = c/(21.094952663 * el->px * RTS * a); } el->px = el->px/a; /* a is dimensionless */ el->epoch = J2000; return(0); }