CG 5
CG 5
XAVIER’S COLLEGE
MAITIGHAR, KATHMANDU
Lab Report 5
Line using BLA algorithm
Submitted by
Jeshika Baniya
019BIM017
Submitted to
Mr. Ganesh Yogi
Lecturer
Department of Computer Science
St. Xavier’s College
BLA Algorithm
This algorithm is used for scan converting a line. It was developed by Bresenham. It is an
efficient method because it involves only integer addition, subtractions, and multiplication
operations. These operations can be performed very rapidly so lines can be generated quickly.
In this method, next pixel selected is that one who has the least distance from true line.
The method works as follows:
Assume a pixel P1'(x1',y1'),then select subsequent pixels as we work our may to the night, one
pixel position at a time in the horizontal direction toward P2'(x2',y2').
To chooses the next one between the bottom pixel S and top pixel T.
If S is chosen
We have xi+1=xi+1 and yi+1=yi
If T is chosen
We have xi+1=xi+1 and yi+1=yi+1
The actual y coordinates of the line at x = xi+1is
y=mxi+1+b
di=△x (2 (xi+1)+2b-2yi-1)
=2△xyi-2△y-1△x.2b-2yi△x-△x
di=2△y.xi-2△x.yi+c
Where c= 2△y+△x (2b-1)
We can write the decision variable di+1 for the next slip on
di+1=2△y.xi+1-2△x.yi+1+c
di+1-di=2△y.(xi+1-xi)- 2△x(yi+1-yi)
Since x_(i+1)=xi+1,we have
di+1+di=2△y.(xi+1-xi)- 2△x(yi+1-yi)
Special Cases
If chosen pixel is at the top pixel T (i.e., di≥0) ⟹ yi+1=yi+1
di+1=di+2△y-2△x
If chosen pixel is at the bottom pixel T (i.e., di<0) ⟹ yi+1=yi
di+1=di+2△y
Finally, we calculate d1
d1=△x[2m(x1+1)+2b-2y1-1]
d1=△x[2(mx1+b-y1)+2m-1]
package jeshika;
import java.awt.*;
import javax.swing.*;
public class bla extends JFrame
{
bla()
{
setSize(700,700);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout(FlowLayout.CENTER));
}