void CMyDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CDC *pDC;
pDC = this->GetDC();
int iList[100];
iList[0]=1; //费氏数列初始的两个元素
iList[1]=1;
int i;
int ix; //横坐标的整数点
int iy; //纵坐标的整数点
double dR=200; //半径
int iStart=300;
int iNum=9; //画几边形;10个圆就是,10-1边形
double dx,dy;
double dPi = 3.1415926535; //π,2π是一个圆周
double dPercision = 0.01; //精度0.01弧度 数值小,越像多边形
double da=0; //角度
dx = cos(da)*dR; //取得XY坐标,cos和sin呼唤,可以改变旋转方向,目前是顺时针
dy = sin(da)*dR;
ix = int(dx); //取整
iy = int(dy);
pDC->MoveTo(iStart+ix, iStart+iy);
for(da=0; da<=2*dPi; da+=dPercision) //画圆
{
dx = cos(da)*dR;
dy = sin(da)*dR;
ix = int(dx);
iy = int(dy);
pDC->LineTo(iStart+ix, iStart+iy);
}
i=0;
dPercision = 2*dPi/9.00001; //画内接九边形
for(da=0; da<=2*dPi; da+=dPercision)
{
dx = cos(da)*dR;
dy = sin(da)*dR;
ix = int(dx);
iy = int(dy);
iList[i++]=ix;
iList[i++]=iy;
pDC->LineTo(iStart+ix, iStart+iy);
pDC->LineTo(iStart, iStart);
pDC->LineTo(iStart+ix, iStart+iy);
}
i=0;
dPercision = 2*dPi/9.00001; //画外接九边形
dR=dR/sin(dPi-dPercision/2-dPi/2);//(半径变化)
for(da=0; da<=2*dPi; da+=dPercision)
{
dx = cos(da)*dR;
dy = sin(da)*dR;
ix = int(dx);
iy = int(dy);
iList[i++]=ix;
iList[i++]=iy;
pDC->LineTo(iStart+ix, iStart+iy);
pDC->LineTo(iStart, iStart);
pDC->LineTo(iStart+ix, iStart+iy);
}
pDC->SetTextColor(RGB(255, 0, 0));
i=0;
dPercision = 2*dPi/9.00001; //画外接九边形
//dR=dR/sin(dPi-dPercision/2-dPi/2);
for(da=dPercision/2; da<=2*dPi+dPercision/2; da+=dPercision)//转动半顶角个角
{
dx = cos(da)*dR;
dy = sin(da)*dR;
ix = int(dx);
iy = int(dy);
iList[i++]=ix;
iList[i++]=iy;
pDC->LineTo(iStart+ix, iStart+iy);
pDC->LineTo(iStart, iStart);
pDC->LineTo(iStart+ix, iStart+iy);
}