# 正多边形画法，圆的内接，外切正多边形画法。

1082人阅读 评论(0)

void CMyDlg::OnButton2()
{
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);
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：3092次
• 积分：132
• 等级：
• 排名：千里之外
• 原创：9篇
• 转载：2篇
• 译文：0篇
• 评论：0条
阅读排行
评论排行
最新评论