Example #1
0
/* Nutation -- AA page B20
 * using nutation in longitude and obliquity from nutlo()
 * and obliquity of the ecliptic from epsiln()
 * both calculated for Julian date J.
 *
 * p[] = equatorial rectangular position vector of object for
 * mean ecliptic and equinox of date.
 */
int nutate( double J, double *p )
{
double ce, se, cl, sl, sino, f;
double dp[3], p1[3];
int i;

nutlo(J); /* be sure we calculated nutl and nuto */
epsiln(J); /* and also the obliquity of date */

f = eps + nuto;
ce = cos( f );
se = sin( f );
sino = sin(nuto);
cl = cos( nutl );
sl = sin( nutl );

/* Apply adjustment
 * to equatorial rectangular coordinates of object.
 *
 * This is a composite of three rotations: rotate about x axis
 * to ecliptic of date; rotate about new z axis by the nutation
 * in longitude; rotate about new x axis back to equator of date
 * plus nutation in obliquity.
 */
p1[0] =   cl*p[0]
        - sl*coseps*p[1]
        - sl*sineps*p[2];

p1[1] =   sl*ce*p[0]
        + ( cl*coseps*ce + sineps*se )*p[1]
        - ( sino + (1.0-cl)*sineps*ce )*p[2];

p1[2] =   sl*se*p[0]
        + ( sino + (cl-1.0)*se*coseps )*p[1]
        + ( cl*sineps*se + coseps*ce )*p[2];

for( i=0; i<3; i++ )
	dp[i] = p1[i] - p[i];

for( i=0; i<3; i++ )
	p[i] = p1[i];
return(0);
}
Example #2
0
/* 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);
}