1 / 5

# 畫線演算法 93610020 葉書豪 資工四 - PowerPoint PPT Presentation

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' 畫線演算法 93610020 葉書豪 資工四' - naeva

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### 畫線演算法93610020 葉書豪 資工四

Naivealgoritm
• A naïve line-drawing algorithm

dx = x2 - x1//x軸的間隔

dy = y2 - y1//y軸的間隔

for x from x1 to x2 {

y = y1 + (dy) * (x - x1)/(dx)

plot(x, y)

}//從起始點根據斜率公式一點一點畫到終點

(dy) )/(dx)即為協率

DDA algorithm
• 根據x軸和y軸的增量來畫出一條線

x_incremennt = float(dx) / float(steps);

y_incremennt = float(dy) / float(steps);

steps = fabs(dx);

Bresenhamalgorithm
• Bresenham演算法對斜率介於0至1之間的直線繪製為(假設直線兩端點為(x,y)和(x,y), xx, yy)：
• 輸入直線兩端點(x,y)及(x,y)。
• i=1;
• Δx=x-x; Δy=y-y; P1=2Δy-Δx; (x1,y1)=(x,y);
• Const1=2(Δx-Δy); Const2=-2Δy;
• while (i≠Δx) {
• if (Pi0) {
• (xi+1,yi+1)=(xi+1,yi+1);
• Pi+1=Pi+Const1; }
• else {
• (xi+1,yi+1)=(xi+1,yi);
• Pi+1=Pi+Const2; }
• i++;
• }
• 在此處2(Δx-Δy)和2Δy僅計算一次，其餘運算皆為整數的加減運算。
• 目前我們只討論斜率介於0和1之間的直線繪製，當直線斜率介於1至無窮大時，我們可經由增加yi之值(yi+1=yi+1)來求xi；

• 基本上畫出來的 速度方面來上 都很快速
• 相差不遠 所以速度沒什麼影響
• 主要是線段的趨近方面
• Bresenham演算法會比較平順
• Naïve會比較一段一段的