Computer Graphics Primitives Part II Midpoint Bresenhams line

Computer Graphics Primitives Part II: Midpoint, Bresenhams line and circle

Midpoint Line Algorithm Hitung konstanta Hitung Untuk setiap iterasi sebanyak ∆x If d >= 0 Else if d<0

Example Midpoint Alg Drawing a line from (0, 0) to (5. 2) i 1 2 3 4 xi 0 1 2 3 yi 0 0 1 1 d 1 -3 3 -1 5 4 2 5

void Midpoint. Line (int x 0, int y 0, int xend, int yend, int color) { int a, b, incre_d 1, incre_d 2, d, x, y; a=y 0 -yend, b=xend-x 0, d=2*a+b; incre_d 1=2*a, incre_d 2=2* (a+b); x=x 0, y=y 0; drawpixel(x, y, color); while (x<x 1) { if (d<0) {x++, y++, d+=incre_d 2; } else {x++, d+=incre_d 1; } drawpixel (x, y, color); } /* while */ } /* mid Point. Line */

Bresenham’s Line Algorithm An accurate, efficient raster line drawing algorithm developed by Bresenham, scan converts lines using only incremental integer calculations that can be adapted to display circles and other curves.

Bresenham’s Algorithm Hitung konstanta Hitung Untuk setiap iterasi sebanyak ∆x If d < 0 Else

Example Bresenham Drawing a line from (0, 0) to (5. 2) i 1 2 3 4 xi 0 1 2 3 yi 0 0 1 1 d -1 3 -3 1 5 4 2 -5

Bresenham’s Line Algorithm void Bresenham. Line (int x 0, int y 0, int xend, int yend, int color) { int dx, dy, incre_p 1, incre_p 2, p, x, y; dy=yend-y 0, dx=xend-x 0; incre_p 1=2*dy, incre_p 2=2* (dy-dx); x=x 0, y=y 0; p=2*dy-dx; drawpixel(x, y, color); while (x<x 1) { if (p<0) {x++, p+=incre_d 1; } else {x++, y++, p+=incre_d 2; } drawpixel (x, y, color); } /* while */ } /* Bresenham */

Midpoint Circle Algorithm Inisialisasi Hitung Untuk setiap iterasi sebanyak ∆x If d < 0 Else

Mid. Point. Circle(int r int color) { int x, y; float d; x=0; y=r; d=1 -r; circlepoints (x, y, color); //draw (x, y) and other symmetric points while(x<=y) { if(d<0) d+=2*x+3; else { d+=2*(x-y)+5; y--; } x++; circlepoints (x, y, color); } }
- Slides: 10