You are on page 1of 29

Unit - 3

Geometry
The smallest element which can be shown on a graph is a point.

The point A is placed in (x, y) plane & (x, y) is the position point of A. This
means point A is at x distance x direction & it is at distance y in the y
direction from the origin (0, 0). The ordered pair (x, y) is known as the co-
ordinates of the point A.

Straight line & line segment

Any two point specify in a plane will define a line. This means to
define a line we need at least two points. In the figure, there are two points
p1(x, y) & p2(x, y) that define a line L1. A random point (x1, y1) is set to be
on the line if & only if it specifies the equation of the line. The equation of a
straight line can be derived with the help of slope concept of a straight line
which measures the steepness of it. The slope is the rate at which an
ordinate of a point on the plane change with respect to a change in the
horizontal co-ordinate. This can be measured by the ratio between
differences of vertical co-ordinates of two points on the line to that of
horizontal co-ordinate of those two points. Generally, slope is denoted by
m.

1
.
Vertical distance between two points
. . m = ------------------------------------------------------
Horizontal distance between two points

Assume that, p1(x1, y1), p2(x2, y2) are the two points in a line, the slope
y2 - y1
m = ------------------
x2 - x1

There are four types of slope:

1. The straight line with positive slope.


2. The straight line with negative slope.
3. The straight line with zero slope.
4. The straight line with undefined infinite slop.

Derive an equation of a line in slope intercept from

The slope between any two points of a line always remains constant.
Let us consider two point p1(x1, y1) & p2(x2, y2) on a line. Let us also
assume that a point (x, y) on the same line according to equation of a
straight line slope between any twp points is constant. Then the slope is
y - y1 y2-y1
m = ----------------- & also m = -------------------
x - x1 x2-x1

2
y - y1 y2 - y1
------------------ = -----------------
x - x1 x2 - x1
y - y1
----------------- = m
x - x1

y - y1 = m(x - x1)

y - y1 = mx-mx1

y = mx-mx1+y1

y = mx + (y1-mx1)

Let us assume that b= (y1-mx1)

y = mx + b

The general form of equation of line


The general form of straight line is,

ax + by + c=0
where a, b and c are the constants, this equation can be derived as follows.
(y - y1) (y2 - y1)
--------------- = -----------------
(x - x1) (x2 -x1)

(y - y1) (x2 - x1) = (y2 - y1)(x - x1)

y(x2 - x1) - y1(x2-x1) = x(y2 - y1) - x1(y2 - y1)

y(x2 - x1) - y1x2 + x1y1 = x(y2 - y1) - x1y2 + x1y1

x(y2 - y1) + y (x2 - x1) – (x1y2 + y1x2) =0

Assume that,
a = (y2 - y1)
b = (x2 - x1)
c = (y1x2- x1y2)

3
ie, ax + by + c = 0
Line segment
A line segment is a part of line which has two end points & we can
find out the length of a line segment and mid point of a line segment.

Length of line segment

Let us imagine a line segment P1P2. The length of the line segment
can be find out by Pythagoras theorem

ie. (ac)2 = (ab)2+(bc)2

ie, l2 = (x1-x2)2 + (y1-y2)2

: l = ((x1- x2)2+(y1-y2)2)1/2

Midpoint of a line segment

The mid point of a line segment p 1 p 2 is located in the center of a line


segment & it bisect a line segment into two equal parts therefore, the co-
ordinates of a mid point would be,

x 1 +x 2 , y 1 +y 2
--------- ----------
2 2

4
Equation of line parallel to- axis at a distance a is,

y=a

Similarly equation of line parallel to y- axis ata distance b is

x=b

Equation of x-axis is,

y=0

Similarly equation of y-axis is

x=0

Let’s assume that we have two line segment


y=m1x+b1 &
y=m2x +b2

Where, m1 != m2, these two lines are not parallel to each other. Hence,
they will interact some point.

Let us assume that, a point (xi, yi) is a point which is an intersecting


point. Since it is an intersecting point will satisfy both the line equation
therefore,

yi = m1xi + b1 &
yi = m2xi + b2

m1xi + b1 = m2xi + b2
m1xi + m2xi = b2 - b1
b2 – b1
xi = --------------
m1 – m2

yi = m1( b2 – b1 ) + b1
------------------
m1 – m2

