//三角形void CHanzitempDlg::DrawFloor(CDC *pDC,int x1, int y1,int x2,int y2,int x3,int y3,int n){ //pDC是画图的设备上下文的指针 //x1,y1,x2,y2,x3,y3是起始的三角形的三点坐标 //其中参数n是递归的层数 int x11,x22,x33,y11,y22,y33; //以下是根据空间几何计算出来的坐标 x11=(x2+x3)/2; y11=(y2+y3)/2; x22=(x1+x3)/2; y22=(y1+y3)/2; x33=(x1+x2)/2; y33=(y1+y2)/2; pDC->MoveTo(x11,y11); pDC->LineTo(x22,y22); pDC->MoveTo(x11,y11); pDC->LineTo(x33,y33); pDC->MoveTo(x22,y22); pDC->LineTo(x33,y33); //递归最后一层,递归的出口 if(n==1) { pDC->MoveTo(x11,y11); pDC->LineTo(x22,y22); pDC->LineTo(x33,y33); pDC->LineTo(x11,y11); } else { //递归画图 DrawFloor(pDC,x1,y1,x33,y33,x22,y22,n-1); DrawFloor(pDC,x33,y33,x2,y2,x11,y11,n-1); DrawFloor(pDC,x22,y22,x11,y11,x3,y3,n-1); }}