Está en la página 1de 6

kepler2.

//CONSTANTES GLOBALES
const double PI = acos(-1.);
const double AU = 1.495978707003e11; //Unidad astronomica (m/AU)
const double G = 6.67388e-11; //Constante gravitacional
const double Mo = 1.98852e30; //Masa del sol (kg)
const double TMAX = 365.25*24.*3600.; //Tiempo maximo 1 año (seg)
const int TICS = 500; //TICS de tiempo
const int NP = 5; //Numero de planetas

//FUNCION PARA OBTENER LAS RAICES DE LA ECUACION POR BISECCION


bool EncontroRaiz(double &x, char *funcion, double a, double b, double *par)
{
TF1 *f1 = new TF1("f1",funcion,a,b);
f1->SetParameters(par);
bool encontro = false;
while ((fabs(b - a) > 0.000001) && (encontro == false))
{
//CALCULAR VALOR MEDIO
x = (a + b)/2;
//VERIFICAR SI ENCONTRO LA RAIZ
if (fabs(f1->Eval(x)) < 0.000001) {encontro = true;}
//SELECCIONAR NUEVO INTERVALO
if (f1->Eval(a)*f1->Eval(x) > 0.0) {a = x;} else {b = x;}
}
return encontro;
}

void AnomaliaVerdadera(double t, double a, double e, double &xv, double &yv)


{
double par[2];
double E;

//MOVIMIENTO MEDIO
double omega = sqrt(G*Mo/pow(a*AU,3));

//ANOMALIA MEDIA
double M = omega*t;

//ANOMALIA EXCENTRICA
double par[2] = {M,e};
if (EncontroRaiz(E,"[0]+[1]*sin(x)-x",M-PI,M+PI,par) == false)
{
printf("No encontré la anomalia excéntrica ...\n");
printf("M = %lf, e = %lf\n",M,e);
exit(0);
}

//ANOMALIA VERDADERA
double r = a*(1 - e*cos(E));
double theta = 2.*atan(sqrt((1 + e)/(1 - e))*tan(E/2.));

//COORDENADAS XV,YV
xv = r*cos(theta) - a*e;
yv = r*sin(theta);
}

void kepler2()
{
double t;
double xv,yv; //Coordenadas anomalia verdadera
double r,theta; //Coordenadas polares
double a[NP] = {0.38709843,0.72332102,1.00000018,1.52371243,5.20248019};
double e[NP] = {0.20563661,0.00676399,0.01673163,0.09336511,0.04853590};

TCanvas *c1=new TCanvas("c1","Planeta", 10, 10, 600 , 600);


c1->SetFillColor(38);

TMultiGraph *mg = new TMultiGraph();


mg->SetMinimum(-6.);
mg->SetMaximum(+6.);

//GRAFICA SOL
TGraph *gs = new TGraph();
gs->SetMarkerStyle(kFullCircle);
gs->SetMarkerColor(kYellow);
gs->SetMarkerSize(1);
gs->SetPoint(0,0,0);
mg->Add(gs,"AP");

//GRAFICA PLANETA
TGraph *gp = new TGraph();
gp->SetMarkerStyle(kFullCircle);
gp->SetMarkerColor(kGray);
gp->SetMarkerSize(1);

////GRAFICAR ORBITAS
for (int np = 0; np < NP; np++)
{
TGraph *tp = new TGraph();
tp->SetLineStyle(kSolid);
tp->SetLineColor(kGray);
tp->SetLineWidth(1);
for (int i = 0; i <= 500; i++)
{
theta = double(i)*2.*PI/500.;
r = a[np]*(1. - e[np]*e[np])/(1. + e[np]*cos(theta));
tp->SetPoint(i,r*cos(theta)-a[np]*e[np],r*sin(theta));
}
mg->Add(tp,"L");
}

//EVOLUCION TEMPORAL
for (int i = 1; i <= TICS; i++)
{
t = double(i - 1)*TMAX/double(TICS - 1);
//printf("tic i = %i \t t = %lf s \n",i,t);
for (int np = 0; np < NP; np++)
{
//CALCULAR ANOMALIA VERDADERA
AnomaliaVerdadera(t,a[np],e[np],xv,yv);

//PLANETA1
gp->SetPoint(np,xv,yv);
mg->Add(gp,"P");

//GRAFICAR
mg->Draw("ALP");
mg->GetXaxis()->SetTitle("(AU)");
mg->GetYaxis()->SetTitle("(AU)");
mg->GetXaxis()->SetLimits(-6.,+6.);

//ACTUALIZAR PAD
gPad->Modified();
gPad->Update();
}
}
}
kepler3.C

//CONSTANTES GLOBALES
const double PI = acos(-1.);
const double AU = 1.495978707003e11; //Unidad astronomica (m/AU)
const double G = 6.67388e-11; //Constante gravitacional
const double Mo = 1.98852e30; //Masa del sol (kg)
const double TMAX = 150*365.25*24.*3600.; //Tiempo maximo 150 años (seg)
const int TICS = 300; //TICS de tiempo
const int NP = 5; //Numero de planetas

//FUNCION PARA OBTENER LAS RAICES DE LA ECUACION POR BISECCION


bool EncontroRaiz(double &x, char *funcion, double a, double b, double *par)
{
TF1 *f1 = new TF1("f1",funcion,a,b);
f1->SetParameters(par);
bool encontro = false;
while ((fabs(b - a) > 0.000001) && (encontro == false))
{
//CALCULAR VALOR MEDIO
x = (a + b)/2;
//VERIFICAR SI ENCONTRO LA RAIZ
if (fabs(f1->Eval(x)) < 0.000001) {encontro = true;}
//SELECCIONAR NUEVO INTERVALO
if (f1->Eval(a)*f1->Eval(x) > 0.0) {a = x;} else {b = x;}
}
return encontro;
}

void AnomaliaVerdadera(double t, double a, double e, double &xv, double &yv)


{
double par[2];
double E;

//MOVIMIENTO MEDIO
double omega = sqrt(G*Mo/pow(a*AU,3));

//ANOMALIA MEDIA
double M = omega*t;

//ANOMALIA EXCENTRICA
double par[2] = {M,e};
if (EncontroRaiz(E,"[0]+[1]*sin(x)-x",M-PI,M+PI,par) == false)
{
printf("No encontré la anomalia excéntrica ...\n");
printf("M = %lf, e = %lf\n",M,e);
exit(0);
}

//ANOMALIA VERDADERA
double r = a*(1 - e*cos(E));
double theta = 2.*atan(sqrt((1 + e)/(1 - e))*tan(E/2.));

//COORDENADAS XV,YV
xv = r*cos(theta) - a*e;
yv = r*sin(theta);
}

void kepler3()
{
double t;
double xv,yv; //Coordenadas anomalia verdadera
double r,theta; //Coordenadas polares
double a[NP] = {5.20248019,9.54149883,19.18797948,30.06952752,39.48686035};
double e[NP] = {0.04853590,0.05550825,0.04685740,0.00895439,0.24885238};

TCanvas *c1=new TCanvas("c1","Planeta", 10, 10, 600 , 600);


c1->SetFillColor(38);

TMultiGraph *mg = new TMultiGraph();


mg->SetMinimum(-70.);
mg->SetMaximum(+70.);

//GRAFICA SOL
TGraph *gs = new TGraph();
gs->SetMarkerStyle(kFullCircle);
gs->SetMarkerColor(kYellow);
gs->SetMarkerSize(1);
gs->SetPoint(0,0,0);
mg->Add(gs,"AP");

//GRAFICA PLANETA
TGraph *gp = new TGraph();
gp->SetMarkerStyle(kFullCircle);
gp->SetMarkerColor(kGray);
gp->SetMarkerSize(1);

////GRAFICAR ORBITAS
for (int np = 0; np < NP; np++)
{
TGraph *tp = new TGraph();
tp->SetLineStyle(kSolid);
tp->SetLineColor(kGray);
tp->SetLineWidth(1);
for (int i = 0; i <= 500; i++)
{
theta = double(i)*2.*PI/500.;
r = a[np]*(1. - e[np]*e[np])/(1. + e[np]*cos(theta));
tp->SetPoint(i,r*cos(theta)-a[np]*e[np],r*sin(theta));
}
mg->Add(tp,"L");
}

//EVOLUCION TEMPORAL
for (int i = 1; i <= TICS; i++)
{
t = double(i - 1)*TMAX/double(TICS - 1);
//printf("tic i = %i \t t = %lf s \n",i,t);
for (int np = 0; np < NP; np++)
{
//CALCULAR ANOMALIA VERDADERA
AnomaliaVerdadera(t,a[np],e[np],xv,yv);

//PLANETA1
gp->SetPoint(np,xv,yv);
mg->Add(gp,"P");

//GRAFICAR
mg->Draw("ALP");
mg->GetXaxis()->SetTitle("(AU)");
mg->GetYaxis()->SetTitle("(AU)");
mg->GetXaxis()->SetLimits(-70.,+70.);

//ACTUALIZAR PAD
gPad->Modified();
gPad->Update();
}
}
}