5
m1b2 – m1b1
= -------------------------- + b1
m 1 – m2

m1b2 – m1b1 + b1(m1-m2)


= -----------------------------------------
m1- m2

m 1b 2 - m 2b 1
= -------------------
m1 – m2

Thus, for the line segment

y = m1x1+ b1 &

y= m2x + b2 , the co-ordinates of the intersection point (xi, yi) are

b2 – b1 m 1b 2 - m 2b 1
-------------- , ------------------
m1 –m2 m1 – m2

Some line segment Properties

In this figure m1=m1, the slope of the both line is same, the two lines
are called parallel to each other,

6
In this figure m1 ≠ m2, the slopes are different but the intercept
values ‘b’ are same then such two lines pass through same point on y-
axis,

In this figure, the intercept value is 0 that means b=0, such line
passes though the origin & intercept at the origin.

7
Here, the line y = m1x + b1 & y = m2x + b 2 are perpendicular to each
other. This situation result into an intercepting relationship between the
two slope m1 & m2

Derived the relationship between m1 & m2 for the lines that are
perpendicular to each other

Let us consider two points P1(x1, y1) & P2(x2, y2) on two lines y1=
m1x & y2 = m2x respectively. As these two lines are perpendicular to each
other, the three points O(0,0), P1(x1, y1) & P2(x2, y2) form a right angled
triangle.

By using Pythagoras theorem,

(P1P2)2 = (P1O)2 + (OP2)2

(x1-x2)2 + (y1-y2)2 = (x1-0)2 - (y1-0)2 + (x2-0)2 + (y2-0)2

x12 - 2x1x2 + x22 + y12 - 2y1y2 + y22 = x12 + y12 + x22 + y22

8
-2 x1 x2 - 2y1y2 =0

-2 x1x2 = 2y1y2

- x1x2 = y1y2

- x2 y1
------- = ------
y2 x1
Since, y 1 = m1 x 1
y1
m1 = ----- &
x1

also y2 = m2x2

y2
m2 = -----
x2

-1
m1 = ------
m2

Therefore, if two lines y = m1x +b1 & y=m2x +b2 are perpendicular to each
other slope are negative reciprocals to each other.

Pixels & Frame Buffer


The pixel is the smallest addressable screen element. It is the
smallest piece of the display screen which we can control. Each pixel has
name & address. The name which identify pixel corresponds to the co-
ordinates which identify the points.

The maximum number of distinguishable points which a line may


have is the measure of the resolution of display device. The gre ater
number of points, the higher the resolution.

Computer Graphics images are made by setting the intensity &


colour of the pixel which compose the screen. We draw line segments by
setting the intensities, that is the brightness of a string of pixel between
starting pixel & ending pixel.

The co-ordinate will be(i , j ) that gives column & row of a pixel .

9
Each pixel will be centered at the co-ordinates. We can place the intensity
values of all pixels into an array of our computers memory.

Our graphic display device can then access this array to determine
the intensity at each pixel should be displayed. This array which contains
internal representation of the image is called F rame buffer it collects &
stores pixel values for use by the display devices.

Line drawing algorithm

The Cartesian slope intercept equation for a straight line is


y = mx + b (1)

with m represent the slope of the line & b as the y intercept.

Given that two end points of a line segment are specified at position (x1,y1)
& (x2,y2). We can determine the value for the slope m & y intercept b using
the following equation,
y2 - y1
m = -------------- (2)
x2 - x1

b = y1 - mx1 (3)

Algorithm for displaying a line are based on the equation (1) and
calculations are given in equation (2) & (3).
For any given x interval ∆x along a line, we can compute y interval ∆y.

∆y = mx (4)

Similarly, we can obtain x interval ∆x corresponding to specified ∆y as

10
∆y
∆x = --------- (5)
m

For line with slope segment |m|<1 [gentle slope, ∆x > ∆y], ∆x can be
set proportional to a small horizontal deflection voltage & the
corresponding vertical deflection is then set proportional to ∆y. ∆y can be
calculated from equation (4)

For line whose slope have magnitude |m|>1[steep slope, ∆y > ∆x]
∆y can be set proportional to a small vertical deflection voltage with the
corresponding horizontal deflection voltage is then set proportional to ∆x.
∆x can be calculated from equation (5).

For line with m=1, (∆x = ∆y) [smooth slope], the horizontal & vertical
voltages are equal. In such case a smooth line with slope m is generated
between specified end points.

Digital deflection analyzer (DDA)

DDA is a scan conversion algorithm based on calculating either ∆y or


∆x, using the equation (4) & (5). We sample the line at unit intervals in
one co-ordinate & determine corresponding integer value nearest the line
path for other co-ordinate.
Consider first a line with positive slope as shown in the figure. If the
slope is <=1, we sample at unit x-interval (∆x=1) & compute each
successive value of y as yk+1 = yk +m

If ∆x > ∆y
Then |m|<=1
∆x=1
yk+1 – yk =(mxk+1 +b) - (mxk + b)

11
yk+1 - yk = mxk+1 – mxk

= m(xk+1 – xk)

= m*1(because xk+1 – xk =1)


=m
yk+1 = yk +m

Subscript k takes an integer value starting from 1, for the first point
& increase by 1 until the final point is reached. m can be any real number
between 0 & 1. Then calculate y value and must be rounded to the nearest
integer.
For the lines with positive slope>1, we reverse the role of x & y that
means we sample at unit y intervals (∆y=1) & calculate each succeeding x
values as xk+1 =xk + 1/m

If ∆y > ∆x
Then |m|=>1
∆y=1
yk+1– yk = (mxk+1 +b) - (mxk +b)
1 = m(xk+1)-m(xk)
= m(xk+1-xk)

xk+1 –xk = 1/m

xk+1 = xk + 1/m
Equation yk+1 = yk + m & xk+1 = xk+1/m are based on the assumption
that the line are to be processed from left end point to the right end point.
If this process is reversed(slope is negative), so that starting end
point is at the right then yk+1 = yk –m because ∆x = -1 & xk+1=xk-1/m
because ∆y = -1

DDA algorithm

Step 1: read the end points (x1, y1) & (x2, y2), so that they are not
equal

Step 2: ∆x=|x2-x1| & ∆y =|y2-y1|

Step 3: if ∆x > ∆y

Step =∆x
Else
Step= ∆y

12
Step 4: ∆x =|x2-x1/steps|

∆y=|y2-y1/steps|

Step 5: x=x1 +.5 *sign (∆x)


y= y1+.5 *sign (∆y)

Step 6: i=0
while(i<=step)
{
plot(integer(x), integer(y))

x = x + ∆x

y = y+ ∆y

i = i+1
}
Step 7: stop

DDA algorithm is faster method for calculating pixel position by


the use of equation y = mx + b. It eliminates the multiplication so that
appropriate increments are applied in the x or y direction to step 2 pixel
position along the line path.

The assumption of round off error in successive of the floating point


increments can cause the calculated pixel position to drive away from the
rule line path for long line segments. In addition to the round operation of
floating point arithmetic in DDA algorithm are time consuming.

13
Bresenham line
An accurate & efficient raster line drawing algorithm developed by
Bresenham converts line using only incremental integer calculation that
can be adopted to display circle & other curves. The vertical axis shows
scan line positions & the horizontal axis shows pixel column.

Sampling at unit x interval in the above figure i.e.


m< 1, we need to decide which of two possible pixel position (y-value) is
closer to the line path at each sample step.

First considering the scan conversion process for lines with positive
slope, i.e m< 1. Pixel positions along a line path are determined by
sampling at unit a interval.

Starting from the left end point (x0, y0) we step to each successive
columns (x position) & plot the pixel whose scan line y is closer to the line
path. That means next pixel should be (xk+1,yk) or (xk+1,yk+1).

14
At sampling xk+1 we label vertical pixel separation from the
mathematical line path d1 &d2 as shown in the figure.

The y-co-ordinate on the mathematical line at pixel column position


xk+1 is calculated as equation,

y= m(xk+1) + b (1)

d1 = y - yk

= m(xk+1) + b - yk

d2 = yk+1 - yk

= yk+1 - (m(xk+1) +b )

= yk+1 - m(xk+1) - b

d1 - d2 = m(xk+1 ) + b - yk - (yk+1 – m(xk+1) -b )

= 2m(xk+1) - 2yk + 2b - 1 (2)

The decision parameter pk=∆x(d1-d2)

= ∆x(2m(xk+1) -2yk + 2b -1)

= ∆x(2∆y/∆x(xk+1) -2yk +2b -1)

