樹心幽徑

« 三角形的內切圓 | Main | 三角形的垂心 »

三角形的旁切圓
2017/12/04,13:05

alt

/*
   算出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);
   printf("P=(%.2f,%.2f)\n",*px,*py);
}
/*
   算出過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;
}

/*
   繪出三角形ABC的角C對的旁切圓
   三角形ABC A(xa,ya), B(xb,yb), C(xc,yc)
   Q為角A的外角平分線在CB邊的交點,
   (xq,yq)=(xb,yb)+c*(xb-xc,yb-yc)/(b-c)
   R為角B的外角平分線在CA邊的交點,
   (xr,yr)=(xa,ya)+c*(xa-xc,ya-yc)/(a-c)
   Ic為AQ和BR的交點,角C所對的旁心
   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)
   Ic在CB上的垂足Hcb,即切點
   CB的直線參數式為(xc,yc)+k(xb-xc,yb-yc)
   IcHcb的直線參數式為(xic,yic)+t(yb-yc,xc-xb)
   當k=((xc-xb)*(xc-xic)-(yb-yc)*(yc-yic))/((yb-yc)*(yb-yc)+(xc-xb)*(xc-xb))
     xhcb=xc+k*(xb-xc)
     yhcb=yc+k*(yb-yc)
   Ic在CA上的垂足Hca,即切點
   CA的直線參數式為(xc,yc)+k(xa-xc,ya-yc)
   IcHca的直線參數式為(xic,yic)+t(ya-yc,xc-xa)
   當k=((xc-xa)*(xc-xic)-(ya-yc)*(yc-yic))/((ya-yc)*(ya-yc)+(xc-xa)*(xc-xa))
     xhca=xc+k*(xa-xc)
     yhca=yc+k*(ya-yc)
*/
void SideCircle(double xa,double ya,double xb,double yb,double xc,double yc,Image *pim,char *cst){
pim->strokeColor(cst);
double c=pow(pow(xa-xb,2)+pow(ya-yb,2),0.5);
double b=pow(pow(xa-xc,2)+pow(ya-yc,2),0.5);
double a=pow(pow(xb-xc,2)+pow(yb-yc,2),0.5);
double xq=xb+c*(xb-xc)/(b-c);
double yq=yb+c*(yb-yc)/(b-c);
pim->draw(DrawableText(xq, yq, "Q"));
pim->draw( DrawableLine(xb,yb,xq,yq));
pim->draw( DrawableLine(xa,ya,xq,yq));
double xr=xa+c*(xa-xc)/(a-c);
double yr=ya+c*(ya-yc)/(a-c);
pim->draw(DrawableText(xr, yr, "R"));
pim->draw( DrawableLine(xa,ya,xr,yr));
pim->draw( DrawableLine(xb,yb,xr,yr));

double xic,yic,xhc,yhc; 
TSIP(xa,ya,xq,yq,xb,yb,xr,yr,&xic,&yic);
pim->draw(DrawableText(xic, yic, "Ic"));
IcABHc(xa,ya,xb,yb,xic,yic,&xhc,&yhc);
pim->draw(DrawableText(xhc, yhc, "H"));
pim->draw(DrawableCircle(xic,yic,xhc,yhc));

IcABHc(xa,ya,xc,yc,xic,yic,&xhc,&yhc);
pim->draw(DrawableText(xhc, yhc, "H"));
pim->draw(DrawableCircle(xic,yic,xhc,yhc));
pim->draw(DrawableLine(xa,ya,xhc,yhc));

IcABHc(xc,yc,xb,yb,xic,yic,&xhc,&yhc);
pim->draw(DrawableText(xhc, yhc, "H"));
pim->draw(DrawableCircle(xic,yic,xhc,yhc));
pim->draw(DrawableLine(xb,yb,xhc,yhc));

pim->draw(DrawableLine(xa,ya,xic,yic));
pim->draw(DrawableLine(xb,yb,xic,yic));
pim->draw(DrawableLine(xc,yc,xic,yic));

}

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType