1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<math.h>
#define pi 3.1416
float solve_Kepler_for_E_B(float M,float e){
float tpl,breakflag,E1,tol,E;
tol = 1.e-09;
breakflag = 0;
E1 = M;
while (breakflag == 0){
E = M + e*sin(E1);
if (abs(E - E1) < tol){
breakflag = 1;
}
E1 = E;
}
while (E > (2*pi)){
E = E - 2*pi;
}
while (E < 0){
E = E + 2*pi;
}
return E;
}
void compute_AZ_EL(float Mylat, float Mylongitude, int h , int m , int s, int yy, int dd , int mm,float *Azimut,float *Elevation,float *alp_deg )
{
float phi_heures,xeq,yeq,zeq,GMSTO,SIDTIME,ph_HA,x_sol,z_sol,xL,azimut,hauteur_deg;
float M_rad,E,cov,siv,xv,yv,r,v,v_deg,lon,x,y,z,d,w,e,M,L,obl,E_rad,LON,y_sol,lat,yL,zL;
int Y,Mois,D,heure,min,seconds,a;
Y=yy;Mois=mm;D=dd;heure=h;min=m;seconds=s;
LON=Mylongitude;
lat=Mylat;
d=367*Y-floor((7*(Y+floor((Mois+9)/12)))/4)+floor((275*Mois)/9)+D-730530;
//d = d+ (hour + min/60 + seconds/3600)/24;
w = 282.9404 + ((4.70935)*10e-5) *d ;a = 1;
e = 0.016709 - 1.151* 10e-9* d;
M = 356.0470 + 0.9856002585* d -floor((356.0470 + 0.9856002585* d)/360)*360;
L = w+M -floor((w+M)/360)*360;
obl = 23.4393 - 3.563* 10e-7* d;
M_rad = M*pi/180;
//Anomalie excentrique [rad]
E_rad = solve_Kepler_for_E_B(M_rad, e);
E=E_rad*180/pi;
// Anomalie vraie [rad]. On passe par les composantes de la position pour
// pouvoir utiliser la fonction atan2 de Matlab, ces termes correspondent à la formule 19
cov = (cos(E_rad)-e)/(1-e*cos(E_rad));
siv = sqrt(1-pow(e,2))*sin(E_rad)/(1-e*cos(E_rad));
xv = cov*a*(1-e*cos(E_rad));
yv = siv*a*(1-e*cos(E_rad));
r = sqrt(xv*xv+yv*yv);
v = atan2(siv,cov);
v_deg=v*180/pi;
lon = v_deg+w-floor((v_deg+w)/360)*360;
x=r*cos(lon*pi/180); y=r*sin(lon*pi/180); z=0;
//Coordonnées équatoriales
xeq=x; yeq=y*cos(obl*pi/180)-z*sin(obl*pi/180); zeq=y*sin(obl*pi/180)+z*cos(obl*pi/180);
// Ascension droite et déclinaison
phi_heures=(atan2(yeq,xeq))*12/pi;
//phi_deg=phi_heures*15;
*alp_deg=(atan2(zeq,sqrt(pow(xeq,2)+pow(yeq,2))))*180/pi;
GMSTO=(w+M - floor((w+M)/360)*360 +180)/15;
SIDTIME=GMSTO+heure+LON/15;
ph_HA=(SIDTIME-phi_heures)*15;
x_sol=cos(ph_HA*pi/180)*cos(*alp_deg*pi/180); y_sol=sin(ph_HA*pi/180)*cos(*alp_deg*pi/180);
z_sol=sin(*alp_deg*pi/180);
xL=x_sol*sin(lat*pi/180)-z_sol*cos(lat*pi/180); yL=y_sol; zL=x_sol*cos(lat*pi/180)+z_sol*sin(lat*pi/180);
*Azimut=atan2(yL,xL)*180/pi+180;
*Elevation=asin(zL)*180/pi;
}
int main(int argc, char *argv[])
{
float Azimut,Elevation,alp_deg;
// heure = 12; LON=4.3; lat=50.8 ; heure+1
//Mois=3;Y= 2010;D=16.5;
compute_AZ_EL(50.8,4.3,12 ,0 ,0, 2010, 16.5, 3,&Azimut,&Elevation,&alp_deg ) ;
printf("azimut: %f\n",Azimut);
printf("Elevation: %f\n",Elevation);
printf("alp_deg : %f\n",alp_deg );
system("PAUSE");
return 0;
} |