0% found this document useful (0 votes)
92 views30 pages

Astronomyformula

This document contains code for astronomy.js, a JavaScript library for general astronomy calculations. It defines numeric constants, custom trigonometry functions, and classes for astronomical objects like the Sun and Earth. Functions calculate positions, distances, and other properties for different coordinate systems.

Uploaded by

palharjeet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views30 pages

Astronomyformula

This document contains code for astronomy.js, a JavaScript library for general astronomy calculations. It defines numeric constants, custom trigonometry functions, and classes for astronomical objects like the Sun and Earth. Functions calculate positions, distances, and other properties for different coordinate systems.

Uploaded by

palharjeet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

27/03/2017 cosinekitty.com/astronomy.

js

/*
astronomy.jsbyDonCrosshttp://cosinekitty.com

Generalpurposeastronomycalculationroutines.
Designedforusebyhtml,svg,andcscript/wscript.
*/

//
//Numericconstants...

varMETERS_PER_ASTRONOMICAL_UNIT=1.4959787e+11;
varMETERS_PER_EARTH_EQUATORIAL_RADIUS=6378140.0;
varEARTH_RADII_PER_ASTRONOMICAL_UNIT=METERS_PER_ASTRONOMICAL_UNIT/
METERS_PER_EARTH_EQUATORIAL_RADIUS;//23454.78

//
//Customtrigonometryandmathfunctions.
//Wedomostofourmathinangulardegreesandsideralhours,insteadofradians.

functionAngleClass()
{
this.DEG_FROM_RAD=180.0/Math.PI;
this.RAD_FROM_DEG=Math.PI/180.0;
this.HOURS_FROM_RAD=12.0/Math.PI;
this.RAD_FROM_HOURS=Math.PI/12.0;

this.CosDeg=function(degrees)
{
returnMath.cos(this.RAD_FROM_DEG*degrees);
}

this.SinDeg=function(degrees)
{
returnMath.sin(this.RAD_FROM_DEG*degrees);
}

this.TanDeg=function(degrees)
{
returnMath.tan(this.RAD_FROM_DEG*degrees);
}

this.CosHour=function(hours)
{
returnMath.cos(this.RAD_FROM_HOURS*hours);
}

this.SinHour=function(hours)
{
returnMath.sin(this.RAD_FROM_HOURS*hours);
}

this.AtanDeg2=function(y,x)
{
returnthis.DEG_FROM_RAD*Math.atan2(y,x);
}

this.FixHours=function(hours)
{
returnthis.FixCycle(hours,24.0);
}

this.FixDegrees=function(degrees)
{
returnthis.FixCycle(degrees,360.0);
}

this.FixCycle=function(angle,cycle)
{
varfraction=angle/cycle;
http://cosinekitty.com/astronomy.js 1/30
27/03/2017 cosinekitty.com/astronomy.js

returncycle*(fractionMath.floor(fraction));
}

this.Polar=function(x,y,z)
{
varrho=(x*x)+(y*y);
varradius=Math.sqrt(rho+(z*z));
varphi=Angle.AtanDeg2(y,x);
if(phi<0){
phi+=360.0;
}
varrho=Math.sqrt(rho);
vartheta=Angle.AtanDeg2(z,rho);
returnnewSphericalCoordinates(phi,theta,radius);
}

this.DMS=function(x)
{
vara={};

a.negative=(x<0);
if(a.negative){
x=x;
}

a.degrees=Math.floor(x);
x=60.0*(xa.degrees);
a.minutes=Math.floor(x);
x=60.0*(xa.minutes);
a.seconds=Math.round(10.0*x)/10.0;//Roundtothenearesttenthofanarcsecond.

if(a.seconds==60){
a.seconds=0;
if(++a.minutes==60){
a.minutes=0;
++a.degrees;
}
}

returna;
}

this.DMM=function(x)
{
vara={};
a.negative=(x<0);
if(a.negative){
x=x;
}

a.degrees=Math.floor(x);
x=60.0*(xa.degrees);
a.minutes=Math.round(100.0*x)/100.0;//Roundtonearesthundredthofan
arcminute.
a.seconds=0.0;//FillinjustforconsistencywithAngle.DMS

if(a.minutes>=60.0){
a.minutes=60.0;
++a.degrees;
}

returna;
}

this.SafeArcSinInDegrees=function(z)
{
varabs=Math.abs(z);
if(abs>1.0){
//GuardagainstblowingupduetoslightroundofferrorsinMath.Asin...

http://cosinekitty.com/astronomy.js 2/30
27/03/2017 cosinekitty.com/astronomy.js

if(abs>1.00000001){
throw"InvalidargumenttoSafeArcSinInDegrees";
}elseif(z<1.0){
return90.0;
}else{
return+90.0;
}
}else{
returnthis.DEG_FROM_RAD*Math.asin(z);
}
}
}

varAngle=newAngleClass();

//

functionDefaultGeocentricCoordinates(day)//thisfunctionisusedformostcelestialbodies
(butnottheMoon)
{
varbc=this.EclipticCartesianCoordinates(day);//getthisbody's
heliocentriccoordinates
varec=Astronomy.Earth.EclipticCartesianCoordinates(day);//getEarth'sheliocentric
coordinates
returnbc.Subtract(ec);//subtractvectorstogetthevectorfromEarthtothisbody
}

functionDefaultEclipticAngularCoordinates(day)
{
varhc=this.EclipticCartesianCoordinates(day);
varac=Angle.Polar(hc.x,hc.y,hc.z);
returnac;
}

functionDefaultHorizontalCoordinates(day,location)
{
varsky=this.EquatorialCoordinates(day,location);
returnnewHorizontalCoordinates(sky,location,day);
}

functionLog10(x)
{
returnMath.log(x)/Math.LN10;
}

//

functionSunClass()
{
this.Name="Sun";

this.EclipticCartesianCoordinates=function(day)
{
returnnewCartesianCoordinates(0.0,0.0,0.0);
}

this.EclipticAngularCoordinates=function(day)
{
returnnewSphericalCoordinates(0.0,0.0,0.0);
}

this.GeocentricCoordinates=DefaultGeocentricCoordinates;
this.EquatorialCoordinates=EqCoords;

this.DistanceFromEarth=function(day)
{
returnAstronomy.Earth.EclipticCartesianCoordinates(day).Distance();
}

http://cosinekitty.com/astronomy.js 3/30
27/03/2017 cosinekitty.com/astronomy.js


this.DistanceFromSun=function(day)
{
return0.0;
}

this.HorizontalCoordinates=DefaultHorizontalCoordinates;

this.RadiusInMeters=6.96e+8;

this.VisualMagnitude=function(day)
{
vare=this.DistanceFromEarth(day);
return26.73+(5.0*Log10(e));
}
}

//

functionEarthClass()
{
this.Name="Earth";

this.EclipticCartesianCoordinates=function(day)
{
//WeuseformulasforfindingtheSunasseenfromEarth,
//thennegatethe(x,y,z)coordinatesobtainedtogettheEarth'sposition
//fromtheSun'sperspective.

//http://www.astro.uio.no/~bgranslo/aares/calculate.html<==Noteerrorinformula
forDS,usingsin(RS)whereitshouldsaysin(LS)
//http://www.meteorobs.org/maillist/msg09197.html<==Correctformulas,more
accurate(complex)

//Theseformulasuse'd'basedondayssince1/Jan/200012:00UTC("J2000.0"),insteadof
0/Jan/20000:00UTC("dayvalue").
//Correctbysubtracting1.5days...
vard=day1.5;
varT=d/36525.0;//JuliancenturiessinceJ2000.0
varL0=280.46645+(36000.76983*T)+(0.0003032*T*T);//Sun'smean
longitude,indegrees
varM0=357.52910+(35999.05030*T)(0.0001559*T*T)(0.00000048*T*T*T);
//Sun'smeananomaly,indegrees

varC=//Sun'sequationofcenterindegrees
(1.9146000.004817*T0.000014*T*T)*Angle.SinDeg(M0)+
(0.019930.000101*T)*Angle.SinDeg(2*M0)+
0.000290*Angle.SinDeg(3*M0)
;

varLS=L0+C;//trueeclipticallongitudeofSun

vare=0.016708617T*(0.000042037+(0.0000001236*T));//Theeccentricityof
theEarth'sorbit.
vardistanceInAU=(1.000001018*(1e*e))/(1+e*Angle.CosDeg(M0+C));//
distancefromSuntoEarthinastronomicalunits(AU)
varx=distanceInAU*Angle.CosDeg(LS);
vary=distanceInAU*Angle.SinDeg(LS);
returnnewCartesianCoordinates(x,y,0.0);//theEarth'scenterisalwaysonthe
planeoftheecliptic(z=0),bydefinition!
}

this.EclipticAngularCoordinates=DefaultEclipticAngularCoordinates;

this.GeocentricCoordinates=function(day)
{
returnnewCartesianCoordinates(0.0,0.0,0.0);
}

http://cosinekitty.com/astronomy.js 4/30
27/03/2017 cosinekitty.com/astronomy.js

this.EquatorialCoordinates=EqCoords;

this.DistanceFromEarth=function(day)
{
return0.0;//includedforcompletenessandconsistencyofplanetinterface
}

this.DistanceFromSun=function(day)
{
returnthis.EclipticCartesianCoordinates(day).Distance();
}

this.VisualMagnitude=function(day)
{
throw"CannotcalculatevisualmagnitudeforEarth!";
}
}

//
//WetreatPlutoasaspecialcase.Seehttp://www.stjarnhimlen.se/comp/ppcomp.html#14

functionPlutoClass()
{
this.Name="Pluto";
this.EclipticCartesianCoordinates=function(day)
{
varS=50.03+(0.033459652*day);
varP=238.95+(0.003968789*day);

varlonecl=238.9508+(0.00400703*day)
19.799*Angle.SinDeg(P)+19.848*Angle.CosDeg(P)+
0.897*Angle.SinDeg(2*P)4.956*Angle.CosDeg(2*P)+
0.610*Angle.SinDeg(3*P)+1.211*Angle.CosDeg(3*P)
0.341*Angle.SinDeg(4*P)0.190*Angle.CosDeg(4*P)+
0.128*Angle.SinDeg(5*P)0.034*Angle.CosDeg(5*P)
0.038*Angle.SinDeg(6*P)+0.031*Angle.CosDeg(6*P)+
0.020*Angle.SinDeg(SP)0.010*Angle.CosDeg(SP)
;

varlatecl=3.9082
5.453*Angle.SinDeg(P)14.975*Angle.CosDeg(P)+
3.527*Angle.SinDeg(2*P)+1.673*Angle.CosDeg(2*P)
1.051*Angle.SinDeg(3*P)+0.328*Angle.CosDeg(3*P)+
0.179*Angle.SinDeg(4*P)0.292*Angle.CosDeg(4*P)+
0.019*Angle.SinDeg(5*P)+0.100*Angle.CosDeg(5*P)
0.031*Angle.SinDeg(6*P)0.026*Angle.CosDeg(6*P)+
0.011*Angle.CosDeg(SP)
;

varr=40.72+
6.68*Angle.SinDeg(P)+6.90*Angle.CosDeg(P)
1.18*Angle.SinDeg(2*P)0.03*Angle.CosDeg(2*P)+
0.15*Angle.SinDeg(3*P)0.14*Angle.CosDeg(3*P)
;

varcoslon=Angle.CosDeg(lonecl);
varsinlon=Angle.SinDeg(lonecl);
varcoslat=Angle.CosDeg(latecl);
varsinlat=Angle.SinDeg(latecl);

varxp=r*coslon*coslat;
varyp=r*sinlon*coslat;
varzp=r*sinlat;

returnnewCartesianCoordinates(xp,yp,zp);//theEarth'scenterisalwaysonthe
planeoftheecliptic(z=0),bydefinition!
}

this.HorizontalCoordinates=DefaultHorizontalCoordinates;

http://cosinekitty.com/astronomy.js 5/30
27/03/2017 cosinekitty.com/astronomy.js

this.EclipticAngularCoordinates=DefaultEclipticAngularCoordinates;
this.GeocentricCoordinates=DefaultGeocentricCoordinates;
this.EquatorialCoordinates=EqCoords;
this.DistanceFromEarth=function(day)
{
returnthis.GeocentricCoordinates(day).Distance();
}

this.DistanceFromSun=function(day)
{
returnthis.EclipticCartesianCoordinates(day).Distance();
}

this.VisualMagnitude=function(day)
{
vars=this.DistanceFromSun(day);
vare=this.DistanceFromEarth(day);
return14.0+(5.0*Log10((e*s)/(31.97177*31.982)));//ahackthatignores
phaseangle,basedondatafromhttp://www.heavensabove.com
}
}

//

functionPlanetPS(//Seehttp://www.stjarnhimlen.se/comp/ppcomp.html#4
name,//nameoftheobject,e.g."Mars"
N0,Nc,//N0=longitudeoftheascendingnode(deg).Nc=rateofchangeindeg/day
i0,ic,//inclinationtotheecliptic(deg)
w0,wc,//argumentofperihelion(deg)
a0,ac,//semimajoraxis,ormeandistancefromSun(AU)
e0,ec,//eccentricity(0=circle,0..1=ellipse,1=parabola)
M0,Mc,//M0=meananomaly(deg)(0atperihelion;increasesuniformlywithtime).Mc
("meanmotion")=rateofchangeindeg/day=360/period
magBase,
magPhaseFactor,
magNonlinearFactor,
magNonlinearExponent)
{
this.Name=name;
this.BodyType='planet';
this.N0=N0;
this.Nc=Nc;
this.i0=i0;
this.ic=ic;
this.w0=w0;
this.wc=wc;
this.a0=a0;
this.ac=ac;
this.e0=e0;
this.ec=ec;
this.M0=M0;
this.Mc=Mc;
this.magBase=magBase;
this.magPhaseFactor=magPhaseFactor;
this.magNonlinearFactor=magNonlinearFactor;
this.magNonlinearExponent=magNonlinearExponent;
}

PlanetPS.prototype.HorizontalCoordinates=DefaultHorizontalCoordinates;
PlanetPS.prototype.EclipticAngularCoordinates=DefaultEclipticAngularCoordinates;

PlanetPS.prototype.MeanAnomaly=function(day)//day=numberofdayselapsedsinceDecember
31,19990:00UTC,i.e.JD2451543.5
{
returnthis.M0+(day*this.Mc);
}

PlanetPS.prototype.NodeLongitude=function(day)
{

http://cosinekitty.com/astronomy.js 6/30
27/03/2017 cosinekitty.com/astronomy.js

returnthis.N0+(day*this.Nc);
}

PlanetPS.prototype.Perihelion=function(day)
{
returnthis.w0+(day*this.wc);
}

PlanetPS.prototype.GeocentricCoordinates=DefaultGeocentricCoordinates;
PlanetPS.prototype.EquatorialCoordinates=EqCoords;

PlanetPS.prototype.EclipticCartesianCoordinates=function(day)
{
vara=this.a0+(day*this.ac);
vare=this.e0+(day*this.ec);
varM=this.M0+(day*this.Mc);
varN=this.N0+(day*this.Nc);
varw=this.w0+(day*this.wc);
vari=this.i0+(day*this.ic);
varE=EccentricAnomaly(e,M);

//Calculatethebody'spositioninitsownorbitalplane,anditsdistancefromthethingit
isorbiting.
varxv=a*(Angle.CosDeg(E)e);
varyv=a*(Math.sqrt(1.0e*e)*Angle.SinDeg(E));

varv=Angle.AtanDeg2(yv,xv);//Trueanomalyindegrees:theanglefromperihelion
ofthebodyasseenbytheSun.
varr=Math.sqrt(xv*xv+yv*yv);//DistancefromtheSuntotheplanetinAU

varcosN=Angle.CosDeg(N);
varsinN=Angle.SinDeg(N);
varcosi=Angle.CosDeg(i);
varsini=Angle.SinDeg(i);
varcosVW=Angle.CosDeg(v+w);
varsinVW=Angle.SinDeg(v+w);

//Nowwearereadytocalculate(unperturbed)eclipticcartesianheliocentriccoordinates.
varxh=r*(cosN*cosVWsinN*sinVW*cosi);
varyh=r*(sinN*cosVW+cosN*sinVW*cosi);
varzh=r*sinVW*sini;

returnthis.Perturb(xh,yh,zh,day);
}

PlanetPS.prototype.Perturb=function(xh,yh,zh,day)
{
//Bydefaultweapplynoperturbations.
//Someplanetswilloverridethismethodsothattheycancorrectfor
//thegravitationalinfluencesofotherplanets.
returnnewCartesianCoordinates(xh,yh,zh);
}

PlanetPS.prototype.DistanceFromEarth=function(day)//returnsthedistanceofthisplanet
fromEarthinastronomicalunits(AU)
{
returnthis.GeocentricCoordinates(day).Distance();
}

PlanetPS.prototype.DistanceFromSun=function(day)
{
returnthis.EclipticCartesianCoordinates(day).Distance();
}

PlanetPS.prototype.VisualMagnitude=function(day)
{
vardistEarth=this.DistanceFromEarth(day);

http://cosinekitty.com/astronomy.js 7/30
27/03/2017 cosinekitty.com/astronomy.js

vardistSun=this.DistanceFromSun(day);
varphase=Astronomy.SunEarthPhaseAngle(this,day);
varmag=this.magBase+(5*Log10(distSun*distEarth))+(this.magPhaseFactor*phase);
if(this.magNonlinearExponent>0){
mag+=this.magNonlinearFactor*Math.pow(phase,this.magNonlinearExponent);
}
returnmag;
}

functionEccentricAnomaly(e,M)
{
varE=M+(e*Angle.SinDeg(M)*(1.0+(e*Angle.CosDeg(M))));
for(;;){
varF=E(E(Angle.DEG_FROM_RAD*e*Angle.SinDeg(E))M)/(1e*Angle.CosDeg
(E));
varerror=Math.abs(FE);
E=F;
if(error<1.0e8){
break;//theangleisgoodenoughnowforourpurposes
}
}

returnE;
}

functionPerturbMajorPlanet(xh,yh,zh,d)
{
varecliptic=Astronomy.EclipticLatLon(xh,yh,zh);
varlonecl=ecliptic.longitude;
varlatecl=ecliptic.latitude;

varr=Math.sqrt(xh*xh+yh*yh+zh*zh);

lonecl+=this.PerturbEclipticLongitude(d);
latecl+=this.PerturbEclipticLatitude(d);

varcoslon=Angle.CosDeg(lonecl);
varsinlon=Angle.SinDeg(lonecl);
varcoslat=Angle.CosDeg(latecl);
varsinlat=Angle.SinDeg(latecl);

varxp=r*coslon*coslat;
varyp=r*sinlon*coslat;
varzp=r*sinlat;

returnnewCartesianCoordinates(xp,yp,zp);
}

functionPerturbEclipticLongitude_Jupiter(d)
{
varMj=Astronomy.Jupiter.MeanAnomaly(d);
varMs=Astronomy.Saturn.MeanAnomaly(d);

vardeltaLong=
0.332*Angle.SinDeg(2*Mj5*Ms67.6)
0.056*Angle.SinDeg(2*Mj2*Ms+21)+
0.042*Angle.SinDeg(3*Mj5*Ms+21)
0.036*Angle.SinDeg(Mj2*Ms)+
0.022*Angle.CosDeg(MjMs)+
0.023*Angle.SinDeg(2*Mj3*Ms+52)
0.016*Angle.SinDeg(Mj5*Ms69)
;

returndeltaLong;
}

http://cosinekitty.com/astronomy.js 8/30
27/03/2017 cosinekitty.com/astronomy.js

functionPerturbEclipticLatitude_Jupiter(d)
{
return0.0;
}

functionPerturbEclipticLongitude_Saturn(d)
{
varMj=Astronomy.Jupiter.MeanAnomaly(d);
varMs=Astronomy.Saturn.MeanAnomaly(d);

vardeltaLong=
0.812*Angle.SinDeg(2*Mj5*Ms67.6)
0.229*Angle.CosDeg(2*Mj4*Ms2.0)+
0.119*Angle.SinDeg(Mj2*Ms3.0)+
0.046*Angle.SinDeg(2*Mj6*Ms69.0)+
0.014*Angle.SinDeg(Mj3*Ms+32.0)
;

returndeltaLong;
}

functionPerturbEclipticLatitude_Saturn(d)
{
varMj=Astronomy.Jupiter.MeanAnomaly(d);
varMs=Astronomy.Saturn.MeanAnomaly(d);

vardeltaLat=
0.020*Angle.CosDeg(2*Mj4*Ms2)+
0.018*Angle.SinDeg(2*Mj6*Ms49)
;

returndeltaLat;
}

functionPerturbEclipticLongitude_Uranus(d)
{
varMj=Astronomy.Jupiter.MeanAnomaly(d);
varMs=Astronomy.Saturn.MeanAnomaly(d);
varMu=this.MeanAnomaly(d);

vardeltaLong=
+0.040*Angle.SinDeg(Ms2*Mu+6)
+0.035*Angle.SinDeg(Ms3*Mu+33)
0.015*Angle.SinDeg(MjMu+20)
;

returndeltaLong;
}

functionPerturbEclipticLatitude_Uranus(d)
{
return0.0;
}

functionEqCoords(day,location)
{
varvectorFromEarth=this.GeocentricCoordinates(day);
vardx=vectorFromEarth.x;
vardy=vectorFromEarth.y;
vardz=vectorFromEarth.z;

//Now(dx,dy,dz)comprisethevectorfromtheEarthtotheobjectincartesianecliptic
coordinates.
//Weconvertheretoequatorialcoordinates,usingformulasbasedontheprecessionofthe
Earth'saxisofrotation.

http://cosinekitty.com/astronomy.js 9/30
27/03/2017 cosinekitty.com/astronomy.js

varT=Astronomy.CenturiesSinceJ2000(day);
varK=23.4392911((46.8150*T)(0.00059*T*T)+(0.001813*T*T*T))/3600.0;
//obliquityofeclipticindegrees.
varcosK=Angle.CosDeg(K);
varsinK=Angle.SinDeg(K);

//Calculateequatorialcartesiancoordinatesusingeclipticcartesiancoordinates...
varqx=dx;
varqy=(dy*cosK)(dz*sinK);
varqz=(dy*sinK)+(dz*cosK);

vareq=Angle.Polar(qx,qy,qz);
eq.longitude/=15.0;//convertdegreestosiderealhours

varDEC=eq.latitude;
varRA=eq.longitude;
vardistanceInAU=eq.radius;

//Determinewhetheratopocentriccorrectioniswarranted.
//ImaginetheanglebetweenthethecenteroftheEarth(geocentric),theremotebody,
//andtheobserveronthesurfaceoftheEarth(topocentric).
//Ifthisangleislessthan1arcminute,wewon'tbotherwiththeextracalculationtime.
//Useapproximationtodeterminewhethertheparallaxmatters:
//asin(RE/r)>=1"whereRE=radiusofEarth,r=distancetoCelestialBody.
//RE/r>=pi/(180*3600)
varparallaxInRadians=1.0/(EARTH_RADII_PER_ASTRONOMICAL_UNIT*distanceInAU);
if(parallaxInRadians>=Math.PI/(180.0*3600.0)){
//Wewereusingtheapproximationthatparallax=asin(parallax).
//Nowthatweknowtheparallaxissignificant,goaheadandcalculatetheexactangle.
parallaxInRadians=Math.asin(parallaxInRadians);

//Itiseasiertocalculatetopocentriccorrectioninhorizontalcoordinates...
varhor=newHorizontalCoordinates(eq,location,day,0.0);

vargclat;
varrho;

if(Astronomy.CorrectForOblateEarth){
gclat=OblateLatitudeCorrection(location.latitude);
rho=OblateRadiusCorrection(location.latitude);
}else{
gclat=location.latitude;
rho=1.0;
}

varaltitude=hor.altitude((Angle.DEG_FROM_RAD*parallaxInRadians)*Angle.CosDeg
(hor.altitude));
varLs=MeanLongitudeOfSun(day);
varGMST0=(Ls+180.0)/15.0;
varutcHours=(dayMath.floor(day))*24.0;
varLST=GMST0+utcHours+(location.longitude/15.0);
varhourAngle=LSTeq.longitude;
varg=Angle.DEG_FROM_RAD*(Math.atan(Angle.TanDeg(gclat)/Angle.CosHour(hourAngle)));

vartopRA=eq.longitude((parallaxInRadians*Angle.HOURS_FROM_RAD)*rho*
Angle.CosDeg(gclat)*Angle.SinHour(hourAngle)/Angle.CosDeg(eq.latitude));
vartopDEC;

if(Math.abs(g)<1.0e6){
topDEC=eq.latitude((parallaxInRadians*Angle.DEG_FROM_RAD)*rho*
Angle.SinDeg(eq.latitude)*Angle.CosHour(hourAngle));
}else{
topDEC=eq.latitude(parallaxInRadians*Angle.DEG_FROM_RAD)*rho*
Angle.SinDeg(gclat)*Angle.SinDeg(geq.latitude)/Angle.SinDeg(g);
}

eq=newSphericalCoordinates(topRA,topDEC,distanceInAU);
}

http://cosinekitty.com/astronomy.js 10/30
27/03/2017 cosinekitty.com/astronomy.js

returneq;
}

functionOblateLatitudeCorrection(latitude)
{
//ThisfunctioncorrectsfortheflatteningoftheEarthduetoitsrotation.
//Givenageographiclatitude(whichisdefinedbasedonthetiltofone'slocalhorizon),
//thisfunctionreturnsgeocentriclatitude(basedontheanglebetweentheequatorialplane
andthelocation).
//Thecorrectioniszeroattheequatorandatbothpoles,andismaximizedat|latitude|=
45degrees.
//See:
//http://en.wikipedia.org/wiki/Latitude#Common_.22latitude.22
//http://en.wikipedia.org/wiki/Latitude#Geocentric_latitude
returnlatitude(0.1924*Angle.SinDeg(2.0*latitude));
}

functionOblateRadiusCorrection(latitude)
{
//ReturnsthefractionofequatorialEarthradiusforsealevelatthegivengeographic
latitude.
//ThisisduetoflatteningcausedbyEarth'srotation.
//Whenlatitude==0(i.e.apointontheequator),thevaluereturnedis1.0.
//Thevalueisminimizedatlatitude==+90(NorthPole)orlatitude==90(SouthPole).
return0.99833+(0.00167*Angle.CosDeg(2.0*latitude));
}

functionHorizontalCoordinates(sky,location,day,horizonCorrectionInArcMinutes)
{
//http://en.wikipedia.org/wiki/Horizontal_coordinate_system

if(horizonCorrectionInArcMinutes==null){
horizonCorrectionInArcMinutes=34.0;
}

varGST=GreenwichSiderealTimeInHours(day);
varLST=GST+(location.longitude/15.0);
varhourAngle=Angle.FixHours(LSTsky.longitude);

varsinLat=Angle.SinDeg(location.latitude);
varcosLat=Angle.CosDeg(location.latitude);

varsinHourAngle=Angle.SinHour(hourAngle);
varcosHourAngle=Angle.CosHour(hourAngle);

varsinDec=Angle.SinDeg(sky.latitude);
varcosDec=Angle.CosDeg(sky.latitude);

varaltitudeRatio=(sinLat*sinDec)+(cosLat*cosDec*cosHourAngle);
//Correctforvaluesthatareoutofrangeforinversesinefunction...
varabsAltitudeRatio=Math.abs(altitudeRatio);
if(absAltitudeRatio>1.0){
if(absAltitudeRatio>1.000001){
//Thisisanexcessiveamountoferror:somethingmustbewrongwiththeformula!
throw("Internalerror:altitudewouldbeacomplexnumber!");
}else{
//Justcorrectforapparentroundoffwithoutgoingbezerk.
this.altitude=(altitudeRatio<0)?90.0:+90.0;
this.azimuth=180.0;//doesn'treallymatterwhatangleweassign:usethisvalue
toassistculminationalgorithm.
}
}else{
this.altitude=Angle.DEG_FROM_RAD*Math.asin(altitudeRatio);
varabsAltitude=Math.abs(this.altitude);
varANGLE_CORRECTION_WINDOW=6.0;//Ichose6degreesastherefractioncutoff,
becausethatisusedforCivilTwilight,whichshouldnotbecorrected.
if((absAltitude<ANGLE_CORRECTION_WINDOW)&&(horizonCorrectionInArcMinutes!=0.0)){
//http://www.jgiesen.de/refract/index.htmlFormoretechnicaldetails.
//Correctforatmosphericlensingmakingtheobjectappearhigherthanitwouldif

http://cosinekitty.com/astronomy.js 11/30
27/03/2017 cosinekitty.com/astronomy.js

theEarthhadnoatmosphere.
//Wewantthecorrectiontomaximizeitseffectatthehorizon,andvanishtozeroas
|altitude|approachesANGLE_CORRECTION_WINDOW.
//Forsimplicityweapplyalinearinterpolationwithinthisrangeofaltitudes.
varlinearFactor=(ANGLE_CORRECTION_WINDOWabsAltitude)/ANGLE_CORRECTION_WINDOW;
this.altitude=(horizonCorrectionInArcMinutes/60.0)*linearFactor;
}

this.azimuth=Angle.FixDegrees(Angle.AtanDeg2(cosDec*sinHourAngle,(cosLat*sinDec)
(sinLat*cosDec*cosHourAngle)));
}
}

functionGreenwichSiderealTimeInHours(day)
{
varmidnight=Math.floor(day);//discardfractionalparttogetsamecalendardayat
midnightUTC
varT0=Astronomy.CenturiesSinceJ2000(midnight);
vartUT=(daymidnight)*24.0;//Greenwichtimeofday,inhours
varSG=(6.6974+2400.0513*T0)+(366.2422/365.2422)*tUT;
SG=Angle.FixHours(SG);
returnSG;
}

//

functionCreateAsteroid(
name,//nameofasteroid
epochJD,//epochoforbitalelementsasJulianDate
Nx,//longitudeoftheascendingnodeatepoch,indegrees
i,//inclinationtotheecliptic,indegrees
w,//argumentofperihelion,indegrees
a,//semimajoraxisinAU
e,//eccentricity
Mx,//meananomalyatepoch,indegrees
T,//orbitalperiod,indays
amag)//absolutemagnitude
{
varday=epochJD2451543.5;//convertJulianDateto"0.0January2000"
standardepochdayvalue.
varMc=360.0/T;//"meanmotion":howmanydegreesperdaythe
bodyorbitsaroundtheSun,onaverage.
varM0=Angle.FixDegrees(MxMc*day);//workbackwardstofigureoutmeananomolyat
standardepoch.

varN0=Nx;//!!!FIXFIXFIX
varNc=0.0;//!!!FIXFIXFIX

varp=newPlanetPS(
name,
N0,Nc,
i,0.0,
w,0.0,
a,0.0,
e,0.0,
M0,Mc,
amag,
0.0,
0.0,
0.0
);

p.BodyType='asteroid';//changebodytypefrom'planet'to'asteroid'

returnp;
}

http://cosinekitty.com/astronomy.js 12/30
27/03/2017 cosinekitty.com/astronomy.js

functionCreateComet(/*seeargumentsforCreateAsteroid*/){
//Passalongthesameargumentsto"CreateAsteroid".
varcomet=CreateAsteroid.apply(this,arguments);
comet.BodyType='comet';//changebodytypefrom'asteroid'to'comet'.
returncomet;
}

functionCreateMinor(/*seeargumentsforCreateAsteroid*/){
//Passalongthesameargumentsto"CreateAsteroid".
varcomet=CreateAsteroid.apply(this,arguments);
comet.BodyType='minor';//indicatethatthisisaminorasteroid
returncomet;
}

functionCreatePlanetJPL(//DesignedforusewithJPLorbitaldata
name,//nameoftheobject,e.g."Mars"
ja0,jac,//semimajoraxis(AU),rate(AU/century)
je0,jec,//eccentricity(1),(1/century)
jI0,jIc,//inclination(deg),(deg/century)
jL0,jLc,//meanlongitude(deg),(deg/century)
ju0,juc,//longitudeofperihelion(deg),(deg/century)
jQ0,jQc,//longitudeofascendingnode(deg),(deg/century)
magBase,
magPhaseFactor,
magNonlinearFactor,
magNonlinearExponent)
{
//ConvertunitsandepochfromJPLformattoPlanetPSformat.
//http://ssd.jpl.nasa.gov/txt/aprx_pos_planets.pdf
//http://ssd.jpl.nasa.gov/txt/p_elem_t1.txt
vardpc=36525.0;//dayspercentury
varcofs=1.5/dpc;//centuriesthatJPLepoch(J2000=1/1/200012UT)isaheadofPS
(12/31/19990UT)

varN0=jQ0cofs*jQc;
varNc=jQc/dpc;

vari0=jI0cofs*jIc;
varic=jIc/dpc;

//w=jujQ
varw0=Angle.FixDegrees((ju0cofs*juc)(jQ0cofs*jQc));
varwc=(jucjQc)/dpc;

vara0=ja0cofs*jac;
varac=jac/dpc;

vare0=je0cofs*jec;
varec=jec/dpc;

//M=jLju
varM0=Angle.FixDegrees((jL0cofs*jLc)(ju0cofs*juc));
varMc=(jLcjuc)/dpc;

returnnewPlanetPS(
name,//nameoftheobject,e.g."Mars"
N0,Nc,//N0=longitudeoftheascendingnode(deg).Nc=rateofchangeindeg/day
i0,ic,//inclinationtotheecliptic(deg)
w0,wc,//argumentofperihelion(deg)
a0,ac,//semimajoraxis,ormeandistancefromSun(AU)
e0,ec,//eccentricity(0=circle,0..1=ellipse,1=parabola)
M0,Mc,//M0=meananomaly(deg)(0atperihelion;increasesuniformlywithtime).
Mc("meanmotion")=rateofchangeindeg/day=360/period
magBase,
magPhaseFactor,
magNonlinearFactor,
magNonlinearExponent
);
}

http://cosinekitty.com/astronomy.js 13/30
27/03/2017 cosinekitty.com/astronomy.js

functionCreateJupiter(){
varplanet=CreatePlanetJPL(
"Jupiter",
5.20288700,0.00011607,//ja0,jac=semimajoraxis(AU),rate(AU/century)
0.04838624,0.00013253,//je0,jec=eccentricity(1),(1/century)
1.30439695,0.00183714,//jI0,jIc=inclination(deg),(deg/century)
34.39644051,3034.74612775,//jL0,jLc=meanlongitude(deg),(deg/century)
14.72847983,0.21252668,//ju0,juc=longitudeofperihelion(deg),(deg/century)
100.47390909,0.20469106,//jQ0,jQc=longitudeofascendingnode(deg),
(deg/century)
9.25,0.014,0,0//visualmagnitudeelements)
);

planet.Perturb=PerturbMajorPlanet;//overridethedonothingmethodfromPlanetPS
planet.PerturbEclipticLongitude=PerturbEclipticLongitude_Jupiter;//methodcalledby
PerturbMajorPlanet
planet.PerturbEclipticLatitude=PerturbEclipticLatitude_Jupiter;//methodcalledby
PerturbMajorPlanet

returnplanet;
}

functionCreateSaturnJPL()
{
varplanet=CreatePlanetJPL(
"SaturnJPL",
9.53667594,0.00125060,//ja0,jac=semimajoraxis(AU),rate(AU/century)
0.05386179,0.00050991,//je0,jec=eccentricity(1),(1/century)
2.48599187,0.00193609,//jI0,jIc=inclination(deg),(deg/century)
49.95424423,1222.49362201,//jL0,jLc=meanlongitude(deg),(deg/century)
92.59887831,0.41897216,//ju0,juc=longitudeofperihelion(deg),(deg/century)
113.66242448,0.28867794,//jQ0,jQc=longitudeofascendingnode(deg),
(deg/century)
9.0,0.044,0,0//visualmagnitudeelements
);

planet.Perturb=PerturbMajorPlanet;//overridethedonothingmethodfromPlanetPS
planet.PerturbEclipticLongitude=PerturbEclipticLongitude_Saturn;//methodcalledby
PerturbMajorPlanet
planet.PerturbEclipticLatitude=PerturbEclipticLatitude_Saturn;//methodcalledby
PerturbMajorPlanet
planet.__BaseVisualMagnitude=planet.VisualMagnitude;//weoverridethebasefunctionto
alsoincludeafactorfortherings...

planet.VisualMagnitude=function(day)
{
varplanetMagnitude=this.__BaseVisualMagnitude(day);//getmagnitudeoftheplanet
bodyitself.

varIr=28.06;//inclinationofSaturn'sringstoecliptic,indegrees
varcosIr=Angle.CosDeg(Ir);
varsinIr=Angle.SinDeg(Ir);

vargc=this.GeocentricCoordinates(day);
varLos=Angle.FixDegrees(Angle.AtanDeg2(gc.y,gc.x));
varLas=Angle.FixDegrees(Angle.AtanDeg2(gc.z,Math.sqrt(gc.x*gc.x+gc.y*gc.y)));
varsinLas=Angle.SinDeg(Las);
varcosLas=Angle.CosDeg(Las);
varNr=169.51+(3.82e5*day);//ascendingnodeoftheplaneofSaturn'srings
varsinLosMinusNr=Angle.SinDeg(LosNr);

varB=Math.asin(sinLas*cosIrcosLas*sinIr*sinLosMinusNr);
varsinB=Math.abs(Math.sin(B));//???canwegetridofdoingbothAsinandSin?

varringMagnitude=(2.6*Math.abs(sinB))+(1.2*sinB*sinB);
returnplanetMagnitude+ringMagnitude;
}

http://cosinekitty.com/astronomy.js 14/30
27/03/2017 cosinekitty.com/astronomy.js

returnplanet;
}

functionCreateSaturn()
{
varplanet=newPlanetPS(
"Saturn",
113.6634,2.3898e5,2.4886,1.081e7,339.3939,2.97661e5,9.55475,0.0,0.055546,
9.499e9,316.9670,0.0334442282,//orbitalelements
9.0,0.044,0,0//visualmagnitudeelements
);

planet.Perturb=PerturbMajorPlanet;//overridethedonothingmethodfromPlanetPS
planet.PerturbEclipticLongitude=PerturbEclipticLongitude_Saturn;//methodcalledby
PerturbMajorPlanet
planet.PerturbEclipticLatitude=PerturbEclipticLatitude_Saturn;//methodcalledby
PerturbMajorPlanet
planet.__BaseVisualMagnitude=planet.VisualMagnitude;//weoverridethebasefunctionto
alsoincludeafactorfortherings...

planet.VisualMagnitude=function(day)
{
varplanetMagnitude=this.__BaseVisualMagnitude(day);//getmagnitudeoftheplanet
bodyitself.

varIr=28.06;//inclinationofSaturn'sringstoecliptic,indegrees
varcosIr=Angle.CosDeg(Ir);
varsinIr=Angle.SinDeg(Ir);

vargc=this.GeocentricCoordinates(day);
varLos=Angle.FixDegrees(Angle.AtanDeg2(gc.y,gc.x));
varLas=Angle.FixDegrees(Angle.AtanDeg2(gc.z,Math.sqrt(gc.x*gc.x+gc.y*gc.y)));
varsinLas=Angle.SinDeg(Las);
varcosLas=Angle.CosDeg(Las);
varNr=169.51+(3.82e5*day);//ascendingnodeoftheplaneofSaturn'srings
varsinLosMinusNr=Angle.SinDeg(LosNr);

varB=Math.asin(sinLas*cosIrcosLas*sinIr*sinLosMinusNr);
varsinB=Math.abs(Math.sin(B));//???canwegetridofdoingbothAsinandSin?

varringMagnitude=(2.6*Math.abs(sinB))+(1.2*sinB*sinB);
returnplanetMagnitude+ringMagnitude;
}

returnplanet;
}

