Last active
December 17, 2015 23:29
-
-
Save Kirilliann/5689952 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function planetposition(Omega, w, jdn, lon, T, e, a, i, name, d, albedo){ | |
//Вычисляем положение | |
var Peri=Omega+w; //долгота перигелия | |
var rad=57.29577951; | |
var M=((jdn-2451920.5)/T)*360+lon-Peri; //средняя аномалия | |
//Решение уравнения кеплера - для планет достаточно одной итерации! | |
var ed=57.295779*e; | |
var E1=M+(ed*Math.sin(M/rad)/(1-e*Math.cos(M/rad))); | |
//Плоскость орбиты планеты, разложение её радиуса-ветора | |
var dzeta=a*(Math.cos(E1/rad)-e); | |
var nu=a*Math.sqrt(1-e*e)*Math.sin(E1/rad); | |
var r=a*(1-e*Math.cos(E1/rad)); | |
//вычисляем угол наклона эклиптики | |
var T21=(jdn-2451920.5)/36525; | |
var ecl=23.43929111+(46.815/3600)*T21+(0.0059/3600)*T21*T21; | |
//===============Преобразование координат===================== | |
var a1=Math.cos(Omega/rad); | |
var a2=Math.sin(Omega/rad); | |
var a3=0; | |
var b1=-Math.sin(Omega/rad)*Math.cos(i/rad); | |
var b2=Math.cos(Omega/rad)*Math.cos(i/rad); | |
var b3=Math.sin(i/rad); | |
var P1=a1*Math.cos(w/rad)+b1*Math.sin(w/rad); | |
var P12=a2*Math.cos(w/rad)+b2*Math.sin(w/rad); | |
var P13=a3*Math.cos(w/rad)+b3*Math.sin(w/rad); | |
var Q1=b1*Math.cos(w/rad)-a1*Math.sin(w/rad); | |
var Q12=b2*Math.cos(w/rad)-a2*Math.sin(w/rad); | |
var Q13=b3*Math.cos(w/rad)-a3*Math.sin(w/rad); | |
var P2=P12*Math.cos(ecl/rad)-P13*Math.sin(ecl/rad); | |
var P3=P12*Math.sin(ecl/rad)+P13*Math.cos(ecl/rad); | |
var Q2=Q12*Math.cos(ecl/rad)-Q13*Math.sin(ecl/rad); | |
var Q3=Q12*Math.sin(ecl/rad)+Q13*Math.cos(ecl/rad); | |
var x=P1*dzeta+Q1*nu; | |
var y=P2*dzeta+Q2*nu; | |
var z=P3*dzeta+Q3*nu; | |
//========================================================== | |
//==================вычисление положения Земли========================== | |
var t1=(jdn-2433282)/365.25; | |
var T2=(t1/100); | |
var L=100.00532+359.9937288*t1; | |
var L1=L+180; | |
var l1=358.47583+35999.04972*T2+0.00015*T2*T2; | |
var p=1.0014-0.01643*Math.cos(l1/rad)-0.00014*Math.cos(2*l1/rad); | |
var lambda=L1+1.9171*Math.sin(l1/rad)+0.0200*Math.sin(2*l1/rad)+0.0003*Math.sin(3*l1/rad); | |
var X0=p*Math.cos(lambda/rad); | |
var Y0=p*Math.sin(lambda/rad); | |
var Z0=0; | |
var Xs=X0; | |
var Ys=Y0*Math.cos(ecl/rad); | |
var Zs=Y0*Math.sin(ecl/rad); | |
//=============================================Взаимное местоположение планеты и Земли============= | |
var Xm=x+Xs; | |
var Ym=y+Ys; | |
var Zm=z+Zs; | |
//=================================Экваториальные координаты============================================================================ | |
var alpha1=Math.atan2(Ym,Xm)*rad/15; | |
if (alpha1<0){ | |
alpha1=alpha1+24; | |
} | |
var lko=Math.sqrt((Xm*Xm)+(Ym*Ym)); | |
var delta1=Math.atan2(Zm,lko)*rad; | |
if (i==0){ //Для Солнца сразу установим блес | |
var m1=-26; | |
var phase=1; | |
var dia1=0 | |
}else{ | |
var dlt=Math.sqrt(Xm*Xm+Ym*Ym+Zm*Zm);//Вычисление расстояния | |
var dia1=(d/(dlt*150e6))*206265; //видимый диаметр | |
var phase=(r+dlt+1)*(r+dlt-1)/(4*r*dlt);//фаза | |
/* | |
Блеск | |
*/ | |
var dm=-26.5+5*Math.log(r)/Math.log(10); | |
var ep=2.5*Math.log(albedo*Math.pow((d/150e6), 2)*Math.pow(r, 2)/Math.pow(dlt*r, 2))/Math.log(10); | |
var dm1=2.5*Math.log(Math.abs(1/phase))/Math.log(10); | |
var m1=dm-ep+dm1;//блеск | |
} | |
return ([alpha1, delta1, m1, phase, dia1]); | |
} | |
function draw(ctx, d, i, phase, name, date){ | |
drawp(d,phase,i*70,100,name,date, name) | |
} | |
/* | |
Функция отрисовки фазы планеты | |
*/ | |
function drawp(r,ph,xc,yc,name,date) { | |
//Канвас и контекст | |
var canvas=document.getElementById("planetsmap"); | |
var ctx=canvas.getContext("2d"); | |
ctx.strokeStyle="#808080"; //линии обводки | |
ctx.beginPath(); | |
ctx.fillStyle="#808080"; //цвет заливки | |
ctx.font = "bold 6px sans-serif"; //шрифт | |
ctx.lineWidth=1; | |
ctx.moveTo(35, 150); | |
ctx.lineTo(65,150); | |
ctx.font = "bold 10px sans-serif"; | |
ctx.fillText ('10"', 45, 140); | |
ctx.font = " 17px sans-serif"; | |
ctx.fillStyle="#ffffff"; | |
ctx.fillText ('Видимые размеры планет и их фаза на '+date, 50, 20); | |
ctx.stroke(); | |
ctx.closePath(); | |
ctx.beginPath(); | |
ctx.arc(xc,yc,r,Math.PI*0.5, Math.PI*1.5, false); | |
ctx.fillStyle="#808080"; | |
ctx.strokeStyle="#F0E68C"; | |
ctx.font = " 12px sans-serif"; | |
ctx.fillText (name, xc, (yc+r+20)); | |
ph=2*(ph-0.5) //фазовый коэффициент | |
/* пошагам рисуем первый лимб*/ | |
var y1=-1; | |
do{ | |
ctx.lineWidth=0; | |
y12=y1; | |
x1=ph*Math.sqrt(r*r-y12*y12); | |
y1=y1+0.1; | |
x2=ph*Math.sqrt(r*r-y1*y1); | |
xt=-Math.sqrt(r*r-y1*y1); | |
ctx.moveTo((x1+xc), (y12+yc)); | |
ctx.lineTo((x2+xc),(y1+yc)); | |
ctx.lineWidth=1; | |
ctx.lineTo((xt+xc),(y1+yc)); | |
} while(y1<=r) | |
/* и второй*/ | |
y1=-1; | |
do{ | |
y12=y1; | |
x1=ph*Math.sqrt(r*r-y12*y12); | |
y1=y1+0.1; | |
x2=ph*Math.sqrt(r*r-y1*y1); | |
xt=Math.sqrt(r*r-y1*y1); | |
ctx.lineWidth=0; | |
ctx.moveTo((x1+xc), (-y12+yc)); | |
ctx.lineTo((x2+xc),(-y1+yc)); | |
ctx.lineWidth=1; | |
ctx.lineTo((-xt+xc),(-y1+yc)); | |
} while(y1<=r) | |
ctx.stroke(); | |
ctx.closePath(); | |
} | |
function drawEllipse(ctx, x, y, a, b, color) { | |
ctx.fillStyle=color | |
ctx.strokeStyle=color; | |
ctx.save(); | |
ctx.beginPath(); | |
ctx.translate(x, y); | |
ctx.scale(a / b, 1); | |
ctx.arc(0, 0, b, 0, Math.PI * 2, true); | |
ctx.fill(); | |
ctx.restore(); | |
ctx.closePath(); | |
ctx.stroke(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment