全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1943
推到 Plurk!
推到 Facebook!

多邊形塗網3

 
jackkcg
站務副站長


發表:891
回覆:1050
積分:848
註冊:2002-03-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-09-11 02:18:47 IP:61.70.xxx.xxx 未訂閱
http://bbs.nsysu.edu.tw/txtVersion/treasure/program/M.855729774.F/M.839161867.C.html    發信人:is80001@cis.nctu.edu.tw (William Yeh) 日期:12 Jun 1995 14:42:53 GMT 標題:多邊形塗網3 信群:tw.bbs.comp.language    看板: 代號:<3rhjpd$el0@news.cis.nctu.edu.tw> 組織:Dept. of Computer & Information Science, NCTU, Taiwan [ Article crossposted from tw.90net.c ] [ Author was Chi'u I-Nan ] [ Posted on 06 Jun 95 17:41:08 ] static void near pascal PackLineData(void) { /* ------------------------------------------------------------- 作用:將多邊形線做成向量形式 備註:向量形式之多邊形線(x,y,dx,dy),其中dy>0或(dy=0且dx>=0) ------------------------------------------------------------- */ int i, dx, dy; if (PackLineFlag) return; PackLineFlag = true; /* 先將首尾相接 */ ClosePoly(); /* 開始做成向量形式 */ for (i=0; i InBuffer[j 1]) { miny = InBuffer[j 1]; minindex = j; } /* 開始對調 */ if (minindex != i) for (j=0; j<4; j ) { miny = InBuffer[i j]; InBuffer[i j] = InBuffer[minindex j]; InBuffer[minindex j] = miny; } } /* 重定掃描線計算工作區域,以重頭計算掃描線 */ LeftPtr = 0; RightPtr = -1; } int* GetScanLine(int *LineCount) { /* ------------------------------------------------------------- 作用:取得多邊形封閉區域掃描線 傳回:LineCount = 掃描線數目,若已無掃描線,則傳回0 函數傳回存放掃描線的緩衝區位址 備註:1.當呼叫本函數後,傳回的掃描線可能不完全,此時必須重複呼 叫本函數取得後面的掃描線,直到傳回掃描線數為0時 2.取得之掃描線格式為y,x1,x2,其中x1<=x2. 每條掃描線各佔 6 byte. ------------------------------------------------------------- */ int HLinePtr; /* 輸出掃描線存放位置 */ int CrossPtr; /* 水平線交點存放位置 */ int i, j, temp, change, dy, crossx, crossx2; /* 做成向量形式並排序 */ PackLineData(); SortLineData(); /* 開始計算掃描線,直到所有多邊形線都結束,或輸出緩衝區已滿 */ HLinePtr = 0; while (LeftPtr < PointPtr) { if (LeftPtr > RightPtr) { /* 工作區域內已無多邊形線,直接跳到下一條線的起點開始計算 */ AreaY = InBuffer[LeftPtr 1]; /* 將所有以該水平線為起點的多邊形線加入工作區域內 */ RightPtr = LeftPtr; while ((RightPtr < PointPtr-4) && (AreaY == InBuffer[RightPtr 5])) RightPtr = 4; } /* 計算本水平線與所有多邊形線的交點 */ CrossPtr = 0; for (i=LeftPtr; i<=RightPtr; i =4) if (InBuffer[i 3] == 0) { /* 水平線 -> 直接將該線整個視為掃描線 */ if (HLinePtr < MaxScanLine*3-3) { OutBuffer[HLinePtr ] = AreaY; OutBuffer[HLinePtr ] = InBuffer[i]; OutBuffer[HLinePtr ] = InBuffer[i] InBuffer[i 2]; } } else { /* 非水平線 -> 算出交點 */ dy = AreaY - InBuffer[i 1]; if (dy == 0) { /* 線的起點 -> 必須特殊處理: 如果此該起點為另一線終點,或是連到水平線, 則此交點不計入 */ crossx = InBuffer[i]; for (j=LeftPtr; j<=RightPtr; j ) { if (InBuffer[j 3] == 0) /* 水平線 -> 多測起點 */ if ((InBuffer[j] == crossx) && (InBuffer[j 1] == AreaY)) break; /* 測試終點 */ if ((InBuffer[j] InBuffer[j 2] == crossx) && (InBuffer[j 1] InBuffer[j 3] == AreaY)) break; } if (j > RightPtr) /* 不符合上述情況時才能將交點計入 */ if (CrossPtr < MaxPoint) PointBuffer[CrossPtr ] = crossx; } else if (CrossPtr < MaxPoint) { /* 非線的起點 -> 算出交點放入 交點crossx = (AreaY-y)*dx/dy x */ crossx = (int) ((long)dy*InBuffer[i 2]/InBuffer[i 3]) InBuffer[i]; PointBuffer[CrossPtr ] = crossx; /* 若太偏向水平線時,必須考慮斷線問題,將斷線部份 加入掃描線 */ if (HLinePtr < MaxScanLine*3-3) { crossx2 = crossx - InBuffer[i 2]/InBuffer[i 3]; if (crossx2 < crossx) { OutBuffer[HLinePtr ] = AreaY; OutBuffer[HLinePtr ] = crossx2; OutBuffer[HLinePtr ] = crossx; } else if (crossx2 > crossx) { OutBuffer[HLinePtr ] = AreaY; OutBuffer[HLinePtr ] = crossx; OutBuffer[HLinePtr ] = crossx2; } } } } * 青衫詩客 -- 小邱 * ... 想飛,是寓詩於纏綿。想飛過萬層山巔,只願魂繞妳夢也牽。 - 青衫 -- |Fidonet: Chi'u I-Nan 90:2010/622 |Internet: Chi'u.I-Nan@f622.n2010.z90.fidonet.org | | Standard disclaimer: The views of this user are strictly his own. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- William Yeh (Chinese name: 葉秉哲) | E-mail address: | is80001@cis.nctu.edu.tw Dept. of Computer & Info. Science | u8023001@cc.nctu.edu.tw National Chiao-Tung University, | william.bbs@bbs.cis.nctu.edu.tw Hsinchu, Taiwan, R.O.C. | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ********************************************************************* -------------------------------------------------------------------------------- ←回列表 ↑上一篇 ↓下一篇 發信人:is80001@cis.nctu.edu.tw (William Yeh) 日期:12 Jun 1995 14:42:59 GMT 標題:多邊形塗網4 信群:tw.bbs.comp.language 看板: 代號:<3rhjpj$el0@news.cis.nctu.edu.tw> 組織:Dept. of Computer & Information Science, NCTU, Taiwan [ Article crossposted from tw.90net.c ] [ Author was Chi'u I-Nan ] [ Posted on 06 Jun 95 17:42:10 ] /* 將算出的交點由小至大排序好 -> 使用Bubble Sort */ change = true; while (change) { change = false; for (i=1; i PointBuffer[i]) { change = true; temp = PointBuffer[i]; PointBuffer[i] = PointBuffer[i-1]; PointBuffer[i-1] = temp; } } /* 開始每兩點結算出一條掃描線 */ for (i=0; i MaxScanLine*3-MaxPoint/2) break; } *LineCount = HLinePtr/3; return(OutBuffer); } * 青衫詩客 -- 小邱 * ... 春紗薄透,花絮混輕塵,讓我們舞若鴛鴦,共守小千神秘。 - 青衫 -- |Fidonet: Chi'u I-Nan 90:2010/622 |Internet: Chi'u.I-Nan@f622.n2010.z90.fidonet.org | | Standard disclaimer: The views of this user are strictly his own. 發表人 - jackkcg 於 2002/09/11 02:20:06
------
**********************************************************
哈哈&兵燹
最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好

Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知
K.表Knowlege 知識,就是本站的標語:Open our mind
系統時間:2024-05-02 11:02:15
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!