樹心幽徑

出水山與草嶺的路
2017/12/14,16:29

typedef struct Point3D
{
    double x,y,z;
} P3D;
typedef struct Point2D
{
    double x,y;
} P2D;

 

//傳回Q在視平面的投影點座標P在視平面座標系的座標(vx,vy)
//視平面的中心點為C,法向量為N(cos(rad),sin(rad),0),原點O,y軸單位向量e2(0,0,-1),x軸單位向量e1為e2 X (-N) =(-sin(rad),cos(rad),0)
//ux為視平面x軸方向二相鄰點的距離,rx為C到y軸的水平點數
//uy為視平面y軸方向二相鄰點的距離,ry為C到x軸的垂直點數
//    O+rx*ux*e1+ry*uy*e2=C
// P=t*N+Q   t為P和Q的距
void QinView(P3D Q,P3D C,int rx,int ry,double ux,double uy,P3D N,double rad,P2D *v,double dist)
{
double t=(C.x-Q.x)*N.x+(C.y-Q.y)*N.y+(C.z-Q.z)*N.z;
P3D P;
P2D vP;
P.x=Q.x+t*N.x; P.y=Q.y+t*N.y; P.z=Q.z+t*N.z;
vP.x=rx+(t*sin(rad)+Q.y-C.y)/(ux*cos(rad));
vP.y=ry-(Q.z-C.z)/uy;
v->x=vP.x; v->y=vP.y;
dist=t;
}

 

alt

 

alt

 

alt

alt

三角形外接圓的三尖內擺線
2017/12/08,15:07

alt

alt

alt

/*
畫出三角外接圓的三尖內擺線 */

void TriCuspedHypocycloid(double xa,double ya,double xb,double yb,double xc,double yc,Image *pim,char *cst){
double xm,ym,k,t;
//外接圓
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));
double a=pow(pow(xm-xa,2)+pow(ym-ya,2),0.5)/3;
for (t=0;t<360;t+=3){
    double rad=(t/180)*M_PI;
    double xt=2*a*cos(rad)+a*cos(2*rad)+xm;
    double yt=2*a*sin(rad)-a*sin(2*rad)+ym;
    double xc=2*a*cos(rad)+xm;
    double yc=2*a*sin(rad)+ym;
    pim->draw(DrawableText(xt, yt, "t"));
    pim->draw(DrawableText(xc, yc, "c"));
    pim->draw(DrawableLine(xt,yt,xc,yc));
//    pim->draw(DrawableCircle(xc,yc,xt,yt));
    }

}

三角形的九點圓
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);
}

 

三角形的垂心
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");
}

 

 

三角形的旁切圓
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