TOPIC IV - V - Line Drawing Algorithms and Primitive Outputs
TOPIC IV - V - Line Drawing Algorithms and Primitive Outputs
PRIMITIVES
Unit Structure
2.0 Objectives
2.1 Introduction
2.2 Scan-Conversion of a Lines
2.3 Scan-Conversion of Circle and Ellipse
2.3.1 Digital Differential Analyzer Algorithm
2.3.2 Bresenham's Line-Drawing Algorithm
2.4 Drawing Ellipses and Other Conics
2.4.1 Bresenham's Method of Circle Drawing
2.4.2 Midpoint Circle Algorithm
2.5 Drawing Ellipses and Other Conics
2.0 OBJECTIVES
2.1 INTRODUCTION
If two endpoints of the line are specified at positions (x1,y1) and (x2,y2), the
values of the slope m and intercept b can be determined as
For lines with magnitude |m| < 1, ∆x can be set proportional to a small horizontal
deflection and the corresponding horizontal deflection is set proportional to ∆y
and can be calculated as:
For lines with |m|>1, ∆y can be set proportional to small vertical deflection and
corresponding ∆x which is set proportional to horizontal deflection is calculated
using:
The following shows line drawn between points (x1, y1) and (x2, y2).
ALGORITHM I
Sampling of the line at unit interval is carried out in one coordinate and
corresponding integer value for the other coordinate is calculated.
If the slope is less than or equal to 1( |m| ≤ 1), the coordinate x is sampled at
unit intervals (∆x = 1) and each successive values of y is computed as:
where k varies from 1 to the end point value taking integer values only. The
value of y calculated is rounded off to the nearest integer value.
For slope greater than 1 (|m| > 1), the roles of y and x are reversed, i.e., y is
sampled at unit intervals (∆y = 1) and corresponding x values are calculated as:
For negative value slopes, we follow the same procedure as above, only the
sampling unit ∆x and ∆y becomes ‘-1’ and;
Pseudo code
LineDDA(Xa, Ya, Xb, Yb) // to draw a line from (Xa, Ya) to (Xb, Yb)
{
Set dx = Xb - Xa, dy = Yb - Ya;
Set steps = dx;
SetX = Xa, Y = Ya;
int c = 0;
Call PutPixel(Xa, ya);
For (i=0; i <steps; i++)
{
X=X+1;
c = c + dy; // update the fractional part
If (c > dx)
{ // (that is, the fractional part is greater than 1
now
Y = y +1; // carry the overflowed integer over
c = c - dx // update the fractional part Call PutPixel(X, Y);
}
}
}
STEPS
I. Read the end points of the line and store left point in (x0, y0)
II. Plot (x0, y0), the first point.
III. Calculate constants ∆x, ∆y, 2∆y and 2∆y - 2∆x, and obtain a decision
parameter p0 as;
NOTE: For a line with positive slope more than 1, the roles of the x and y
directions are interchanged.
PRACTICAL CAT2:
PART 4: Given a line with endpoints at (20, 10) and (30,18) use Brensenham’s line
drawing algorithm to generate the successive pixel positions. Let (X0, Y0=(20,10).
A circle with centre (xc, yc) and radius r can be represented in equation form in three
ways:
2 2 2
Analytical representation: r = (x – xc) + (y – yc)
2 2 2
Implicit representation: (x – xc) + (y – yc) – r = 0
A circle is symmetrical in nature. Eight – way symmetry can be used by reflecting each
o
point about each 45 axis. The points obtained in this case are given below with
illustration by figure.
P1 = (x, y) P5 = (-x, -y)
P2 = (y, x) P6 = (-y, -x)
P3 = (-y, x) P7 = (y, -x)
P4 = (-x, y) P8 = (x, -y)
Bresenham_Circle (Xc,Yc, R)
{
Set X = 0;
Set Y= R;
Set D = 3 – 2R;
While (X < Y)
{
Call Draw_Circle (Xc, Yc, X, Y);
X=X+1;
if (D < 0)
{
D=D+4X+6;
}
else
{
Y=Y–1;
D=D+4(X–Y)+10;
}
Call Draw_Circle (Xc, Yc, X, Y);
}
}
Draw_Circle (Xc, Yc, X, Y)
{
Call PutPixel (Xc + X, Yc, +Y);
Call PutPixel (Xc – X, Yc, +Y);
Call PutPixel (Xc + X, Yc, – Y);
Call PutPixel (Xc – X, Yc, – Y);
Call PutPixel (Xc + Y, Yc, + X);
Call PutPixel (Xc – Y, Yc, – X);
Call PutPixel (Xc + Y, Yc, – X);
Call PutPixel (Xc – Y, Yc, – X);
}
In this algorithm, we define the unit interval and consider the nearest point of the circle
boundary in each step.
1. If pk < 0 then yk+1=yk, by this the plotting points will be ( xk+1 ,yk). By this
the value for the next point will be given as:
Pk+1=pk +2(xk+1) +1
2. If pk > 0 then yk+1=yk-1, by this the plotting points will be (xk+1, yk-1). By this
the value of the next point will be given as:
Pk+1=pk+2(xk+1) +1-2(yk+1)
Pk+1=pk+2(xk+1) +1-2(yk+1)
Now the DDA algorithm for circle can be applied to draw the ellipse.
Similarly a conic can be defined by the equation
If starting pixel on the conic is given, the adjacent pixel can be determined similar to
the circle drawing algorithm.
ASSIGNMENT:
1. Write down the equation of a standard ellipse.
2. Which scan conversion technique can be applied to draw an ellipse?
3. Explain how ellipse and other conics can be drawn using scan conversion
technique.