Name: Pranav G Dasgaonkar Roll No: 70 CLASS: 8 (CMPN-2) CG Experiment No: 02
The document describes a student's computer graphics experiment to implement Bresenham's line algorithm. It provides the student's name, class, and experiment number. It then explains Bresenham's line algorithm uses integer calculations to determine pixel coordinates as it moves across the x-axis. The procedure and C++ program are described to input endpoints, calculate constants, test the decision parameter at each x value, and plot pixels to draw the line.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
84 views4 pages
Name: Pranav G Dasgaonkar Roll No: 70 CLASS: 8 (CMPN-2) CG Experiment No: 02
The document describes a student's computer graphics experiment to implement Bresenham's line algorithm. It provides the student's name, class, and experiment number. It then explains Bresenham's line algorithm uses integer calculations to determine pixel coordinates as it moves across the x-axis. The procedure and C++ program are described to input endpoints, calculate constants, test the decision parameter at each x value, and plot pixels to draw the line.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4
NAME : PRANAV G DASGAONKAR
ROLL NO : 70 CLASS : 8 (CMPN-2) CG EXPERIMENT NO : 02
AIM: Implement Bresenham’s Line Algorithm.
THEORY: Bresenham Line Drawing Algorithm: The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage of this algorithm is that, it uses only integer calculations. Moving across the x axis in unit intervals and at each step choose between two different y coordinates. PROCEDURE: 1. Input the two line endpoints and store the left endpoint in(x0 , y0 ) 2. Load (x0 , y0 ) into the frame buffer; that is, plot the first point. 3. Calculate constants ∆x, ∆y, 2∆y and 2∆y - 2∆x, and obtain the starting value for the decision parameter as: P0=2∆y - ∆x 4. At each xk , the next point the line, starting at k=0, perform the following test: If pk < 0, the next point is (xk+1 ,yk ) and Pk+1=pk+2∆y Otherwise, the next point is (xk+1,yk+1 ) and pk+1=pk +2∆y - 2∆x 5. Repeat step 4 ∆x times 6. STOP PROGRAM: #include<stdio.h> #include<conio.h> #include <graphics.h> void main() { int x1,x2,y1,y2,gd,gm,dx,dy,step; int x,y,const1,const2,k,p,x_end; detectgraph(&gd,&gm); initgraph(&gd,&gm,"C:\\TC\\BGI"); printf("\ nEnter the end point coordinates of the line.......\n"); scanf("%d%d%d%d",&x1,&y1,&x2,&y2); dx=abs(x2-x1); dy=abs(y2-y1); p=2*dy-dx; const1=2*dy; const2=2*(dy-dx); if(x1>x2) { x=x2; y=y2; x_end=x1; } else { x=x1; y=y1; x_ end=x2; } putpixel(x,y,15); while(x<x_end) { X ++; If(p<0) p+=const1; else { y++; p+=const2; } putpixel(x,y,15); } getch(); closegraph(); }