#include<conio.h>
#include<iostream.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
class abs{
private:
float carga1,carga2,carga3,K;
unsigned int grado12,grado23,grado13;
float Fe12,Fe23,Fe13,Dist12,Dist23,Dist13;
unsigned int PI,c1x,c1y,c2x,c2y,c3x,c3y;
public:
void dibujar();
void borrar();
void calcular();
abs();
~abs();
}objabs;
void abs::dibujar()
{
setcolor(1);
circle(c2x,c2y,2);
circle(c3x,c3y,2);
circle(c1x,c1y,2);
}
void abs::borrar()
{
setcolor(9);
circle(c2x,c2y,2);
circle(c3x,c3y,2);
circle(c1x,c1y,2);
//setcolor(14);
line(c1x,c1y,c2x,c2y);
line(c2x,c2y,c3x,c3y);
line(c3x,c3y,c1x,c1y);
}
abs::abs()
{
PI=3.141592;
carga1=4e-6;
carga2=2e-6;
carga3=3e-6;
grado12=60;
grado13=60;
grado23=0;
K=9e9;
Dist12=0.2;
Dist13=0.2;
Dist23=0.2;
c2x=300;
c2y=250;
c3x=(Dist23*100)+c2x;
c3y=c2y;
c1x=((c2x+((Dist23*100)+c2x))/2);
c1y=c2y-(sin(PI*grado12/180)*20);
}
void abs::calcular()
{
Fe12=K*((carga1*carga2)/(pow(Dist12,2)));
Fe13=K*((carga1*carga3)/(pow(Dist13,2)));
Fe23=K*((carga2*carga3)/(pow(Dist23,2)));
int aux1x,aux1y,aux2x,aux2y,aux3x,aux3y;
aux1y=c1y-(((Fe13*sin(PI*grado13/180))+(Fe12*sin(PI*grado12/180))));
aux1x=c1x+(((Fe12*cos(PI*grado12/180))-(Fe13*cos(PI*grado13/180))));
aux2y=c2y+((Fe12*sin(PI*grado12/180))+(Fe23*sin(PI*grado23/180)));
aux2x=c2x-((Fe12*cos(PI*grado12/180))+(Fe23*cos(PI*grado23/180)));
aux3y=c3y+((Fe13*sin(PI*grado13/180))+(Fe23*sin(PI*grado23/180)));
aux3x=c3x+((Fe13*cos(PI*grado13/180))+(Fe23*cos(PI*grado23/180)));
c1y=aux1y;
c1x=aux1x;
c2y=aux2y;
c2x=aux2x;
c3y=aux3y;
c3x=aux3x;
}
void inicializar()
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "a:\BGI");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}
setbkcolor(9);
}
abs::~abs()
{
}
main()
{
int tiempo;
clrscr();
inicializar();
for(tiempo=0;tiempo<500;tiempo++){
tiempo+=10;
objabs.dibujar();
if(tiempo==10)
getch();
delay(100);
objabs.borrar();
objabs.calcular();
}
objabs.dibujar();
outtextxy(550,470,"5 segundos");
getch();
closegraph();
//cout<<tiempo/100<<" segundos";
//getch();
return 0;
}