gip5
DESCRIPTION
useTRANSCRIPT
OUTPUT PRIMITIVES
Set pixel(x,y intensity)
Get pixel(x,y)
LINE DRAWING ALGORITHM
Cartesian slope intercept equation for a straight line
Y=mx+b;
m=slope and b as the y-intercept
m=y2-y1/x2-x1 ------1
b=y1-m.x1 ------2
y =m x -------3
x = y/m -------4
For lines with slope magnitudes < 1, x is set proportional to small horizontal deflection voltage and corresponding y from 3
For slopes with magnitude > 1 y is set proportional to small vertical deflection voltage and corresponding horitonal deflection voltage set proportional to x from 4
DAA ALGORITHM
Digital differential analyzer is based on calculating x or y
We sample the line or unit intervals in one coordinate and determine corresponding interger values nearest the line path for the other coordinate
Positive slope
If slope <=1 x=1 and compute yk +1=yk+m
K=1 is increased by I until the final endpoint is reached
If slope >1 , y=1 and compute
Xk+1=Xk+1/m (left end point to right end point)
If this processing is reversed, starting endpoint is at right
X=-1
Yk+1=yk-m
Slope >1, y=-1 and Xk+1=Xk -1/m
DAA is faster method , disadvantage and round off error can cause calculated pixel positions to drift away from the true line path
Procedure line DAA(xa,ya,xb,yb=interger)
Var
dx,dy,steps,k:=interger;
xinc,yinc,x,y:=real
Begin
dx=xb-xa
dy=yb-ya
If abs(dx)>abs(dy) then steps =abs(x)
else steps=abs(dy)
xinc=dx/steps
yinc=dy/steps
x=xa
y=ya
Setpixel(round(x),round(y),1);
for k=1 to steps do
x=x+xinc;
y=y+yinc;
Setpixel(round(x),round(y),1)
End
End;(line DAA)
Bresenham’s line algorithm
Developed by bresenham .Used to draw line, adapted to display circles and curves.
Specified line path
13
12
11
10
10 11 12 13
Vertical axes show scan-line position and horizontal axes identify pixel columns.
Sampling at unit 11 interval, decide which of two possible pixel position is closer to the line path at each sample step.
Next position (11,11) or (11,12)
Answered by Bresenham’s line algorithm by testing the sign of the integer parameter and difference between the separations of the two pixel positions from the actual line path
Positive slope <1
Current pixel position(xk,yk),next pixel would be at (xk+1,yk) and (xk+1,yk+1)
At xk+1
Yk+1 d2
Y d1
yk
xk+1
the y coordinate on the mathematical line at pixel column position xk+1 is
y=m(xk+1)+b 1
then
d1=y-yk
=m(xk+1)+b-yk 2 from 1
And d2=(yk+1)-y
=yk+1-m(xk+1)-b
d1-d2=2m(xk+1)-2yk+2b-1
A decision parameter pk is obtained by finding m= y/ x
Pk= x(d1-d2)
=2 y.xk-2 x.yk+c
Sign of pk is sign of (d1-d2) since x>0
Parameter c is a constant
C=2 y+ x(2b-1)
If d1<d2 , we plot the lower pixel pk is negative. Otherwise we plot the upper pixel
Pk+1=2 y.xk+1- 2 x yk+1+c
Pk+1-pk=2 y(xk+1-xk)-2 x(yk+1-yk)
But xk+1=xk+1 so that
Pk+1=pk+2 y-2 x(yk+1-yk)
The first parameter p0 is evaluated starting from pixel position (x0 yo) and
m= x/ y
b=(y0-mx0)
p0=2 y- x
|m|<1
1)Input the two line end points and store the left endpoint(x0 y0)
2) Load (x0 y0) into the frame buffer (ie) load the first point
3)Calculate constants x, y 2 y and 2 y-2 x and obtain the starting decision parameter
P0 =2 y- 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 plot point is(xk+1,yk+1)
Pk+1=pk+2 y-2 x
Repeat steps and x times (20 ,10) and (30,18) x=10 y=8
P0=2 y- x = 6
2 y=16 2 y- x=-4
K pk
6