樹心幽徑

« working with inverse cycle 1 | Main | 三角形的內切圓 »

三角形的外接圓
2017/11/27,15:29

alt

/*
   繪出三角形ABC的外接圓
   三角形ABC A(xa,ya), B(xb,yb), C(xc,yc)
   Ma是BC的垂直平分線  ((xb+xc)/2,(yb+yc)/2) +t(yc-yb,xb-xc)
   Mb是AC的垂直平分線  ((xa+xc)/2,(ya+yc)/2) +k(ya-yc,xc-xa)
   Ma,Mb 交點即外心M(xm,ym) 此時k=(yc-yb)(ya-yb)-(xb-xc)(xa-xb)/2((xb-xc)(ya-yc)-(yc-yb)(xc-xa))
   xm=(xa+xc)/2+k(ya-yc)
   ym=(ya+yc)/2+k(xc-xa)
*/
void OuterCircle(double xa,double ya,double xb,double yb,double xc,double yc,Image *pim,char *cst){
double k=0.5*((yc-yb)*(ya-yb)-(xb-xc)*(xa-xb))/((xb-xc)*(ya-yc)-(yc-yb)*(xc-xa));
double xm=0.5*(xa+xc)+k*(ya-yc);
double ym=0.5*(ya+yc)+k*(xc-xa);
pim->strokeColor(cst);
pim->draw(DrawableCircle(xm,ym,xa,ya));
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"));
pim->draw(DrawableText(xm, ym, "O"));
pim->draw( DrawableLine(xm,ym,xa,ya));
pim->draw( DrawableLine(xm,ym,xb,yb));
pim->draw( DrawableLine(xm,ym,xc,yc));
}

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType