int writeMoon (double jd, struct ln_lnlat_posn obs) { struct ln_equ_posn equ; // equatorial moon position struct ln_hrz_posn hrz; // horiz alt/az double lum; // luminance, best guess double discSize; // solar disc size from libnova double adjAlt; // altitude adjustment float lunPos[3],lunC[3]; double phase,discFrac,limb; // set lunar color (slightly brownish) lunC[0] = 1.05; lunC[1] = 1.00; lunC[2] = 0.85; // should really modify this near the horizon! // get moon position ln_get_lunar_equ_coords (jd, &equ); ln_get_hrz_from_equ (&equ, &obs, jd, &hrz); // 360 deg azimuth is due South, 270 is due East // position in vector format lunPos[0] = -sin(hrz.az*DEGTORAD)*cos(hrz.alt*DEGTORAD); lunPos[1] = -cos(hrz.az*DEGTORAD)*cos(hrz.alt*DEGTORAD); lunPos[2] = sin(hrz.alt*DEGTORAD); fprintf(stdout,"\n# Lunar altitude %7.3f deg, azimuth %7.3f deg\n",hrz.alt,hrz.az); if (hrz.alt < -5.0) { return(FALSE); } // get phase and fraction illuminated phase = ln_get_lunar_phase(jd); discFrac = ln_get_lunar_disk(jd); // get disc size discSize = 2.*ln_get_lunar_sdiam(jd)/3600.0; fprintf(stdout,"# lunar phase %7.3f, disc illum fraction %7.3f, disc size %6.2f deg\n",phase,discFrac,discSize); // phase 0/360 is full, 180 is new // get phase details -- later // limb = ln_get_lunar_bright_limb(jd); // get altitude adjustment due to refraction (altitude, p in millibars, temp in C) adjAlt = ln_get_refraction_adj (hrz.alt,1010.,10.); // luminance is 1/449000 of full bright sun // and scaled by fraction visible lum = 15.6 * pow(discFrac,2); // moon is a source, like the sun fprintf(stdout,"void light lunar\n"); fprintf(stdout,"0\n0\n3 %g %g %g\n",lum*lunC[0],lum*lunC[1],lum*lunC[2]); // complete the moon fprintf(stdout,"lunar source moon\n"); fprintf(stdout,"0\n0\n4 %g %g %g %.3f\n",lunPos[0],lunPos[1],lunPos[2],discSize); return(TRUE); }
int main (int argc, char* argv[]) { double JD; struct ln_rect_posn moon; struct ln_equ_posn equ; struct ln_lnlat_posn ecl; struct ln_lnlat_posn observer; struct ln_rst_time rst; struct ln_zonedate rise, transit, set; /* observers location (Edinburgh), used to calc rst */ observer.lat = 55.92; /* 55.92 N */ observer.lng = -3.18; /* 3.18 W */ /* get the julian day from the local system time */ JD = ln_get_julian_from_sys(); printf ("JD %f\n",JD); /* get the lunar geopcentric position in km, earth is at 0,0,0 */ ln_get_lunar_geo_posn (JD, &moon, 0); printf ("lunar x %f y %f z %f\n",moon.X, moon.Y, moon.Z); /* Long Lat */ ln_get_lunar_ecl_coords (JD, &ecl, 0); printf ("lunar long %f lat %f\n",ecl.lng, ecl.lat); /* RA, DEC */ ln_get_lunar_equ_coords (JD, &equ); printf ("lunar RA %f Dec %f\n",equ.ra, equ.dec); /* moon earth distance */ printf ("lunar distance km %f\n", ln_get_lunar_earth_dist(JD)); /* lunar disk, phase and bright limb */ printf ("lunar disk %f\n", ln_get_lunar_disk(JD)); printf ("lunar phase %f\n", ln_get_lunar_phase(JD)); printf ("lunar bright limb %f\n", ln_get_lunar_bright_limb(JD)); /* rise, set and transit time */ if (ln_get_lunar_rst (JD, &observer, &rst) == 1) printf ("Moon is circumpolar\n"); else { ln_get_local_date (rst.rise, &rise); ln_get_local_date (rst.transit, &transit); ln_get_local_date (rst.set, &set); print_date ("Rise", &rise); print_date ("Transit", &transit); print_date ("Set", &set); } /* rise, set and transit time */ if (ln_get_lunar_rst (JD - 24, &observer, &rst) == 1) printf ("Moon is circumpolar\n"); else { ln_get_local_date (rst.rise, &rise); ln_get_local_date (rst.transit, &transit); ln_get_local_date (rst.set, &set); print_date ("Rise", &rise); print_date ("Transit", &transit); print_date ("Set", &set); } /* rise, set and transit time */ if (ln_get_lunar_rst (JD - 25, &observer, &rst) == 1) printf ("Moon is circumpolar\n"); else { ln_get_local_date (rst.rise, &rise); ln_get_local_date (rst.transit, &transit); ln_get_local_date (rst.set, &set); print_date ("Rise", &rise); print_date ("Transit", &transit); print_date ("Set", &set); } return 0; }