= 2∆yxk - 2∆xyk + 2∆y + 2∆x(2b-1)

= 2∆yxk - 2∆xyk + c

where c = 2∆y + 2∆x(2b-1).

The decision parameter pk for the kth step in the line algorithm can
be obtained by re-arranging the equation, so that it involves only integer
calculation. pk =∆x(d1-d2), the sign of pk is same as the sign of (d1-d2) and
the parameter c in the equation pk is constant, and has the value 2∆y +
2∆x(2b-1) , which is independent of the pixel position and will be
eliminated the following calculation

The decision parameter p k determine the position of y co-ordinate at


x interval if p k is negative, we plot the lower pixel otherwise we plot the

15
upper pixel at position k+1 the decision parameter can be calculated as,

pk+1- pk = 2∆yxk+1 - 2∆xyk+1 +c - (2∆yxk - 2∆xyk - c)

= 2∆y(xk+1- xk)/2 - 2∆x(yk+1- yk)

pk+1 = pk + 2∆y- 2∆x(yk+1- yk)

where the term yk+1 - yk is either 0 or 1

if pk< 0 at k+1
position (xk+1, yk)
else
(xk+1, yk+1)

if pk<0 , yk+1 - yk = 0
else
yk+1 - yk = 1

if pk < 0 then yk+1- yk =0


pk+1 = pk + 2∆y
plot (xk+1, yk))
else
pk+1 = pk + 2 ∆y - 2∆x
plot(xk+1, yk+1)
at (x0,y0) the decision parameter can be calculated from,
p 0 = 2∆y-∆x

Algorithm
Step 1 − Input the two end-points of line, storing the left end-point
in (x0,y0)(x0,y0).
Step 2 − Plot the point (x0,y0)(x0,y0).
Step 3 − Calculate the constants dx, dy, 2dy, and (2dy – 2dx) and get
the first value for the decision parameter as −

p0=2dy−dxp0=2dy−dx
Step 4 − At each XkXk along the line, starting at k = 0, perform the
following test −
If pkpk < 0, the next point to plot is (xk+1,yk)(xk+1,yk) and
pk+1=pk+2dypk+1=pk+2dy
Otherwise,
pk+1=pk+2dy−2dxpk+1=pk+2dy−2dx

16
Step 5 − Repeat step 4 (dx – 1) times.

For m > 1, find out whether you need to increment x while incrementing
y each time.

After solving, the equation for decision parameter PkPk will be very
similar, just the x and y in the equation gets interchanged.

BRESENHAM ALGORITHM

Values of the frame buffer along a line segment with integer end points
Arguments XA and YA are the co-ordinates of other endpoint
XB and YB are the co-ordinates of other endpoint
INTENSITY is the intensity setting to be used for vector.
Global FRAME the two-dimensional frame buffer array
Local DX, DY the vector to be drawn
R,C the row and column indices for the pixel
F the final row or column
G for testing for a new row or column
INC1 increment for G when row or column is unchaged
INC2 increment for G when row or column changes
POS-SLOPE a flag to indicate if the slope is positive
BEGIN
Determine the components of the vector
DX <- XB-XA;
DY <- YB-YA;
Determine the sign of the slope
POS-SLOPE <-(DX>0);
IF DY <0 THEN POS-SLOPE <- NOT POS-SLOPE ;
Decide on whether to step across columns or up rows
IF |DX| > |DY| THEN
BEGIN
This is the gentle slope case
IF DX > 0 THEN
BEGIN
C <- XA;
R <- YA;
F <- XB;
END
ELSE
BEGIN
C <- XB;
R <- YB;
F <- XA;
END;
INC1 <- 2 * |DY|;
G <- 2 * |DY| - |DX|;

17
INC2 <- 2* ( |DY| - |DX|);
IF POS-SLOPE THEN
BEGIN
Now step across line segment
WHILE C <= F DO

BEGIN
Set nearest pixel in the frame buffer
FRAME[C,R] <- INTENSITY;
Next column
C <- C + 1;
Should row change
IF G >= 0 THEN
BEGIN
R <- R + 1;
G <- G + INC2;
END
ELSE G <- G + INC1;
END;
END
ELSE
BEGIN
WHILE C <= F DO
BEGIN
Set nearest pixel in the frame buffer;
FRAME[C, R] <-INTENSITY;
Next column
C <- C + 1;
Should row change
IF G > 0 THEN
BEGIN
R <- R -1 ;
G <- INC2;
END
ELSE G <- G + INC1;
END;
END
ELSE
BEGIN
This is the sharp slope case
Here the above steps are repeated
With the roles of X and Y interchanged
END;
RETURN;
END;

