樹心幽徑

« 三角形的垂心 | Main | 三角形外接圓的三尖內擺線 »

三角形的九點圓
2017/12/05,22:15

alt

 

alt

alt

/*
   繪出三角形ABC的九點圓(三邊的中點DEF、三高的垂足GHI、頂點到垂心線段的中點JKL)
   九點圓和三角形的內切圓和旁切圓相切。
   三角形ABC A(xa,ya), B(xb,yb), C(xc,yc)
*/
void NinePCircle(double xa,double ya,double xb,double yb,double xc,double yc,Image *pim,char *cst){
pim->strokeColor("white");
pim->draw( DrawableLine(xc,yc,xa,ya));
pim->draw( DrawableLine(xb,yb,xa,ya));
pim->draw( DrawableLine(xb,yb,xc,yc));
pim->draw(DrawableText(xa, ya, "A"));
pim->draw(DrawableText(xb, yb, "B"));
pim->draw(DrawableText(xc, yc, "C"));
double xd=(xc+xb)/2;
double yd=(yc+yb)/2;
double xe=(xa+xc)/2;
double ye=(ya+yc)/2;
double xf=(xa+xb)/2;
double yf=(ya+yb)/2;
pim->draw(DrawableText(xd, yd, "D"));
pim->draw(DrawableText(xe, ye, "E"));
pim->draw(DrawableText(xf, yf, "F"));

pim->strokeColor("blue");
double xg,yg,xh,yh,xi,yi;
IcABHc(xa,ya,xb,yb,xc,yc,&xi,&yi);
pim->draw(DrawableText(xi, yi, "I"));
pim->draw(DrawableLine(xc,yc,xi,yi));
IcABHc(xb,yb,xc,yc,xa,ya,&xg,&yg);
pim->draw(DrawableText(xg, yg, "G"));
pim->draw(DrawableLine(xa,ya,xg,yg));
IcABHc(xc,yc,xa,ya,xb,yb,&xh,&yh);
pim->draw(DrawableText(xh, yh, "H"));
pim->draw(DrawableLine(xb,yb,xh,yh));
double xs,ys;
TSIP(xa,ya,xg,yg,xb,yb,xh,yh,&xs ,&ys);
pim->draw(DrawableText(xs, ys, "S"));

pim->strokeColor("red");
double k=0.5*((yf-ye)*(yd-ye)-(xe-xf)*(xd-xe))/((xe-xf)*(yd-yf)-(yf-ye)*(xf-xd));
double xm=0.5*(xd+xf)+k*(yd-yf);
double ym=0.5*(yd+yf)+k*(xf-xd);
pim->draw(DrawableCircle(xm,ym,xd,yd));

double xj=(xs+xa)/2;
double yj=(ys+ya)/2;
pim->draw(DrawableText(xj, yj, "J"));

double xk=(xs+xb)/2;
double yk=(ys+yb)/2;
pim->draw(DrawableText(xk, yk, "K"));

double xl=(xs+xc)/2;
double yl=(ys+yc)/2;
pim->draw(DrawableText(xl, yl, "L"));

pim->strokeColor("green");
pim->draw(DrawableLine(xf,yf,xk,yk));
pim->draw(DrawableLine(xe,ye,xl,yl));
pim->draw(DrawableLine(xf,yf,xe,ye));
pim->draw(DrawableLine(xk,yk,xl,yl));
pim->draw(DrawableLine(xk,yk,xe,ye));

pim->strokeColor("cyan");
pim->draw(DrawableLine(xd,yd,xf,yf));
pim->draw(DrawableLine(xj,yj,xl,yl));
pim->draw(DrawableLine(xd,yd,xl,yl));
pim->draw(DrawableLine(xj,yj,xf,yf));
pim->draw(DrawableLine(xj,yj,xd,yd));

pim->strokeColor(cst);
k=0.5*((yc-yb)*(ya-yb)-(xb-xc)*(xa-xb))/((xb-xc)*(ya-yc)-(yc-yb)*(xc-xa));
xm=0.5*(xa+xc)+k*(ya-yc);
ym=0.5*(ya+yc)+k*(xc-xa);
pim->draw(DrawableCircle(xm,ym,xa,ya));
}

/*
   算出過Ic和AB垂直的直線交點Hc
   Ic在AB上的垂足Hc
   AB的直線參數式為(xa,ya)+k(xb-xa,yb-ya)
   IcHc的直線參數式為(xic,yic)+t(yb-ya,xa-xb)
   當k=((xa-xb)*(xa-xic)-(yb-ya)*(ya-yic))/((yb-ya)*(yb-ya)+(xa-xb)*(xa-xb))
     xhc=xa+k*(xb-xa)
     yhc=ya+k*(yb-ya)
*/
void IcABHc(double xa,double ya,double xb,double yb,double xic,double yic,double *px,double *py){
   double k=((xa-xb)*(xa-xic)-(yb-ya)*(ya-yic))/((yb-ya)*(yb-ya)+(xa-xb)*(xa-xb));
   double  xhc=xa+k*(xb-xa);
   double  yhc=ya+k*(yb-ya);
   *px=xhc;
   *py=yhc;
}

 

/*
   算出AB和CD二線的交點
   AB的直線參數式為(xa,ya)+t(xb-xa,yb-ya)
   CD的直線參數式為(xc,yc)+k(xd-xc,yd-yc)
   交點P(xp,yp)的k如下
   k=((yb-ya)*(xc-xa)-(yc-ya)*(xb-xa))/((yd-yc)*(xb-xa)-(yb-ya)*(xd-xc))
   xp=xc+k*(xd-xc)
   yp=yc+k*(yd-yc)
*/
void TSIP(double xa,double ya,double xb,double yb,double xc,double yc,double xd,double yd,double *px,double *py){
   double k=((yb-ya)*(xc-xa)-(yc-ya)*(xb-xa))/((yd-yc)*(xb-xa)-(yb-ya)*(xd-xc));
   *px=xc+k*(xd-xc);
   *py=yc+k*(yd-yc);
}

 

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType