樹心幽徑

« 三角形的旁切圓 | Main | 三角形的九點圓 »

三角形的垂心
2017/12/04,21:03

三角形ABC的垂心是三邊垂足三角形DEF的內心。  三角形ABC的三頂點為三邊垂足三角形DEF的旁心。

alt

 

void InnerCircle(double xa,double ya,double xb,double yb,double xc,double yc,Image *pim,char *cst);

/*
   算出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);
}
/*
   算出過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 HCircle(double xa,double ya,double xb,double yb,double xc,double yc,Image *pim,char *cst){
pim->strokeColor(cst);
double xd,yd,xe,ye,xf,yf;
IcABHc(xa,ya,xb,yb,xc,yc,&xf,&yf);
pim->draw(DrawableText(xf, yf, "Fh"));
pim->draw(DrawableLine(xc,yc,xf,yf));
IcABHc(xb,yb,xc,yc,xa,ya,&xd,&yd);
pim->draw(DrawableText(xd, yd, "Dh"));
pim->draw(DrawableLine(xa,ya,xd,yd));
IcABHc(xc,yc,xa,ya,xb,yb,&xe,&ye);
pim->draw(DrawableText(xe, ye, "De"));
pim->draw(DrawableLine(xb,yb,xe,ye));
InnerCircle(xd,yd,xe,ye,xf,yf,pim,cst);
pim->strokeColor("blue");
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"));
}

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));

}

/*
   繪出三角形ABC的內接圓
   三角形ABC A(xa,ya), B(xb,yb), C(xc,yc)
   D為角A的角平分線在BC邊的交點,
   (xd,yd)=(xb,yb)+c*(xc-xb,yc-yb)/(b+c)   D=B+c*Vecter(BC)/(b+c)
   E為角B的角平分線在AC邊的交點,
   AD的直線參數式為(xa,ya)+t(xd-xa,yd-ya)
   BE的直線參數式為(xb,yb)+k(xe-xb,ye-yb)
   AD及BE的交點I,即為三角形的內心
   k=((xd-xa)*(yb-ya)-(xb-xa)*(yd-ya))/((ya-yd)*(xe-xb)-(ye-yb)*(xd-xa))
   xi=xb+k*(xe-xb)
   yi=yb+k*(ye-yb)
   s=(a+b+c)/2
   area=pow(s*(s-a)*(s-b)*(s-c),0.5);
   r=area/s;
   I在BC上的垂足J,即切點
   IJ的直線參數式為(xi,yi)+t(yc-yb,xb-xc)
   BC的直線參數式為(xb,yb)+k(xc-xb,yc-yb)
   當k=((xb-xc)*(xb-xi)-(yc-yb)*(yb-yi))/((yc-yb)*(yc-yb)+(xb-xc)*(xb-xc))
     xj=xb+k*(xc-xb)
     yj=yb+k*(yc-yb)
   I在AC上的垂足K,即切點
   IK的直線參數式為(xi,yi)+t(yc-ya,xa-xc)
   AC的直線參數式為(xa,ya)+k(xc-xa,yc-ya)
   當k=((xa-xc)*(xa-xi)-(yc-ya)*(ya-yi))/((yc-ya)*(yc-ya)+(xa-xc)*(xa-xc))
     xk=xa+k*(xc-xa)
     yk=ya+k*(yc-ya)
   I在AB上的垂足L,即切點
   IL的直線參數式為(xi,yi)+t(yb-ya,xa-xb)
   AB的直線參數式為(xa,ya)+k(xb-xa,yb-ya)
   當k=((xa-xb)*(xa-xi)-(yb-ya)*(ya-yi))/((yb-ya)*(yb-ya)+(xa-xb)*(xa-xb))
     xl=xa+k*(xb-xa)
     yl=ya+k*(yb-ya)
*/
void InnerCircle(double xa,double ya,double xb,double yb,double xc,double yc,Image *pim,char *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 xd=xb+c*(xc-xb)/(b+c);
double yd=yb+c*(yc-yb)/(b+c);
double xe=xc+a*(xa-xc)/(a+c);
double ye=yc+a*(ya-yc)/(a+c);
double xf=xa+b*(xb-xa)/(a+b);
double yf=ya+b*(yb-ya)/(a+b);

double s=(a+b+c)/2;
double area=pow(s*(s-a)*(s-b)*(s-c),0.5);
double r=area/s;
printf("s=%.2f area=%.2f r=area/s=%.2f \n",s,area,r);

pim->strokeColor(cst);
pim->draw( DrawableLine(xa,ya,xd,yd));
pim->draw(DrawableText(xd, yd, "D"));
pim->draw( DrawableLine(xb,yb,xe,ye));
pim->draw(DrawableText(xe, ye, "E"));
pim->draw( DrawableLine(xc,yc,xf,yf));
pim->draw(DrawableText(xf, yf, "F"));
double  k=((xd-xa)*(yb-ya)-(xb-xa)*(yd-ya))/((yd-ya)*(xe-xb)-(ye-yb)*(xd-xa));
double  xi=xb+k*(xe-xb);
double  yi=yb+k*(ye-yb);
pim->draw(DrawableText(xi, yi, "I"));
pim->draw(DrawableCircle(xi,yi,xi+r,yi));

k=((xb-xc)*(xb-xi)-(yc-yb)*(yb-yi))/((yc-yb)*(yc-yb)+(xb-xc)*(xb-xc));
double xj=xb+k*(xc-xb);
double yj=yb+k*(yc-yb);
pim->draw(DrawableText(xj, yj, "J"));
pim->draw( DrawableLine(xi,yi,xj,yj));

k=((xa-xc)*(xa-xi)-(yc-ya)*(ya-yi))/((yc-ya)*(yc-ya)+(xa-xc)*(xa-xc));
double  xk=xa+k*(xc-xa);
double  yk=ya+k*(yc-ya);
pim->draw(DrawableText(xk, yk, "K"));
pim->draw( DrawableLine(xi,yi,xk,yk));

k=((xa-xb)*(xa-xi)-(yb-ya)*(ya-yi))/((yb-ya)*(yb-ya)+(xa-xb)*(xa-xb));
double xl=xa+k*(xb-xa);
double yl=ya+k*(yb-ya);
pim->draw(DrawableText(xl, yl, "L"));
pim->draw( DrawableLine(xi,yi,xl,yl));
SideCircle(xa,ya,xb,yb,xc,yc,pim,"cyan");
SideCircle(xb,yb,xc,yc,xa,ya,pim,"pink");
SideCircle(xc,yc,xa,ya,xb,yb,pim,"green");
pim->strokeColor("red");
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"));
}
int main()
{
int w=1024*2;
int h=768*2;
Image im( Geometry(w, h), Color("black"));
char cst[20];
im.font("/usr/share/fonts/truetype/arphic/uming.ttc");
im.fontPointsize(30);
im.strokeWidth(2);

im.fillColor("transparent"); // Fill color
im.draw(DrawableFillOpacity(50));
im.strokeWidth(3);
double px1,py1,ipx,ipy,ox,oy,r,tx,ty;
ox=w/2; oy=h/2; r=h/12;
im.strokeColor("cyan");
double px;
double py;
struct point{
   double x,y;
};
point p[]={ {ox,oy+2*r},{ox+2*r,oy-1.7*r},{ox-r,oy-2*r}};
strcpy(cst,"pink");
HCircle(p[0].x,p[0].y,p[1].x,p[1].y,p[2].x,p[2].y,&im,cst);
im.write("hCircle.jpg");
}

 

 

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType