Practical 3 CGR PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Practical No.3: Program to draw line using Bresenham’s algorithm.

I. Practical Significance

Bresenham’s line algorithm is an algorithm that determines the points of a n-


dimensional raster that should be selected in order to form a close approximation to a
straight line between two points.It is commonly used to draw line primitives in a bitmap
image.

II. Relevant Program Outcomes(POs):


• Basic knowledge: Apply knowledge of basic mathematics, sciences and basic
engineering to solve the broad-based Computer engineering problems.
• Discipline knowledge: Apply Computer programming knowledge to solve broad-
based computer engineering related problems.
• Experiments and practice: Plan to perform experiments and practices to use the
results to solve broad based Computer engineering problems
• Engineering tools: Apply relevant Computer programming technologies and tools
with an understanding of the limitations.
• Communication: Communicate effectively in oral and written form

III. Competency and practical skills


This practical is expect to develop the following skills in you

Develop ‘C’ programs to draw basic graphics objects:

1. Write syntax of graphic functions.


2. Write and Save a simple c program.
3. Setup graphics drivers, graphics mode and directory to run graphics program.
4. Compile the C program using Turbo C.
5. Debug and execute the program.

IV. Relevant Program Outcomes(s):


• Implement standard algorithms to draw various graphics objects using C program.

V. Practical Outcome(POs):

Implement DDA algorithm to draw line.

VI. Relevant Affective domain related Outcome(s):

a) Handle command Prompt environment.


b) Experiment with graphics environment.
c) Follow safety/ethical practices.

VII. Minimum Theoretical Background

Bresenham’s line algorithm determines the points to an n-dimensional raster that is selected to
form a close approximation to a straight line between two points. It is used to draw line primitives in
a bitmap image, as it uses only integer addition, subtraction and bit shifting.it is an incremental error
algorithm. It is one of the earliest algorithm developed in the field of computer graphics.

Consider a line with initial point (x1,y1) and terminal point (x2,y2) in device space. if Δx=x2-x1 and
Δy=y2-y1,we define the driving axis (DA) to be the x-axis if |Δx|≥ |Δy| and the y-axis if if |Δy|≥
|Δx|.The DA is used as the “axis of control” for the algorithm and is the axis of maximum movement.
Within the main loop of the algorithm, the co-ordinate corresponding to the DA is incremented by
one unit. The coordinate corresponding to the other axis (usually denoted by the passive axis or PA)
is only incremented as needed.

Procedure

1. Input the two line end-points,storing the left end-point in(x0,y0).


2. Plot the point(x0,y0)
3. Calculate the constants Δx, Δy, 2Δx,2Δy and (2Δy-2Δx) and get the first value for the
decision parameter as p0:2Δy-2Δx
4. At each xk along the line,starting at k=0,perform the following test:
If pk<0, the next point to plot is (xk+1,yk) and pk+1=pk+2Δy
Otherwise,the next point to plot is (xk+1,yk+1) and pk+1=pk+2Δy-2Δx

5. Repeat step 4 (Δx) times

Sample output of the source example:

I. Algorithm
(Write on blank pages)

II. Flowchart
(Draw on blank pages)
III. ‘C’ Program Code

I. Resources required

SR.NO. Name of Resource Specification Quantity Remarks


1 Hardware: Computer Computer(i3-i5 As per Batch For all
System prefarablre),RA Size Experiments
M minimum
2GB and
onwards but
not limited
2 Operating System Windows XP/ As per Batch For all
Windows Size Experiments
7/LINUX version
5.0 or later
3 Software Turboc/C++ As per Batch For all
Version 3.0 or Size Experiments
later with
DOSBOX

XI. Precautions

1.Ensure that all C statements must end with a semicolon(;).

2.Use white spaces in C to describe blanks and tabs.

3.Ensure use of proper graphics function For relevant object.

4.Follow Safety/ethical Practices.

XII. Results

……………………………………………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………………………………………………

……………………………………………………………………………………………………………………………………………………….

XIII. Conclusion(s)

…………………………………………………………………………………………………………………………………………………………..

…………………………………………………………………………………………………………………………………………………………..

…………………………………………………………………………………………………………………………………………………………..

XIV Practical Related Questions

1.Explain the term decision parameter.

2.Write advantages of Bresenharm’s algorithm over DDA

XV Exercise
1.Give following values for every iteration of bresenham’s algorithm to draw a line from (3,4) to (6,8)

Δx Δy 2Δx 2Δy P

2. 1.Give following values for every iteration of bresenham’s algorithm to draw a line from (-6,-6) to
(-14,-14)

Δx Δy 2Δx 2Δy P

You might also like