18
Vecgen Algorithm
In vecgen algorithm two end points are storing (x a, ya) & (xb, yb).
Intensity setting is to be used for the vector. Then calculate the value of
Dx & Dy. This is used to draw the vector R & C, the Row & column indices
for the pixel to be changed. The stopping index will be F. The line segment
co-ordinate D can be calculated at starting point. The Variable H denotes
the differences between line segment & row index. M=Dy/Dx, the slope of
the line segment is calculated for the change in H, when a boundary is
cross.

For the gentle slope -1<m< 1, there are more columns than rows.
These are the line segment when the length of x components Dx = X b - Xa
is longer than the length of Y components Dy = Yb - Ya. In this cases we
step across the column & slope for the row.
For the sharp slope case, where Dx < Dy, we step up the row & solve
for column.
Instead of determining the fall of Y value of line segment for e ach
column, we shall only keep the record of current height above the closest
low boundary, at each step. At each step height increases by m along with
Y can check the height at each step to see if we have to move into a new
row then the change row value is used to select the pixel.
For lines with negative slope, the height is decreased & check for
crossing of a lower row boundary [R = R -1].

19
For the line with sharp slope case, similar procedure is used only the
role of X & Y are exchanged. A new height is found for a new row by
adding 1/m to the height of the old row.
For gentle slop case, we shall turn on pixel in the columns that have
center line which crosser the line segment.
We shall center columns & rows on integer co-ordinate values, so if
Xa is the left end of the line segment & Xb is the right end of the line
segment. Then columns between c = ceiling(Xa) & f = floor(Xb) will be
affected. Our starting point Y position will be corresponds to the point X =
c & may not be end point YA. The starting Y value may be determined
from the equation as follows:

D = mc + b
= mc + ya - mxa , where b = ya - mxa
= ya + m(c - xa)

To find out the index of crosses row, we round the value of Y.


Rounding may be done by adding 0.5 and then use floor() function.

r = floor(d + 0.5)
To find the height of Y above the row boundary, we take the
difference of Y & R and add m, then we have height value which should be
check the next column.
H=r–d+m

VECGEN ALGORITHM
Values of the frame buffer along a line segment with integer end points
Arguments XA and YA are the co-ordinates of other endpoint
XB and YB are the co-ordinates of other endpoint
INTENSITY is the intensity setting to be used for vector.
Global FRAME the two-dimensional frame buffer array
Local DX, DY the vector to be drawn
R,C the row and column indices for the pixel
F the stopping index
D the line segment co-ordinate at the starting point
H the difference between the line segment and the row index
M the slope of the line segment
M1 the change in H when a boundary is crossed

BEGIN
Determine the components of the vector
DX <- XB-XA;
DY <- YB-YA;

20
Decide on whether to step across columns or up rows
IF |DX| > |DY| THEN
BEGIN
This is the gentle slope case
M <- DY/DX;
Set up of starting point depends on which point is leftmost
IF DX > 0 THEN

BEGIN
C <- CEILING(XA);
D <- YA + M * (C – XA)
F <- FLOOR(XB);
END
ELSE
BEGIN
C <- CEILING(XB);
D <- YB + M * (C – XB)
F <- FLOOR(XA);
END;
R <- FLOOR(D + 0.5);
H <- R – D + M;
IF M > 0 THEN
BEGIN
The positive slope case
M1 <- M – 1;
Now step through the columns WHILE C<= F DO
BEGIN
Set the nearest pixel in the frame buffer
FRAME[C, R] <- INTENSITY;
Next column
C <- C + 1;
Show row change
IF H >= 0.5 THEN
BEGIN
R <- R + 1;
H <- H + M1;
END
ELSE H <- H + M;
END;
END
ELSE
BEGIN
Then negative slope case

