#include #include #include #include typedef struct punct{ int x,y; }punct; typedef struct punctreal{ //centrul cercului circumscris double x,y; }punctreal; punct a,b,c; punctreal O;//centrul cercului double r; void citire_triunghi(){ printf("coordonatele punctului A sunt:"); scanf("%d %d",&a.x,&a.y); printf("coordonatele punctului B sunt:"); scanf("%d %d",&b.x,&b.y); printf("coordonatele punctului C sunt:"); scanf("%d %d",&c.x,&c.y); } void desenare_triunghi(punct a, punct b, punct c){ moveto(a.x,a.y); setcolor(BLUE); line(a.x,a.y,b.x,b.y); line(b.x,b.y,c.x,c.y); line(c.x,c.y,a.x,a.y); setcolor(RED); outtextxy(a.x,a.y,"A"); outtextxy(b.x,b.y,"B"); outtextxy(c.x,c.y,"C"); } punctreal centru_cerc(punct a, punct b,punct c){ punctreal centru; double D,Dm,Dn; D=(double)(b.x-a.x)*(c.y-a.y)-(double)(b.y-a.y)-(c.x-a.x); D=-4*D; Dm=(pow(a.x,2)+pow(a.y,2))*(b.y-c.y)+(pow(b.x,2)+pow(b.y,2))*(c.y-a.y)+(pow(c.x,2)+pow(c.y,2))*(a.y-b.y); Dm=-2*Dm; Dn=(pow(a.x,2)+pow(a.y,2))*(b.x-c.x)+(pow(b.x,2)+pow(b.y,2))*(c.x-a.x)+(pow(c.x,2)+pow(c.y,2)0*(a.x-b.x); Dn=2*Dn; if(D==0) printf("puncte coliniare"); else{ centru.x=Dm/D; centru.y=Dn/D; } return centru; } double raza_cerc(punct a,punct b,punct c){ punctreal centru; double raza; centru=centru_cerc(a,b,c); raza=sqrt((centru.x-a.x)*(centru.x-a.x)+(centru.y-a.y)*(centru.y-a.y)); return raza; } double distanta(punct p, punct q){ return sqrt(pow(p.x-q.x,2)+pow(p.y-q.y,2)); } punctreal centrucercinscris(punct A,punct B, punct C){ double a=distanta(B,C); double b=distanta(A,C); double c=distanta(A,B); double p=a+b+c; punctreal centru; centru.x=A.x*a/p+B.x*b/p+C.x*c/p; centru.y=A.y*a/p+B.y*b/p+C.y*c/p; return centru; } double razacercinscris(punct A,punct B,punct C){ double a=distanta(B,C); double b=distanta(A,C); double c=distanta(A,B); double p=a+b+c/2; double S=fabs(((double)(B.x-A.x)*(C.y-A.y)-(double)(B.y-A.y)*(C.x-A.x))/2); double raza=S/p; return raza; } void main(){ punctreal I; double R; int gd=DETECT,gm; citire_triunghi(); initgraph(&gd,&gm,"C:\\tc\\BGI"); desenare_triunghi(a,b,c); O=centru_cerc(a,b,c); r=raza_cerc(a,b,c); setcolor(RED); circle(O.x,O.y);//deseneaza cercul de raza r circumscris setcolor(RED); circle(O.x,O.y,1); I=centrucercinscris(a,b,c); R=razacercinscris(a,b,c); setcolor(GREEN); circle(I.x,I.y,R);//deseneaza cercul de raza R inscris setcolor(GREEN);circle(I.x,I.y,1); getch(); closegraph(); }