计算机图形学 圆周算法的实现

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

《计算机图形学实验报告》样例

实验名称:圆周画法的实现

1.实验内容

1.画出圆心坐标为(75,90)和半径为50的红色圆周

2.画出圆心坐标为(‐40,‐80)和半径为60的蓝色圆周

2.程序的基本思路和功能

先用MFC构建界面外观,然后在相应位置分别用Bresenham和DDA编辑画圆的程序然后编译运行。

3.关键代码及说明

void Circle::circleMinPoint(CDC* pDC)

{

xCenter = (float)(400 + x);

yCenter = (float)(300 - y);

//绘制圆心

drawCenter(pDC);

//r = 50;

//设置颜色

color = RGB(red,green,blue);

float m_x = 0;

float m_y = r;

float d = 1.25 - r;

circlePoint(m_x,m_y,pDC);

while(m_x <= m_y){

if(d<=0){

d = d + 2 * m_x + 3;

}else{

d = d + 2 * ( m_x - m_y ) + 5;

m_y = m_y - 1;

}

m_x = m_x + 1;

circlePoint(m_x,m_y,pDC);

}

}

void Circle::circleBresenham(CDC* pDC) {

//确认圆心坐标

xCenter = (float)(400 + x);

yCenter = (float)(300 - y);

//绘制圆心

drawCenter(pDC);

//r = 50;

//设置颜色

color = RGB(red,green,blue);

float m_x = 0;

float m_y = r;

float p = 3 - 2 * r;

circlePoint(m_x,m_y,pDC);

do{

if( p>=0 ){

p = p + 4 * ( m_x - m_y ) + 10;

m_y = m_y - 1;

}else{

p = p + 4 * m_x + 6;

}

m_x = m_x + 1;

circlePoint(m_x,m_y,pDC);

}while(m_x <= m_y);

}

void Circle::circlePoint(float m_x, float m_y, CDC* pDC) {

//设置颜色

//COLORREF color = RGB(red,green,blue);

float c_x;

float c_y;

//1:一上

c_x = xCenter + m_x;

c_y = yCenter - m_y;

pDC->SetPixel((int)c_x,(int)c_y,color);

//2:一下

c_x = xCenter + m_y;

c_y = yCenter - m_x;

pDC->SetPixel((int)c_x,(int)c_y,color); //3:三下

c_x = xCenter - m_x;

c_y = yCenter + m_y;

pDC->SetPixel((int)c_x,(int)c_y,color); //4:三上

c_x = xCenter - m_y;

c_y = yCenter + m_x;

pDC->SetPixel((int)c_x,(int)c_y,color); //5:四下

c_x = xCenter + m_x;

c_y = yCenter + m_y;

pDC->SetPixel((int)c_x,(int)c_y,color); //6:四上

c_x = xCenter + m_y;

c_y = yCenter + m_x;

pDC->SetPixel((int)c_x,(int)c_y,color); //7:二上

c_x = xCenter - m_x;

c_y = yCenter - m_y;

pDC->SetPixel((int)c_x,(int)c_y,color); //8:二下

c_x = xCenter - m_y;

c_y = yCenter - m_x;

pDC->SetPixel((int)c_x,(int)c_y,color);

}

void Circle::drawCenter(CDC* pDC)

{

pDC->SetPixel((int)xCenter,(int)yCenter,color);

pDC->SetPixel((int)xCenter+1,(int)yCenter,color);

pDC->SetPixel((int)xCenter,(int)yCenter+1,color);

pDC->SetPixel((int)xCenter+1,(int)yCenter+1,color);

pDC->SetPixel((int)xCenter-1,(int)yCenter,color);

pDC->SetPixel((int)xCenter,(int)yCenter-1,color);

pDC->SetPixel((int)xCenter-1,(int)yCenter-1,color);

}

4.程序运行结果及分析

相关文档
最新文档