21
M <- -M;
H <- -H;
M1 <- M – 1;
WHILE C <= F DO
BEGIN
Set the nearest pixel in the frame buffer
FRAME[C, R] <- INTENSITY;
Next column
C <- C + 1;
Should row change
IF H > 0.5 THEN
BEGIN
R <- R -1;
H <- H + M1;
END
ELSE H <- H + M;
END;
END;
ELSE
BEGIN
The sharp slope case
IF DY = 0.0 THEN RETURN;
Here the above steps are repeated
With the roles of x and y interchanged
END;
RETURN;
END;
END
ELSE
BEGIN
This is the sharp slope case
Here the above steps are repeated
With the roles of X and Y interchanged
END;
RETURN;
END;

Illustrate the vecgan algorithm and draw a line with the end points (20,10)
& (30,18).
C = ceiling(Xa) = 20
m = 8/10 = 0.8
F = floor(Xb) = 30

22
D =Ya + m(C - Xa ) =10 + 0.8(20-20) =10
R = floor(d + 0.5) = floor(10+0.5) =10
m = m – 1 = 0.8 – 1 = -0.2
H = r – d + m =10 – 10 +0.8 =0.8
*check with condition
If h >= 0.5
H= H+m
Else
H = H + m1
H= 0.8 + -0.2 =0.6 (20,10)
H= 0.6 + -0.2 =0.4 (21,11)
H= 0.4 + 0.8 =1.2 (22,11)
H= 1.2 + -0.2 =1 (23,12)
H= 1 + -0.2 =0.8 (24,13)
H= 0.8 + -0.2 =0.6 (25,14)
H= 0.6+ -0.2 =0.4 (26,15)
H= 0.4 + 0.8 =1.2 (27,16)
H= 1.2 + -0.2 =0.8 (28,17)
H= 0.8 + -0.2 =0.6 (29,18)
H= 0.6 + -0.2 =0.4 (30,18)

ANTIALIASING OF LINES

Many displays allow only two pixel states, on or off. For these
displays, lines may have a jagged or stair-step appearance when they step
from one row or column to the next. This is one aspect of a phenomenon
called aliasing. Aliasing produces the defects which occur when the scene
being displayed changes faster or more smoothly than every two pixel.
Displays which allow setting pixels to gray levels between black and white
provide a means to reduce this effect. The technique is called antialiasing,
and it uses the gray levels to gradually turn off the pixels in one row as it
gradually turns on the pixels in the next.
The vector generation algorithms can be modified to perform
antialiasing. Remember that for gentle sloped lines, the line position for
each column index and decided which row was closest. The line segment
would lie between two pixels, and we picked one. Suppose that instead of
picking the closest, we turned them both on. We should choose the
intensity values according to a function of the distance between the pixel
index and the line segment so that the pixel closest to the line receives
most of its intensity. The sum of the intensity values for the two pixels
should match the total intensity value for the line.

23
Aliasing is a fact of any computer image which depends on a grid of
finite number of pixels in the horizontal and vertical direction. It can not
be eliminated, but its visually irritating obviousness can be minimized.

The following approaches are possible for reducing jagging of image:

1) To increase the resolution to such an extent that means more pixels


become available to coincide with the computed values. In other
words, to make the steps so small and so many that the staircase
begins to look more like a sloping ramp.

2) By an Anti-Aliasing process:
Display two or more pixels around the computed location at varying
intensities, or by Dithering (combining pixels of available colours),
rather than a single pixel at the rounded off location.

3) Shift the pixel by a fraction of the dimension, ¼, ½, or ¾, in a


recently discovered technique called Pixel Phasing.

y = mx + b

m = 0.3
x= 20
to 30 ,
b= 39

x= 20 21 22 23 24 25 26 27 28 29 30
y= 45 45.3 45.6 45.9 46.2 46.5 46.8 47.1 47.4 47.7 48

20 21 22 23 24 25 26 27 28 29 30
45
46
47
48
upper and 45 100 70 40 10
lower row 46 30 60 90 80 50 20
percentage 47 20 50 80 90 60 30

24
48 10 40 70 100

Line Styles:-

Many different style of lines are required. Generally solid lines,


dashed lines, dotted lines & thick lines are used as different line style in
graphics application. Dashed lines & dotted lines are generated by minor
modification in DDA, VECGEN & Bresenham algorithm.

A dashed line can be generated by inter dashed space between the


dashes. Generally, dashes & inter dashed spaces are equal in length,
where as a dotted line can be generated by very short length dashes.
Thick lines:- The thick line primitives more interesting. A line or a line