functionCreateUranus()
{
varplanet=CreatePlanetJPL(
"Uranus",
19.18916464,0.00196176,//ja0,jac=semimajoraxis(AU),rate(AU/century)
0.04725744,0.00004397,//je0,jec=eccentricity(1),(1/century)
0.77263783,0.00242939,//jI0,jIc=inclination(deg),(deg/century)
313.23810451,428.48202785,//jL0,jLc=meanlongitude(deg),(deg/century)
170.95427630,0.40805281,//ju0,juc=longitudeofperihelion(deg),(deg/century)
74.01692503,0.04240589,//jQ0,jQc=longitudeofascendingnode(deg),
(deg/century)
7.15,0.001,0,0//visualmagnitudeelements
);

planet.Perturb=PerturbMajorPlanet;//overridethedonothingmethodfromPlanetPS
planet.PerturbEclipticLongitude=PerturbEclipticLongitude_Uranus;//methodcalledby
PerturbMajorPlanet
planet.PerturbEclipticLatitude=PerturbEclipticLatitude_Uranus;//methodcalledby
PerturbMajorPlanet

returnplanet;

http://cosinekitty.com/astronomy.js 15/30
27/03/2017 cosinekitty.com/astronomy.js

//

functionMeanAnomalyOfSun(d)
{
return356.0470+(0.9856002585*d);
}

functionSunArgumentOfPerihelion(d)
{
return282.9404+(4.70935e5*d);
}

functionMeanLongitudeOfSun(d)
{
returnMeanAnomalyOfSun(d)+SunArgumentOfPerihelion(d);
}

functionCreateMoon()
{
varmoon=newPlanetPS(
"Moon",
125.1228,0.0529538083,5.1454,0,318.0634,0.1643573223,60.2666/
EARTH_RADII_PER_ASTRONOMICAL_UNIT,0,0.054900,0,115.3654,13.0649929509,
0.23,0.026,4.0e9,4
);

moon.EclipticCartesianCoordinates=function(day)
{
varmc=this.GeocentricCoordinates(day);
varec=Astronomy.Earth.EclipticCartesianCoordinates(day);
returnec.Add(mc);
}

moon.GeocentricCoordinates=PlanetPS.prototype.EclipticCartesianCoordinates;//Moonuses
sameformulasasplanet,butresultsingeocentricvalues!

moon.Perturb=function(xh,yh,zh,d)
{
varMs=MeanAnomalyOfSun(d);//meananomalyofSun
varws=SunArgumentOfPerihelion(d);//Sun'sargumentofperihelion
varLs=Ms+ws;//meanlongitudeofSun

varMm=this.MeanAnomaly(d);//Moon'smeananomaly
varNm=this.NodeLongitude(d);//longitudeofMoon'snode
varwm=this.Perihelion(d);//Moon'sargumentofperihelion
varLm=Mm+wm+Nm;//MeanlongitudeoftheMoon

varD=LmLs;//meanelongationoftheMoon
varF=LmNm;//argumentoflatitudefortheMoon

vardeltaLong=
1.274*Angle.SinDeg(Mm2*D)+//theEvection
0.658*Angle.SinDeg(2*D)//theVariation
0.186*Angle.SinDeg(Ms)//theYearlyEquation
0.059*Angle.SinDeg(2*Mm2*D)
0.057*Angle.SinDeg(Mm2*D+Ms)+
0.053*Angle.SinDeg(Mm+2*D)+
0.046*Angle.SinDeg(2*DMs)+
0.041*Angle.SinDeg(MmMs)
0.035*Angle.SinDeg(D)//theParallacticEquation
0.031*Angle.SinDeg(Mm+Ms)
0.015*Angle.SinDeg(2*F2*D)+
0.011*Angle.SinDeg(Mm4*D)
;

vardeltaLat=
0.173*Angle.SinDeg(F2*D)

http://cosinekitty.com/astronomy.js 16/30
27/03/2017 cosinekitty.com/astronomy.js

0.055*Angle.SinDeg(MmF2*D)
0.046*Angle.SinDeg(Mm+F2*D)+
0.033*Angle.SinDeg(F+2*D)+
0.017*Angle.SinDeg(2*Mm+F)
;

vardeltaRadius=
0.58*Angle.CosDeg(Mm2*D)
0.46*Angle.CosDeg(2*D)
;

varecliptic=Astronomy.EclipticLatLon(xh,yh,zh);
varlonecl=ecliptic.longitude;
varlatecl=ecliptic.latitude;

varr=Math.sqrt(xh*xh+yh*yh+zh*zh);

lonecl+=deltaLong;
latecl+=deltaLat;
r+=deltaRadius/EARTH_RADII_PER_ASTRONOMICAL_UNIT;

varcoslon=Angle.CosDeg(lonecl);
varsinlon=Angle.SinDeg(lonecl);
varcoslat=Angle.CosDeg(latecl);
varsinlat=Angle.SinDeg(latecl);

varxp=r*coslon*coslat;
varyp=r*sinlon*coslat;
varzp=r*sinlat;

returnnewCartesianCoordinates(xp,yp,zp);
}

moon.RadiusInMeters=1.7374e+6;

returnmoon;
}

//

functionAstronomyClass()
{
this.DayValue=function(utc)
{
//http://www.elated.com/articles/workingwithdates/
//Returnnumberofdayssince0/Jan/200000:00UTC...
return1.0+(utc.getTime()Date.UTC(2000,0,1))/(3600.0*24.0*1000.0);
}

this.DaysSinceJ2000=function(day)
{
returnday1.5;
}

this.CenturiesSinceJ2000=function(day)
{
returnthis.DaysSinceJ2000(day)/36525.0;
}

this.CurrentDayValue=function(utc)
{
returnthis.DayValue(newDate());
}

this.DayValueToDate=function(day)
{
vardate=newDate();
varM=3600.0*24.0*1000.0;

http://cosinekitty.com/astronomy.js 17/30
27/03/2017 cosinekitty.com/astronomy.js

varT0=Date.UTC(2000,0,1);
date.setTime(M*(day1.0)+T0);
returndate;
}

this.EclipticLatLon=function(x,y,z)
{
return{'longitude':Angle.AtanDeg2(y,x),'latitude':Angle.AtanDeg2(z,Math.sqrt(x*x+
y*y))};
}

this.NextRiseTime=function(body,day,location)
{
returnAstronomy_FindNextTransition(body,day,day+1.1,location,
Astronomy_RiseCondition,3);
}

this.NextSetTime=function(body,day,location)
{
returnAstronomy_FindNextTransition(body,day,day+1.1,location,
Astronomy_SetCondition,3);
}

this.NextCulmTime=function(body,day,location)
{
returnAstronomy_FindNextTransition(body,day,day+1.1,location,
Astronomy_CulminateCondition,6);
}

this.NextNewMoon=function(day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(this.Moon,day,day+numDays,null,
Astronomy_RelativeLongitudeCondition,numIntervals,0.0);
}

this.NextMoonFirstQuarter=function(day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(this.Moon,day,day+numDays,null,
Astronomy_RelativeLongitudeCondition,numIntervals,90.0);
}

this.NextFullMoon=function(day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(this.Moon,day,day+numDays,null,
Astronomy_RelativeLongitudeCondition,numIntervals,180.0);
}

this.NextMoonThirdQuarter=function(day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(this.Moon,day,day+numDays,null,
Astronomy_RelativeLongitudeCondition,numIntervals,270.0);
}

this.NextOpposition=function(body,day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(body,day,day+numDays,null,
Astronomy_RelativeLongitudeCondition,numIntervals,180.0);
}

this.NextConjunction=function(body,day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(body,day,day+numDays,null,
Astronomy_RelativeLongitudeCondition,numIntervals,0.0);
}

this.NextMaxSunAngle=function(body,day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(body,day,day+numDays,null,
Astronomy_MaxSunAngleCondition,numIntervals);

http://cosinekitty.com/astronomy.js 18/30
27/03/2017 cosinekitty.com/astronomy.js

}

this.NextVernalEquinox=function(day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(this.Sun,day,day+numDays,null,
Astronomy_VernalEquinoxCondition,numIntervals);
}

this.NextAutumnalEquinox=function(day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(this.Sun,day,day+numDays,null,
Astronomy_AutumnalEquinoxCondition,numIntervals);
}

this.NextNorthernSolstice=function(day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(this.Sun,day,day+numDays,null,
Astronomy_NorthernSolsticeCondition,numIntervals);
}

this.NextSouthernSolstice=function(day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(this.Sun,day,day+numDays,null,
Astronomy_SouthernSolsticeCondition,numIntervals);
}

this.NextPeakVisualMagnitude=function(body,day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(body,day,day+numDays,null,
Astronomy_PeakVisualMagnitudeCondition,numIntervals);
}

this.NextMinAngleWithOtherBody=function(body,day,numDays,numIntervals,otherBody)
{
returnAstronomy_FindNextTransition(body,day,day+numDays,null,
Astronomy_MinAngleWithOtherBodyCondition,numIntervals,otherBody);
}

this.NextMoonPerigee=function(day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(null,day,day+numDays,null,
Astronomy_MoonPerigee,numIntervals,null);
}

this.NextMoonApogee=function(day,numDays,numIntervals)
{
returnAstronomy_FindNextTransition(null,day,day+numDays,null,Astronomy_MoonApogee,
numIntervals,null);
}

this.SunEarthPhaseAngle=function(body,day)
{
if(body.Name=="Sun"){
throw"CannotcalculateSunEarthPhaseAngleoftheSun";
}else{
varh=body.EclipticCartesianCoordinates(day);//a.k.a.Heliocentric
Coordinates
varg=body.GeocentricCoordinates(day);

//Wetakeadvantageofthefactthatwhentwolinescross,oppositeanglesareequal.
//Inotherwords,wewanttheanglebetween(h)and(g),whichisthesameasthe
anglebetweenhandg,
//because(h)dot(g)=hdotg:
//((hx)*(gx)=hx*gx,etc.

returnAngleBetweenVectorsInDegrees(h,g);
}
}

http://cosinekitty.com/astronomy.js 19/30
27/03/2017 cosinekitty.com/astronomy.js

this.AngleWithSunInDegrees=function(body,day)
{
if(body.Name=="Sun"){
return0.0;
}else{
vars=Astronomy.Sun.GeocentricCoordinates(day);
varb=body.GeocentricCoordinates(day);
returnAngleBetweenVectorsInDegrees(s,b);
}
}

this.AngleBetweenBodiesInDegrees=function(body1,body2,day)
{
vara=body1.GeocentricCoordinates(day);
varb=body2.GeocentricCoordinates(day);
returnAngleBetweenVectorsInDegrees(a,b);
}

this.RelativeLongitude=function(body,day)
{
//ReturnstherelativelongitudebetweenthebodyandtheSunasseenfromEarth's
center.
varbc=body.GeocentricCoordinates(day);
varsc=this.Sun.GeocentricCoordinates(day);

varblon=Angle.AtanDeg2(bc.y,bc.x);
varslon=Angle.AtanDeg2(sc.y,sc.x);
varrlon=Angle.FixDegrees(blonslon);
returnrlon;
}

this.PrecessionRotationMatrix=function(EPOCH1,EPOCH2)
{
varCDR=Math.PI/180.0;
varCSR=CDR/3600.0;
varT=0.001*(EPOCH2EPOCH1);
varST=0.001*(EPOCH11900.0);
varA=CSR*T*(23042.53+ST*(139.75+0.06*ST)+T*(30.230.27*ST+18.0*
T));
varB=CSR*T*T*(79.27+0.66*ST+0.32*T)+A;
varC=CSR*T*(20046.85ST*(85.33+0.37*ST)+T*(42.670.37*ST41.8*
T));
varSINA=Math.sin(A);
varSINB=Math.sin(B);
varSINC=Math.sin(C);
varCOSA=Math.cos(A);
varCOSB=Math.cos(B);
varCOSC=Math.cos(C);

varr=[[],[],[]];
r[0][0]=COSA*COSB*COSCSINA*SINB;
r[0][1]=COSA*SINBSINA*COSB*COSC;
r[0][2]=COSB*SINC;
r[1][0]=SINA*COSB+COSA*SINB*COSC;
r[1][1]=COSA*COSBSINA*SINB*COSC;
r[1][2]=SINB*SINC;
r[2][0]=COSA*SINC;
r[2][1]=SINA*SINC;
r[2][2]=COSC;

returnr;
}

//Wearetakingashortcutforcomputationalefficiency:
//Wecalculatetherotationmatrixforthecurrentdateasingletime,
//thenkeepusingit.Thiswillbeplentyaccurateforanything
//lessthanadecadebeforeorafterthecurrentdate.
//
this.ConstellationRotationMatrix=this.PrecessionRotationMatrix(newDate().getFullYear(),

http://cosinekitty.com/astronomy.js 20/30
27/03/2017 cosinekitty.com/astronomy.js

1875);

/*
ThePrecessEquatorialCoordinates()functionwastranslatedfromCtoC#byDonCross,
thentoJavascriptbyDonCross,basedon
codewithoriginalcommentsthus:

Thisprogramisatranslationwithafewadaptationsofthe
Fortranprogram.f,madebyFO@CDS(francois@simbad.ustrasbg.fr)
inNovember1996.
*/
this.PrecessEquatorialCoordinates=function(eq,matrix)
{
//Donsays:intheoriginalCcode,theRA1andDEC1passedinwerealwaysinradians.
//Iwanttopassinhoursanddegrees,respectively,soconverttoradianshere...
varRA1=Angle.RAD_FROM_HOURS*eq.longitude;
varDEC1=Angle.RAD_FROM_DEG*eq.latitude;

/*Computeinputdirectioncosines*/
varA=Math.cos(DEC1);

varx1=[
A*Math.cos(RA1),
A*Math.sin(RA1),
Math.sin(DEC1)
];

/*Performtherotationtogetthedirectioncosinesatepoch2*/
varx2=[0.0,0.0,0.0];
for(vari=0;i<3;i++){
for(varj=0;j<3;j++){
x2[i]+=matrix[i][j]*x1[j];
}
}

//Donsays:formypurposes,IalwayswantRAinhoursandDECindegrees...
varRA2=Angle.HOURS_FROM_RAD*Math.atan2(x2[1],x2[0]);
if(RA2<0){
RA2+=24.0;
}

varDEC2=Angle.SafeArcSinInDegrees(x2[2]);

returnnewSphericalCoordinates(RA2,DEC2,eq.radius);
}

this.FindConstellation=function(eq)
{
vareqOld=this.PrecessEquatorialCoordinates(eq,this.ConstellationRotationMatrix);
varra=eqOld.longitude;
vardec=eqOld.latitude;
for(vari=0;i<ConstellationEdgeArray.length;++i){
vare=ConstellationEdgeArray[i];
if((e.DecBottom<=dec)&&(e.RaRight>ra)&&(e.RaLeft<=ra)){
varc=ConstellationByConciseName[e.ConciseName];
return{'ConciseName':e.ConciseName,'FullName':c.FullName,
'PossessiveName':c.PossessiveName};
}
}
returnnull;//notfound!
}

this.CorrectForOblateEarth=true;//Settofalseifoblatenessformulasturnoutto
haveproblems.

this.Sun=newSunClass();
this.Moon=CreateMoon();

this.Mercury=newPlanetPS("Mercury",48.3313,3.24587e5,7.0047,5.0e8,29.1241,

http://cosinekitty.com/astronomy.js 21/30
27/03/2017 cosinekitty.com/astronomy.js

1.01444e5,0.387098,0.0,0.205635,5.59e10,168.6562,4.0923344368,0.36,0.027,2.2e13,6);
this.Venus=newPlanetPS("Venus",76.6799,2.46590e5,3.3946,2.75e8,54.8910,1.38374e
5,0.723330,0.0,0.006773,1.302e9,48.0052,1.6021302244,4.34,0.013,4.2e7,3);
this.Earth=newEarthClass();
this.Mars=newPlanetPS("Mars",49.5574,2.11081e5,1.8497,1.78e8,286.5016,
2.92961e5,1.523688,0.0,0.093405,2.516e9,18.6021,0.5240207766,1.51,0.016,0,0);

//Asteroidsandcomets
//nameepochJDNx=longascnodei=inclination
w=argofperia=semimajoraxise=eccentricityMx=meananom@epochT=orbitalperiod
absmag
this.Ceres=CreateAsteroid("Ceres",2457000.5,80.32926547452543,10.59338616262872,
72.52203270043788,2.76750591440571,0.07582276595896797,95.98917578768719,1681.633163085685,
4.18);//http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=1
this.Pallas=CreateAsteroid("Pallas",2457000.5,173.0962475866183,34.84099788068097,
309.9303277309815,2.771606108489468,0.2312736282433415,78.22870368538561,1685.371678425934,
5.15);//http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=2
this.Juno=CreateAsteroid("Juno",2457000.5,169.8711811946533,12.98166179450518,
248.4099652667037,2.670700240558908,0.2554482627817375,33.07715332505229,1594.175554183099,
5.91);//http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=3
this.Vesta=CreateAsteroid("Vesta",2457000.5,103.8513672233257,7.140427316529066,
151.1985275178533,2.361793227026224,0.08874017002173754,20.86384148999364,1325.748779938602,
3.67);//http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=4
this.Ida=CreateMinor("Ida",2457000.5,324.0275757719688,1.132199172379656,
110.4961991586997,2.862142759005513,0.04143441719730059,276.9785940904641,1768.623391686735,
9.94);//http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=243
this.Gaspra=CreateMinor("Gaspra",2457000.5,253.1678768421052,4.102608826356864,
129.4892377057742,2.209868867807942,0.1734277243451101,293.2411112895537,1199.908645279267,
11.46);//http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=951
this.Comet_9P=CreateComet("9P/T1",2456717.5,68.88181348869867,10.50258430337173,
179.3031328527078,3.140094842040291,0.5115944387599365,203.237608505211,2032.415859334781,
13.10);//comet9P/Tempel1:http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=9P
this.Comet_19P=CreateComet("19P/B",2456870.5,75.3828362947892,30.36856213315691,
353.4432880799574,3.602573738021955,0.6255352567887734,316.6290089712147,2497.570436475743,
8.90);//comet19P/Borrelly:http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=19P
this.Comet_67P=CreateComet("67P/CG",2456981.5,50.14210951437195,7.040200902346087,
12.78560606538363,3.462817302992186,0.6409739314162571,319.3033467788339,2353.654952366357,
13.55);//comet67P/ChuryumovGerasimenko:http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=67P
this.Comet_81P=CreateComet("81P/W2",2456978.5,136.1250968664513,3.239043597517584,
41.68675738457102,3.448547391975779,0.5380434533956898,265.9016154674808,2339.121199169129,
8.60);//comet81P/Wild2:http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=81P

this.Jupiter=CreateJupiter();
this.Saturn=CreateSaturn();
//this.SaturnJPL=CreateSaturnJPL();
this.Uranus=CreateUranus();
this.Neptune=newPlanetPS("Neptune",131.7806,3.0173e5,1.7700,2.55e7,272.8461,
6.027e6,30.05826,3.313e8,0.008606,2.15e9,260.2471,0.005995147,6.90,0.001,0,0);
this.Pluto=newPlutoClass();

this.Body=[
this.Sun,
this.Mercury,
this.Venus,
this.Earth,
this.Moon,
this.Mars,
this.Ceres,
this.Pallas,
this.Juno,
this.Vesta,
this.Ida,
this.Gaspra,
this.Comet_9P,
this.Comet_19P,
this.Comet_67P,
this.Comet_81P,
this.Jupiter,
this.Saturn,

http://cosinekitty.com/astronomy.js 22/30
27/03/2017 cosinekitty.com/astronomy.js

//this.SaturnJPL,//notmuchbetterthanexistingSaturn...notreadyforpublish
this.Uranus,
this.Neptune,
this.Pluto
];

this.IsBodyName=function(name)
{
return(this[name]!=null)&&(this[name].Name==name);
}

this.PlanetNumber={
'Mercury':1,
'Venus':2,
'Earth':3,
'Mars':4,
'Jupiter':5,
'Saturn':6,
'Uranus':7,
'Neptune':8,
'Pluto':9
};
}

functionAstronomy_AngularRadius(body,day,location)
{
if(body.RadiusInMeters==null){
return0.0;
}else{
//FIXFIXFIX:uselocationtofigureoutdistancefrombodytoobserver,notjustcenter
ofEarth!
vardistance=body.DistanceFromEarth(day)*METERS_PER_ASTRONOMICAL_UNIT;
returnAngle.DEG_FROM_RAD*(body.RadiusInMeters/distance);
}
}

functionAstronomy_UpperLimbAltitude(body,day,location)
{
varaltitude=body.HorizontalCoordinates(day,location).altitude;
varradius=Astronomy_AngularRadius(body,day,location);
returnaltitude+radius;
}

functionAstronomy_RiseCondition(body,day1,day2,location)
{
//Returntrueifupperlimbofbodyrisesintherangeoftimet:day1<=t<=day2.
varaltitude1=Astronomy_UpperLimbAltitude(body,day1,location);
varaltitude2=Astronomy_UpperLimbAltitude(body,day2,location);
return(altitude1<=0.0)&&(altitude2>=0.0);
}

functionAstronomy_SetCondition(body,day1,day2,location)
{
//Returntrueifupperlimbofbodysetsintherangeoftimet:day1<=t<=day2.
varaltitude1=Astronomy_UpperLimbAltitude(body,day1,location);
varaltitude2=Astronomy_UpperLimbAltitude(body,day2,location);
return(altitude1>=0.0)&&(altitude2<=0.0);
}

functionAstronomy_CulminateCondition(body,day1,day2,location)
{
//Returntrueifcenterofbodycrossesthemeridianbetweenday1andday2.
varculm=false;
varhc1=body.HorizontalCoordinates(day1,location);
//Figureoutiftheobjectcrossesthemeridianbetweenday1andday2.
//Thishappensiftheobjectmovesfromaneasternazimuthtoawesternazimuth.
//Anazimuthiseasternifsin(azimuth)>0,orwesternifsin(azimuth)<0.
//Thealtitudeatbothtimesmustbeabovethehorizon(altitude>0).
if(hc1.altitude>0){

http://cosinekitty.com/astronomy.js 23/30
27/03/2017 cosinekitty.com/astronomy.js

varsin1=Angle.SinDeg(hc1.azimuth);
if(sin1>=0){
varhc2=body.HorizontalCoordinates(day2,location);
if(hc2.altitude>0){
varsin2=Angle.SinDeg(hc2.azimuth);
if(sin2<=0){
culm=true;
}
}
}
}
returnculm;
}

functionAstronomy_MaxSunAngleCondition(body,day1,day2)
{
//Calculateslopesusingateensyweensyincrement.
//Wehavefoundthemaximumiftheangleisincreasingatday1anddecreasingatday2.

varday1b=day1+1.0e7;
varday2a=day21.0e7;

varsa1=Astronomy.AngleWithSunInDegrees(body,day1);
varsa1b=Astronomy.AngleWithSunInDegrees(body,day1b);
varsa2a=Astronomy.AngleWithSunInDegrees(body,day2a);
varsa2=Astronomy.AngleWithSunInDegrees(body,day2);

return(sa1<=sa1b)&&(sa2a>=sa2);
}

functionAstronomy_MoonApogee(body,day1,day2,location,otherBody)
{
//Theparameters'body','location','otherBody'areallunused.
//ReturntrueifMoonisatgreatestdistancefromEarth.

varday1b=day1+1.0e6;
varday2a=day21.0e6;

vardist1=Astronomy.Moon.DistanceFromEarth(day1);
vardist1b=Astronomy.Moon.DistanceFromEarth(day1b);
vardist2a=Astronomy.Moon.DistanceFromEarth(day2a);
vardist2=Astronomy.Moon.DistanceFromEarth(day2);

return(dist1b>=dist1)&&(dist2a>=dist2);
}

functionAstronomy_MoonPerigee(body,day1,day2,location,otherBody)
{
//Theparameters'body','location','otherBody'areallunused.
//ReturntrueifMoonisatgreatestdistancefromEarth.

varday1b=day1+1.0e7;
varday2a=day21.0e7;

vardist1=Astronomy.Moon.DistanceFromEarth(day1);
vardist1b=Astronomy.Moon.DistanceFromEarth(day1b);
vardist2a=Astronomy.Moon.DistanceFromEarth(day2a);
vardist2=Astronomy.Moon.DistanceFromEarth(day2);

return(dist1b<=dist1)&&(dist2a<=dist2);
}

functionAstronomy_MinDistance(body,day1,day2,location,otherBody)
{
varday1b=day1+1.0e7;
varday2a=day21.0e7;
}

http://cosinekitty.com/astronomy.js 24/30
27/03/2017 cosinekitty.com/astronomy.js

functionAstronomy_MinAngleWithOtherBodyCondition(body,day1,day2,location,otherBody)
{
varday1b=day1+1.0e7;
varday2a=day21.0e7;

varsa1=Astronomy.AngleBetweenBodiesInDegrees(body,otherBody,day1);
varsa1b=Astronomy.AngleBetweenBodiesInDegrees(body,otherBody,day1b);
varsa2a=Astronomy.AngleBetweenBodiesInDegrees(body,otherBody,day2a);
varsa2=Astronomy.AngleBetweenBodiesInDegrees(body,otherBody,day2);

return(sa1>=sa1b)&&(sa2a<=sa2);
}

functionAstronomy_PeakVisualMagnitudeCondition(body,day1,day2)
{
varday1b=day1+1.0e7;
varday2a=day21.0e7;

varm1=body.VisualMagnitude(day1);
varm1b=body.VisualMagnitude(day1b);
varm2a=body.VisualMagnitude(day2a);
varm2=body.VisualMagnitude(day2);

return(m1>=m1b)&&(m2a<=m2);
}

functionAstronomy_VernalEquinoxCondition(sun,day1,day2)
{
vargc1=sun.GeocentricCoordinates(day1);
vargc2=sun.GeocentricCoordinates(day2);
returngc1.x>0&&gc2.x>0&&gc1.y<=0&&gc2.y>=0;
}

functionAstronomy_AutumnalEquinoxCondition(sun,day1,day2)
{
vargc1=sun.GeocentricCoordinates(day1);
vargc2=sun.GeocentricCoordinates(day2);
returngc1.x<0&&gc2.x<0&&gc1.y>=0&&gc2.y<=0;
}

functionAstronomy_NorthernSolsticeCondition(sun,day1,day2)
{
vargc1=sun.GeocentricCoordinates(day1);
vargc2=sun.GeocentricCoordinates(day2);
returngc1.y>0&&gc2.y>0&&gc1.x>=0&&gc2.x<=0;
}

functionAstronomy_SouthernSolsticeCondition(sun,day1,day2)
{
vargc1=sun.GeocentricCoordinates(day1);
vargc2=sun.GeocentricCoordinates(day2);
returngc1.y<0&&gc2.y<0&&gc1.x<=0&&gc2.x>=0;
}

functionAstronomy_RelativeLongitudeCondition(body,day1,day2,location,longitude)
{
varlon1=Astronomy.RelativeLongitude(body,day1);
varlon2=Astronomy.RelativeLongitude(body,day2);
returnAnglesInOrder(lon1,longitude,lon2);
}

functionAnglesInOrder(a,b,c)
{
a=Angle.FixDegrees(a);
b=Angle.FixDegrees(b);
c=Angle.FixDegrees(c);

varMARGIN=45.0;

http://cosinekitty.com/astronomy.js 25/30
27/03/2017 cosinekitty.com/astronomy.js

if(c<a){
varswap=a;
a=c;
c=swap;
}

if(a<=MARGIN&&c>=360.0MARGIN){
//thisisthewraparoundcase
return((b>=0.0)&&(b<=a))||((b>=c)&&(b<=360.0));
}elseif(ca<=2*MARGIN){
return(a<=b)&&(b<=c);
}else{
throw"AnglesInOrdercontinuityfailure!";
}
}

functionAstronomy_FindNextTransition(body,startDay,endDay,location,condition,numIntervals,
customData)
{
vardt=(endDaystartDay)/numIntervals;
vart1=startDay;
for(vari=0;i<numIntervals;++i){
vart2=t1+dt;
if(condition(body,t1,t2,location,customData)){
if(dt<1.0e6){
returnt1+(0.5*dt);
}else{
varevt=Astronomy_FindNextTransition(body,t1,t2,location,condition,3,
customData);
if(evt==null){
returnt1+(0.5*dt);//somehowtheanswerslippedthroughthecracks:
sodothebestwecan
}else{
returnevt;
}
}
}

t1=t2;
}
returnnull;
}

//

functionCartesianCoordinates(x,y,z)
{
this.x=x;
this.y=y;
this.z=z;
}

CartesianCoordinates.prototype.toString=function()
{
return"("+this.x+","+this.y+","+this.z+")";
}

CartesianCoordinates.prototype.Distance=function()
{
returnMath.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);
}

CartesianCoordinates.prototype.Normalize=function()
{
varr=this.Distance();
if(r==0.0){
throw"Cannotnormalizezerovector.";

http://cosinekitty.com/astronomy.js 26/30
27/03/2017 cosinekitty.com/astronomy.js

}
returnnewCartesianCoordinates(this.x/r,this.y/r,this.z/r);
}

CartesianCoordinates.prototype.Subtract=function(other)
{
returnnewCartesianCoordinates(this.xother.x,this.yother.y,this.zother.z);
}

CartesianCoordinates.prototype.Add=function(other)
{
returnnewCartesianCoordinates(this.x+other.x,this.y+other.y,this.z+other.z);
}

functionAngleBetweenVectorsInDegrees(va,vb)
{
vara=va.Normalize();
varb=vb.Normalize();

//Thenormalizeddotproductoftwovectorsisequaltothecosineoftheanglebetweenthem.
vardotprod=a.x*b.x+a.y*b.y+a.z*b.z;
varabs=Math.abs(dotprod);
if(abs>1.0){
if(abs>1.00000001){
//Somethingisreallymessedup!AvoidimpossibleMath.Acos()argument...
throw"Internalerror:dotproduct="+dotprod;
}else{
//Assumethatroundofferrorhascausedavaliddotproductvaluetowanderoutside
allowedvaluesforMath.Acos()...
return(dotprod<0)?180.0:0.0;
}
}else{
returnAngle.DEG_FROM_RAD*Math.acos(dotprod);
}
}

//

functionSphericalCoordinates(longitude,latitude,radius)
{
this.longitude=longitude;
this.latitude=latitude;
this.radius=radius;
}

//

functionGeographicCoordinates(longitude,latitude,elevationInMetersAboveSeaLevel)
{
if(elevationInMetersAboveSeaLevel==null){
elevationInMetersAboveSeaLevel=0.0;
}

this.longitude=longitude;
this.latitude=latitude;
this.radius=(elevationInMetersAboveSeaLevel/METERS_PER_ASTRONOMICAL_UNIT)+
EARTH_RADII_PER_ASTRONOMICAL_UNIT;
}

//
//Createasingletoninstance"Astronomy",asasubstituteforanamespace...

varAstronomy=newAstronomyClass();

/*
$Log:astronomy.js,v$
Revision1.332009/03/0800:02:10Don.Cross
MyC#astro.exe(compiledassun.exe)nowhasa"javascript"optionthatgenerates

http://cosinekitty.com/astronomy.js 27/30
27/03/2017 cosinekitty.com/astronomy.js

constellation.js.
Thisnewconstellation.jsfilecontainsthedataneededforconstellationcalculationbasedon
equatorialcoordinates.
Iupdatedmyastronomy.jscodetoallowuseofthisdatatodetermineaconstellation.
Thepagesolar_system.htmlusesthisnowtoshowtheconciseconstellationsymbolforeach
celestialbody.

Revision1.322008/03/1921:43:36Don.Cross
Addedabilitytocalculatedate/timeofpeakvisualmagnitude.
FixedbugwherescriptcrashedinDecembermonthsduetoborkeduplineofcode.

Revision1.312008/03/1920:43:55Don.Cross
Implementedvisualmagnitudecalculation.
SolarSystempagedisplaysbothmagnitudeandsunanglenow.

Revision1.302008/03/1718:27:40Don.Cross
Calculateconjunctionsofplanets.Forinferiorplanets,distinguishbetweeninferiorand
superiorconjunctions.

Revision1.292008/03/1701:05:41Don.Cross
ImplementedmaxelongationformulasforMercuryandVenus.
IhadtotweaktheAstronomy_FindNextTransitiontoreturnalesspreciseanswerratherthan
justgiveup
whentheanswerslipsthroughthecracksduetoroundofferror.Thisseemstoworkfine,but
Iwillneedtokeepaneyeonit.

Revision1.282008/03/1622:54:47Don.Cross
Movednext/prev/currentcontrolsabovethecalendarsotheydon'tjumparound.
Nowcalculateoppositionsofsuperiorplanets.

Revision1.272008/03/1621:59:37Don.Cross
Implementedcalculationofequinoxesandsolstices.
Removedfixedheightofextrainfodivsothatitexpandswhentherearealotofeventson
oneday.
Addedlinkstootherastronomypages.

Revision1.262008/03/1620:40:09Don.Cross
NowcalculatingmoonphasesconsistentlywithSunCalc.exe(andSky&Telescopemagazineweb
site)
usingrelativelongitudewithSuninsteadofphaseangles.
Displayingfullmoonandnewmoonalso.

Revision1.252008/03/1620:07:07Don.Cross
Implementedcalculationofmoon'sfirstandthirdquarters.
AstronomyCalendarnowdisplaysgraphicsandaddsdetailsindetailbox.

Revision1.242008/03/0115:19:58Don.Cross
AddedAstronomy.IsBodyName().
Insteadofuglylinksfromplanetnamestocalculateextrainfo,madeselectbox
intheextrainfoboxitselftochoosetheobject.
Madethechoicepersistentviaacookie.

Revision1.232008/02/2823:28:11Don.Cross
Implementedcalculationofrise,set,andculminationofabody.
Whenuserclicksonabody'sname,displayrise,setandculminationtimesforit.
Defaulttoshowingsunrise,sunculmination,andsunset.

Revision1.222008/02/2721:36:12Don.Cross
Ihavechangedmymindaboutcorrectingaltitudebasedontheapparentangularradiusofthe
SunandMoon.
Itmakesmoresensetocalculateapparentaltitudeofthecenterofallobjects,butthento
knowthattheSunandMoon
haveasignificantangularradiusforthepurposesofriseandsettimes.
ThisalsoallowstheangularsizeoftheSunandMoontobecalculatedexactlybasedontheir
distancefromtheobserver.
Also,becauseCivil,Nautical,andAstronomicalTwilightaredefinedbyhowfarbelowthe
horizonthecenteroftheSunis,
Iconstrictedtheatmosphericcorrectionto6degreesinsteadof10degrees.CivilTwilight
iswhentheSunisat6degreesaltitude,

http://cosinekitty.com/astronomy.js 28/30
27/03/2017 cosinekitty.com/astronomy.js

soIwillbeabletocalculatethatinagreementwithothersources.

Revision1.212008/02/2702:27:49Don.Cross
Oops!ForgottogiveahorizoncorrectionforPluto!
ThisfixesaproblemwherealtitudeofPlutoshowsupas"NaN"whenitwaswithin10degrees
ofthehorizon.

Revision1.202008/02/2623:17:20Don.Cross
Implementedrefinementstotopocentricparallaxcorrection,factoringintheoblatenessofthe
Earth.

Revision1.192008/02/2221:52:18Don.Cross
ImplementedPluto.

Revision1.182008/02/2112:40:35Don.Cross
Nocodechange...justmadeindentationconsistenton1lineofcode.

Revision1.172008/02/1800:05:35Don.Cross
FixeddivisionbyzeroinHorizontalcoordinateconversionwhenlatitude=0.

Revision1.162008/02/1723:19:22Don.Cross
Gothorizontalcoordinatesworking!
Fixedbugsinsolar_system.htmlwithnotloading/applyingpolarityoflat/loncorrectly.

Revision1.152008/02/1720:07:16Don.Cross
Startingtoaddoptionstodisplaydifferentkindsofangularcoordinates.
Addingcontrolstoentergeographiccoordinates.

Revision1.142008/02/1602:59:59Don.Cross
DisplayRAandDECinniceHTMLformatwithhours/degrees,minutes,seconds.

Revision1.132008/02/1602:33:56Don.Cross
Implementedcalculationofequatorialcoordinates(RA,DEC),butnotyetwithtopocentric
parallaxcorrection.

Revision1.122008/02/1522:39:15Don.Cross
Renamed"Astronomy.Planet"arrayto"Astronomy.Body",andalsoincludesinittheSunand
Moon.
InthefutureImayincludesomefamouscometsandlargeasteroidsalso.

Revision1.112008/02/1521:14:10Don.Cross
ImplementedtheMoon.
Implementedgeocentriccoordinatesforallbodies.

Revision1.102008/02/1520:25:23Don.Cross
AddedSunasacelestialbody.

Revision1.92008/02/1516:56:13Don.Cross
FixedquirkinAstronomy.DayValuefunction:passing0asthedayvalue
toDate.UTCiswhatwascausinginconsistencyincscriptandhtmlversion
ofJavascript.WhenIpass1instead,theybothreturnthesame,correctvalue.

Revision1.82008/02/1515:03:20Don.Cross
ImplementedNeptune.
Implementedperturbationalgorithms,whichallowedimplementingJupiter,Saturn,andUranus.

Revision1.72008/02/1503:01:25Don.Cross
ImplementedMercuryandVenus.
Displaycoordinatesinatableinsteadofclunkytext.
Displaycoordinatesupdatedeverysecondinrealtime.

Revision1.62008/02/1423:25:56Don.Cross
FixedbuginAstronomyClass:wasoffby1day.
GotMarsworking,whichistheframeworkforMercuryandVenusaswell.
Todotheouterplanets(exceptPluto),Iwillneedtoimplementperturbation.
Plutoisaspecialcaseandwillbecodedseparately.

Revision1.52008/02/1422:36:05Don.Cross
Displayhumanfriendlydateandtimealongwithnumericdayvalue.

http://cosinekitty.com/astronomy.js 29/30
27/03/2017 cosinekitty.com/astronomy.js

Revision1.42008/02/1422:28:11Don.Cross
GotEarthcartesiancoordinateformulasworking.

Revision1.32008/02/1422:04:43Don.Cross
DefinedCartesianCoordinatesclass.
DiscovereditiseasytooverridetoString(),whichinturnoverridesdefaultbehaviorfor
convertingtostring.

Revision1.22008/02/1421:43:40Don.Cross
ImplementedAstronomy.DayValue()andAstronomy.CurrentDayValue().

Revision1.12008/02/1421:20:32Don.Cross
Ifiguredouthowtodotheequivalentof#includefromcscript.

*/

http://cosinekitty.com/astronomy.js 30/30

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy