/************************************************************** * The function Circle_Euler draws the Euler's circle of a * * triangle ABC with automatic scales. * * * * By J-P Moreau, Paris. * * (www.jpmoreau.fr) * **************************************************************/ #include void OutText(int ix,int iy,char *s); //Functions used here of Graph2D.cpp void Cercle(double xc,double yc,double r,int trait); void Initwindow(int,double,double,double,double); void MoveXY(double,double); void LineXY(double,double); void Legendes (int,char *,char *,char *,int,int,char *,int,int,char *); double a, b; //see Draw_Circle() extern MaxX, MaxY; //Solve linear system ax+b=c and a1x+b1y=c1. void System2D(double a,double b,double c,double a1,double b1,double c1, double *x, double *y) { if (fabs(b*a1-a*b1)<1e-12) OutText(10,10," * Error in System2D - System is singular!"); else { *y = (c*a1-c1*a)/(b*a1-a*b1); if (a!=0.0) *x = (c-b*(*y))/a; else *x = (c1-b1*(*y))/a1; } } //determine coefficients a, b of y=ax+b straight line passing //through 2 points (x1,y1) and (x2,y2). void Line2D(double x1,double y1,double x2,double y2, double *a, double *b) { System2D(x1,1.0,y1,x2,1.0,y2,a,b); } //Draw line y=ax+b from (x1,y1) to (x2,y2). void Draw_Line(double x1,double x2,double a,double b) { MoveXY(x1,a*x1+b); LineXY(x2,a*x2+b); } //Draw a circle passing through 3 points (x1,y1),(x2,y2),(x3,y3). void Draw_Circle3P(double x1,double y1,double x2,double y2,double x3,double y3) { double c,r; //coefficient c of circle equation //x²+y²-2ax-2by+c=0 and radius r. System2D(2.0*(x2-x1),2.0*(y2-y1),(x2*x2+y2*y2-x1*x1-y1*y1), 2.0*(x3-x1),2.0*(y3-y1),(x3*x3+y3*y3-x1*x1-y1*y1),&a,&b); c=2.0*a*x1+2.0*b*y1-x1*x1-y1*y1; r=sqrt(a*a+b*b-c); Cercle(a,b,r,0); Cercle(a,b,r/100.0,0); } void Circle_Euler() { double ax,ay,bx,by,cx,cy; double a1x,a1y,b1x,b1y,c1x,c1y; double x0,y0,x1,y1,x2,y2; //define 3 points A, B, C in plane (Ox,Oy) ax=0.3333; ay=1.6666; bx=0.0; by=0.0; cx=1.5; cy=0.0; Initwindow(10,-0.5,2.0,-0.5,2.0); /*TextXY(ax-0.05,ay+0.1,"A"); TextXY(bx-0.05,by-0.05,"B"); TextXY(cx+0.025,cy-0.025,"C"); */ MoveXY(ax,ay); LineXY(bx,by); LineXY(cx,cy); LineXY(ax,ay); Draw_Circle3P(ax,ay,bx,by,cx,cy); //TextXY(ax+0.05,ay+0.3,"Circumscribed Circle"); x1=a; y1=b; //define 3 points of Euler's circle a1x=(ax+bx)/2.0; a1y=(ay+by)/2.0; b1x=(cx+bx)/2.0; b1y=(cy+by)/2.0; c1x=(ax+cx)/2.0; c1y=(ay+cy)/2.0; //draw the 3 bisectors of triangle ABC} MoveXY(ax,ay); LineXY(b1x,b1y); MoveXY(bx,by); LineXY(c1x,c1y); MoveXY(cx,cy); LineXY(a1x,a1y); //drax euler circle of triangle ABC Draw_Circle3P(a1x,a1y,b1x,b1y,c1x,c1y); //TextXY(0.3,0.55,"Euler's Circle"); x2=a; y2=b; Line2D(x1,y1,x2,y2,&a,&b); Draw_Line(ax,0.7*cx,a,b); //TextXY(ax+0.39,ay-0.3,"Euler's Line"); Legendes(10,"Euler's Circle of triangle ABC","X","Y",0.56*MaxX,0.18*MaxY,"Circumscribed Circle", 0.55*MaxX, 0.4*MaxX,"Euler's Line"); Legendes(10,"","","",0.33*MaxX,0.48*MaxY,"Euler's Circle", 0,0,""); Legendes(10,"","","",0.37*MaxX,0.2*MaxY,"A", 0.25*MaxX,0.74*MaxY,"B"); Legendes(10,"","","",0.39*MaxX,0.67*MaxY,"H", 0.77*MaxX,0.74*MaxY,"C"); Legendes(10,"","","",0.42*MaxX,0.58*MaxY,"O1", 0.5*MaxX,0.5*MaxY,"O"); Legendes(10,"","","",0.37*MaxX,0.74*MaxY,"HA", 0.49*MaxX,0.55*MaxY,"G"); Legendes(10,"","","",0.61*MaxX,0.5*MaxY,"HB", 0.31*MaxX,0.62*MaxY,"HC"); //Draw line C-Hc perpendicular to side AB Line2D(ax,ay,bx,by,&a,&b); System2D(a,-1,-b,(-1.0/a),-1.0,-(cy+cx/a),&x0,&y0); // Hc is in (x0,y0) MoveXY(cx,cy); LineXY(x0,y0); //Draw line B-Hb perpendicular to side AC Line2D(ax,ay,cx,cy,&a,&b); System2D(a,-1,-b,(-1.0/a),-1.0,-(by+bx/a),&x0,&y0); // Hb is in (x0,y0) MoveXY(bx,by); LineXY(x0,y0); /*Draw line A-Ha perpendicular to side BC (here a=0} Line2D(bx,by,cx,cy,&a,&b); System2D(a,-1,-b,(-1.0/a),-1.0,-(ay+ax/a),&x0,&y0); // Hb is in (x0,y0) MoveXY(ax,ay); LineXY(x0,y0); */ MoveXY(ax,ay); LineXY(ax,0.0); //special case a=0 } //end of file gceuler.cpp