segment generated by the standard DDA algorithm of a single pixel width.

(x2,y2+ wy )
(x2,y2)

(x2, y2- wy )
Upper Line
Boundary

Lower Line
Boundary
(x1,y1+ wy )
x1,y1)
(x1,y1- wy )

25
Consider a line segment of slope m<1. Let P 1(x1, y1) & P2(x2, y2) are
the end points of a line segment with width w. Here two parallel line
segments will be drawn from a central line (x 1, y1) & (x2, y2) at a distance
w/2.
The co-ordinates of end points of upper & lower boundaries are (x 1,
y1+wy) & (x2, y2+wy) & (x1, y1-wy) & (x2, y2 -wy) respectively. The value of w y
can be calculated from the following equation:

w y = w-1 (x 2 - x 1 ) 2 + (y 2 - y 1 )2
2 | x2 - x1 |

In the above equation, w-1 is taken instead of a w. The reason is on both


side line boundaries are drawn, which are of 1 pixel in length. Therefore
from both the side half of the pixel width will be deducted to get exact
width w.
For a line segment with steep slope case [slope m > 1] the roll of the
(x, y) will be interchanged the co-ordinates will be (x1+ wx, y1 ) and (x2+wx,
y2 ) respectively. wx can be calculated,

w x = w-1 (x 2 - x 1 ) 2 + (y 2 - y 1 )2
2 | y 2 - y1 |

Line caps:-
There are three types of line caps are available in graphics application
to make the effect of thick lines more prominent.

They are
(a) Butt cap
(b) Round cap

(c) Projecting cap

26
(a) Butt cap:-
The butt cap is the cap with which end positions of the thick lines are
adjusted in such a way that the line segment appears with square ends.
The ends of such thick lines are perpendicular to the original line segment.

(b) Round Cap:-


In the Round cap upper & lower line boundaries are joined by circular
or with semi circle of diameter of width same as the width of the line
segment.
(c) Projecting Square Cap
The projecting square cap can be drawn by extending the portion of line
segment & join it to make a square.
Thick Line Joints

(a) Miter Joint (b) Round Joint (c) Bevel Joint

Construction of thick line joints

When two thick segments are connected with each other, they create
problem at joining point. When two thick line segments are joined an angle
is created at the joining point.

The problem that occurred while joining two thick lines can be
removed from the poly lines by adding some additional portion to the joint
by using some specific type of joining process. These joints are miter joint,
round joint and bevel joint as shown in the figure.

(a) Miter Joint


The miter joint is one in which the exterior boundaries of two thick
line segments are extended up to their intersection points(the point where
this two line segments meet each other if they extended.

(b) Round joint

27
In Round joint, the exterior boundaries are connected with a circular
arc with a diameter of total thickness of two thick lines, which are joined.

(c) Bevel joint


Bevel joint is one where butt cap is used to draw line segments & a
small triangle that is created at the joint is filled with colour of these two.
Character generation:-
Characters are almost always built into the graphics display devices.
Usually, by hardware but sometimes through software.
There are two primary methods for character generation.
1. Stroke method.

2. Dot matrix/Bitmap.

Stroke method:-
This method creates character by a series of line segment like
strokes of a pen. We could build our own stroke method character
generator by using the line drawing (VECGEN) Algorithm. We could
decide what line segment are needed for each character & set ups the calls
to the line drawing (VECGEN) algorithm for each character we wish to. In
actual graphics display the commands for drawing the character line
segment may be in either hardware or software.
The stroke method provides itself to change of scale(dimension). The
character may be made twice as large by simply doubling the length of
each segment.

Dot Matrix / Bitmap:-

It is the 2nd method of character generation. In this scheme,


characters are represented by an array of dots. An array of 5 dots wide & 7
dots high is often used. But 7X9, 9X13 arrays are also found in high
resolution devices such as Inkjet or Laser printer may use characters
array that printer may use character arrays that are over 100 pixels on a
nozzle.

This array is like a small frame buffer, just big enough to hold
character. The dots are the pixels for this small array. The memory
containing the character dot matrix array is often a hardware device called
a character generator chip.
The size of a dot is fixed, so the dot matrix method does not allow
itself to change its size.

Stroke Method Dot matrix / Bitmap method

28
1 2

29

You might also like