資源簡介
計算機圖形學中采用活性邊表算法,實現多邊形光柵化,本題目主要是在C語言和Win32控制臺應用程序的基礎上在屏幕上繪制多邊形。

代碼片段和文件信息
//?AET.cpp?:?定義控制臺應用程序的入口點。
//
#include?“stdafx.h“
#include?“conio.h“
#include?“windows.h“
void?InitCoordSys(?HWND?hwnd?HDC?hdc)?;
void?AET(HDC?hdc);
typedef?struct?ET??
{
double?x;
long?ymax;
double?vk;
struct?ET?*next;
}ET;
????
int?_tmain(int?argc?_TCHAR*?argv[])
{
//獲?取¨?控?制?臺??§窗???口¨2句?柄à¨2
HWND?hwnd?=?GetConsoleWindow();
//獲?取¨?控?制?臺??§窗???口¨2設|¨¨備à?句?柄à¨2
HDC?hdc?=?GetDC(hwnd);
//修T改?畫-刷?é顏?色|?
::Selectobject(?hdc?GetStockobject(?DC_BRUSH?));
::SetDCBrushColor(?hdc?RGB(02550));???????//改?成¨|想?要°a的ì?顏?色|?
//修T改?畫-筆à¨o顏?色|?
::Selectobject(?hdc?GetStockobject(?DC_PEN));
::SetDCPenColor(?hdc?RGB(?0255?0));
?????InitCoordSys(?hwnd?hdc)?;
?AET(hdc);
?getch();
?ReleaseDC(?hwnd?hdc?);
?return?0;
}
void?AET(HDC?hdc)
{
ET?*etEdge;
int?BucketL;//桶a??長?è
int?i?max=-100min=10000sides;
POINT?spt[7];
printf(“Please?enter?the?number?of?sides?of?the?polygon:\n“);
scanf(“%d“&sides);
printf(“Please?enter?the?coordinate:\n“);
for?(int?c=0;c {
scanf(“%d?%d“&spt[c].x&spt[c].y);
}
::Polygon(hdcsptsides);
//?求¨?出?最á?大?¨?的ì?y值|ì和¨a最á?小?的ì?y值|ì,ê?即??占?用??的ì?最á?大?¨?掃|?§描¨¨線?數oy
for?(i=0;?i {
if?(spt[i].y?>?max)?max?=?spt[i].y;
if?(spt[i].y? }
BucketL?=?max-min+1; //?最á?大?¨?掃|?§描¨¨線?數oy
etEdge?=?new?ET[BucketL]; //長?è度¨¨為aBucketL的ì?創???建?§邊à?表à¨a
for?(i=0;?i {
etEdge[i].next?=?NULL;
}
//?根¨′據Y所¨′給?邊à?求¨?出?邊à?表à¨a
for?(i=0;?i {
int?m?=?i+1;
if?(spt[i].y? {
ET?*q?=?new?ET();
q->x?=?spt[i].x;
q->ymax?=?spt[m].y;
q->vk?=?(double)(spt[m].x-spt[i].x)/(spt[m].y-spt[i].y); //?1/k的ì?值|ì
q->next?=?NULL;
ET*?p?=?&etEdge[spt[i].y-min];
while?(p->next?!=?NULL)?
p?=?p->next;
p->next?=?q;
}
else?if(spt[i].y?>?spt[m].y) //第ì¨2i個?點ì?的ì?坐á?標à¨o大?¨?于?¨2下?一°?個?點ì?的ì?坐á?標à¨o
{
ET?*q?=?new?ET();
q->x?=?spt[m].x;
q->ymax?=?spt[i].y;
q->vk?=?(double)(spt[i].x-spt[m].x)/(spt[i].y-spt[m].y); //?1/k的ì?值|ì
q->next?=?NULL;
ET*?p?=?&etEdge[spt[m].y-min];
while?(p->next?!=?NULL)?p?=?p->next;
p->next?=?q;
}
}
ET?*p;
int?flag=1;
//?將?第ì¨2一°?個?不?為a空?的ì?邊à?表à¨a中D的ì?邊à?與??AET表à¨a合?并?é
for?(i=0;?i {
if?(etEdge[i].next?!=?NULL)
{
p?=?etEdge[i].next;
etEdge[i].next?=?NULL;
break;
}
}
??????????????????
double?x?=?p->x; //橫¨¢向¨°掃|?§描¨¨一°?行D的ì?下?標à¨o
for(int?y=min?;y {
ET*?et?=?p;
double?x_max?=?et->x; //?一°?行D中D最á?右?¨°邊à?的ì?x值|ì
x?=?et->x; //?起e始o?值|ì,ê?一°?行D中D最á?左á¨?邊à?的ì?x值|ì
while(et!=NULL) //?求¨?一°?行D中D的ì?最á?后¨?一°?個?邊à?界?點ì?的ì?x坐á?標à¨o和¨a起e始o?點ì?的ì?x坐á?標à¨o
{
if(et->x?>?x_max)?x_max=et->x;
if?(et->x?x;
et?=?et->next;
}
flag=1;
while(x?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????5180??2012-11-19?21:31??AET\AET\AET.cpp
?????文件???????4358??2012-11-19?20:19??AET\AET\AET.vcxproj
?????文件???????1307??2012-11-19?20:19??AET\AET\AET.vcxproj.filters
?????文件????????143??2012-11-19?20:19??AET\AET\AET.vcxproj.user
?????文件???????1525??2012-11-19?20:19??AET\AET\ReadMe.txt
?????文件????????208??2012-11-19?20:19??AET\AET\stdafx.cpp
?????文件????????233??2012-11-19?20:19??AET\AET\stdafx.h
?????文件????????236??2012-11-19?20:19??AET\AET\targetver.h
?????文件????????881??2012-11-19?20:19??AET\AET.sln
????..A..H.??????9216??2012-11-19?21:32??AET\AET.suo
?????目錄??????????0??2012-11-19?21:45??AET\AET
?????目錄??????????0??2012-11-19?21:45??AET
-----------?---------??----------?-----??----
????????????????23287????????????????????12
- 上一篇:檢查抄襲作業程序
- 下一篇:c++職工信息管理系統課程設計報告
評論
共有 條評論