中​點​畫​圓​算​法,計算機圖形學?

計算機圖形學中點畫圓,中點畫線

工具/原料

MicroSoft Visual C++

中點畫圓

開啟MicroSoft Visual C++ ,

中​點​畫​圓​算​法,計算機圖形學

新建一個 C++ source file檔案,具體命令為“檔案”→“新建”,在彈出的對話方塊中選擇“檔案”選項卡,選擇 C++ source file,命名檔案

中​點​畫​圓​算​法,計算機圖形學

將以下程式碼複製到新建的檔案中,

#include

using namespace std;

#define MidpointLine(r)

void main()

{

int r;

cout<<"請輸入r"<

cin>>r;

int x,y,d;

x=0;

y=r;

d=1-r;

cout<<"x"<<" "<<"y"<<" "<<"d"<

cout<

while(x

{

if(d<0)

{

d+=2*x+3;

x++;

}

else

{

d+=2*(x-y)+5;

x++;y--;

}

cout<

} /*while*/

} /*MidpointLine*/

中​點​畫​圓​算​法,計算機圖形學

“組建”→“開始除錯”→“GO!”,在彈出的對話方塊中都單擊確定。

中​點​畫​圓​算​法,計算機圖形學

中​點​畫​圓​算​法,計算機圖形學

中​點​畫​圓​算​法,計算機圖形學

中​點​畫​圓​算​法,計算機圖形學

除錯完畢,輸入r的值,比如輸入r=125

中​點​畫​圓​算​法,計算機圖形學

中​點​畫​圓​算​法,計算機圖形學

中點畫線演算法

方法同上面的中點畫線一樣,程式碼如下

#include

using namespace std;

#define MidpointLine(x0,y0,x1,y1)

void main()

{

int x0,y0,x1,y1;

cout<<"請輸入x0,y0,x1,y1"<

cin>>x0;

cin>>y0;

cin>>x1;

cin>>y1;

int a,b,delta1,delta2,d,x,y;

a=y0-y1;

b=x1-x0;

d=2*a+b;

delta1=2*a;

delta2=2*(a+b);

x=x0;

y=y0;

cout<<"x"<<" "<<"y"<<" "<<"d"<

cout<

while(x

{

if(d<0)

{x++;y++;

d+=delta2;

}

else

{ x++;

d+=delta1;

}

cout<

} /*while*/

} /*MidpointLine*/

注意事項

確定電腦上已經安裝c++6.0

計算機, 圖形學, 中點, 畫線, 中​點​畫​圓​算​法,
相關問題答案