93610020
Download
Skip this Video
Download Presentation
畫線演算法 93610020 葉書豪 資工四

Loading in 2 Seconds...

play fullscreen
1 / 5

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


  • 73 Views
  • Uploaded on

畫線演算法 93610020 葉書豪 資工四. Naive algoritm. 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 軸的增量來畫出一條線

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

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


An Image/Link below is provided (as is) to download presentation

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
naive algoritm
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
DDA algorithm
  • 根據x軸和y軸的增量來畫出一條線

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

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

假如x的間距大於 y的間距

steps = fabs(dx);

不是的話 steps = fabs(dy);

這個演算法不是一個點一個點畫上去的 而是利用各+0.5的長度直線來趨近一條斜線

bresenham algorithm
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;
slide5
效率比較
  • 基本上畫出來的 速度方面來上 都很快速
  • 相差不遠 所以速度沒什麼影響
  • 主要是線段的趨近方面
  • Bresenham演算法會比較平順
  • Naïve會比較一段一段的

而DDA演算法則比較粗一點 但是已經比較趨近線的平滑性了

ad