Points, Lines, Circles and Ellipses As Primitives, Conversion Algorithms For Primitives
Points, Lines, Circles and Ellipses As Primitives, Conversion Algorithms For Primitives
Points, Lines, Circles and Ellipses As Primitives, Conversion Algorithms For Primitives
Lecture 5
Points, lines, circles and ellipses as primitives, conversion
algorithms for primitives
Introduction
A picture is completely specified by the set of intensities for the pixel positions in the
display. Shapes and colors of the objects can be described internally with pixel arrays
into the frame buffer or with the set of the basic geometric structure such as straight
line segments and polygon color areas. To describe structure of basic object is referred
to as output primitives. Each output primitive is specified with input co-ordinate data
and other information about the way that objects is to be displayed. Additional output
primitives that can be used to constant a picture include circles and other conic sections,
quadric surfaces, Spline curves and surfaces, polygon floor areas and character string.
Points and Lines Point plotting
is accomplished by converting a single coordinate position furnished byan application
program into appropriate operations for the output device. With a CRTmonitor, for
example, the electron beam is turned on to illuminate the screen phosphor atthe
selected location
Line drawing
is accomplished by calculating intermediate positions along the line
path between two specified end points positions. An output device is then directed to fill
inthese positions between the end points Digital devices display a straight line segment
by plotting discrete points between the two end points. Discrete coordinate positions
along the line path are calculated from the equation of the line. For a raster video
display, the line color (intensity) is then loaded into the frame buffer at the
corresponding pixel coordinates. Reading from the frame buffer, the video controller
then plots “the screen pixels”. Pixel positions are referenced according to scan-line
number and column number (pixel position across a scan line). Scan lines are numbered
consecutively from 0, starting
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 11
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
at the bottom of the screen; and pixel columns are numbered from 0, left to right across
each scan line 2. Pixel Positions reference by scan line number and column number to
load an intensity value into the frame buffer at a position corresponding to column
xalong scan line y,setpixel (x, y) To retrieve the current frame buffer intensity setting for
a specified location we use a low level function getpixel (x, y)
Line Drawing Algorithms
Digital Differential Analyzer (DDA) Algorithm
Bresenham’s Line Algorithm
Parallel Line AlgorithmThe Cartesian
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 12
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Lecture 6
Digital Differential Analyzer Algorithm
Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm
which is explained step by step here.
Step 1 − Get the input of two end points (X0,Y0)(X0,Y0) and (X1,Y1)(X1,Y1).
Step 2 − Calculate the difference between two end points.
dx = X1 - X0
dy = Y1 - Y0
Step 3 − Based on the calculated difference in step-2, you need to identify the number
of steps to put pixel. If dx > dy, then you need more steps in x coordinate; otherwise in
y coordinate.
Step 5 − Put the pixel by successfully incremen ng x and y coordinates accordingly and
complete the drawing of the line.
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 13
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Lecture 7
Bresenham’s Line Drawing Algorithm
The Bresenham algorithm is another incremental scan conversion algorithm. The big
advantage of this algorithm is that, it uses only integer calculations. Moving across the x
axis in unit intervals and at each step choose between two different y coordinates.
For example, as shown in the following illustration, from position (2, 3) you need to
choose between (3, 3) and (3, 4). You would like the point that is closer to the original
line.
At sample position Xk+1,Xk+1, the vertical separations from the mathematical line are
labelled as dupperdupper and dlowerdlower.
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 14
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
From the above illustration, the y coordinate on the mathematical line at xk+1xk+1 is −
Y = m(XkXk+1) + b
So, dupperdupper and dlowerdlower are given as follows −
dlower=y−ykdlower=y−yk
=m(Xk+1)+b−Yk=m(Xk+1)+b−Yk
and
dupper=(yk+1)−ydupper=(yk+1)−y
=Yk+1−m(Xk+1)−b=Yk+1−m(Xk+1)−b
You can use these to make a simple decision about which pixel is closer to the
mathematical line. This simple decision is based on the difference between the two
pixel positions.
dlower−dupper=2m(xk+1)−2yk+2b−1dlower−dupper=2m(xk+1)−2yk+2b−1
Let us substitute m with dy/dx where dx and dy are the differences between the end-
points.
dx(dlower−dupper)=dx(2dydx(xk+1)−2yk+2b−1)dx(dlower−dupper)=dx(2dydx(xk+1)−2yk
+2b−1)
=2dy.xk−2dx.yk+2dy+2dx(2b−1)=2dy.xk−2dx.yk+2dy+2dx(2b−1)
=2dy.xk−2dx.yk+C=2dy.xk−2dx.yk+C
So, a decision parameter PkPk for the kth step along a line is given by −
pk=dx(dlower−dupper)pk=dx(dlower−dupper)
=2dy.xk−2dx.yk+C=2dy.xk−2dx.yk+C
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 15
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 16
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Lecture 8
Mid-Point Circle Drawing Algorithm
Step 1 − Input radius r and circle center (xc,yc)(xc,yc) and obtain the first point on the
circumference of the circle centered on the origin as
f(x, y) = x2 + y2 - r2 = 0
f(xi - 1/2 + e, yi + 1)
= (xi - 1/2 + e)2 + (yi + 1)2 - r2
= (xi- 1/2)2 + (yi + 1)2 - r2 + 2(xi - 1/2)e + e2
= f(xi - 1/2, yi + 1) + 2(xi - 1/2)e + e2 = 0
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 17
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 18
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Step 3 − At each XKXK position starting at K=0, perform the following test −
X = X + XC, Y = Y + YC
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 19
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Lecture 9
Mid-Point Ellipse Drawing Algorithm
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 20
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
1. Take input radius along x axis and y axis and obtain center of ellipse.
2. Initially, we assume ellipse to be centered at origin and the first point as : (x, y 0)=
(0, ry).
3. Obtain the initial decision parameter for region 1 as: p1 0=ry2+1/4rx2-rx 2ry
4. For every xk position in region 1 :
If p1k<0 then the next point along the is (xk+1 , yk) and p1k+1=p1k+2ry2xk+1+ry2
Else, the next point is (xk+1, yk-1 )
And p1k+1=p1k+2ry2xk+1 – 2rx2yk+1+ry2
5. Obtain the initial value in region 2 using the last point (x 0, y0) of region 1 as:
p20=ry2(x0+1/2)2+rx2 (y0-1)2-rx2ry2
6. At each yk in region 2 starting at k =0 perform the following task.
If p2k<0 the next point is (xk, yk+1) and p2k+1=p2k-2rx2yk+1+rx2
7. Else, the next point is (xk+1, yk -1) and p2k+1=p2k+2ry2xk+1 -2rx2yk+1+rx2
8. Now obtain the symmetric points in the three quadrants and plot the coordinate
value as: x=x+xc, y=y+yc
9. Repeat the steps for region 1 until 2ry2x>=2rx2y
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 21
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Lecture 10
Fill area primitives including scan line polygon filling inside-outside
test, boundary and flood-fill
Polygon is an ordered list of vertices as shown in the following figure. For filling
polygons with particular colors, you need to determine the pixels falling on the border
of the polygon and those which fall inside the polygon. In this chapter, we will see how
we can fill polygons using different techniques.
Step 2 − ScanLine intersects with each edge of the polygon from Ymin to Ymax. Name
each intersection point of the polygon. As per the figure shown above, they are named
as p0, p1, p2, p3.
Step 3 − Sort the intersection point in the increasing order of X coordinate i.e. (p0, p1),
(p1, p2), and (p2, p3).
Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the
alternate pairs.
Flood Fill Algorithm
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 22
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Sometimes we come across an object where we want to fill the area and its boundary
with different colors. We can paint such objects with a specified interior color instead
of searching for particular boundary color as in boundary filling algorithm.
Instead of relying on the boundary of the object, it relies on the fill color. In other
words, it replaces the interior color of the object with the fill color. When no more
pixels of the original interior color exist, the algorithm is completed.
Once again, this algorithm relies on the Four-connect or Eight-connect method of filling
in the pixels. But instead of looking for the boundary color, it is looking for all adjacent
pixels that are a part of the interior.
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 23
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Algorithm
Step 1 − Ini alize the value of seed point (seedx, seedy), fcolor and dcol.
Step 2 − Define the boundary values of the polygon.
Step 3 − Check if the current seed point is of default color, then repeat the steps 4 and
5 till the boundary pixels reached.
Step 4 − Change the default color with the fill color at the seed point.
setPixel(seedx, seedy, fcol)
Step 5 − Recursively follow the procedure with four neighborhood points.
FloodFill (seedx – 1, seedy, fcol, dcol)
FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)
Step 6 − Exit
There is a problem with this technique. Consider the case as shown below where we
tried to fill the entire region. Here, the image is filled only partially. In such cases, 4-
connected pixels technique cannot be used.
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 24
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
8-Connected Polygon
In this technique 8-connected pixels are used as shown in the figure. We are putting
pixels above, below, right and left side of the current pixels as we were doing in 4-
connected technique.
In addition to this, we are also putting pixels in diagonals so that entire area of the
current pixel is covered. This process will continue until we find a boundary with
different color.
Algorithm
Step 1 − Ini alize the value of seed point (seedx, seedy), fcolor and dcol.
Step 2 − Define the boundary values of the polygon.
Step 3 − Check if the current seed point is of default color then repeat the steps 4 and 5
till the boundary pixels reached
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 25
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Inside-outside Test
This method is also known as counting number method. While filling an object, we
often need to identify whether particular point is inside the object or outside it. There
are two methods by which we can identify whether particular point is inside an object
or outside.
Odd-Even Rule
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 26
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
From the above figure, we can see that from the point (x,y), the number of interactions
point on the left side is 5 and on the right side is 3. From both ends, the number of
interaction points is odd, so the point is considered within the object.
Nonzero Winding Number Rule
This method is also used with the simple polygons to test the given point is interior or
not. It can be simply understood with the help of a pin and a rubber band. Fix up the
pin on one of the edge of the polygon and tie-up the rubber band in it and then stretch
the rubber band along the edges of the polygon.
When all the edges of the polygon are covered by the rubber band, check out the pin
which has been fixed up at the point to be test. If we find at least one wind at the point
consider it within the polygon, else we can say that the point is not inside the polygon.
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 27
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
In another alternative method, give directions to all the edges of the polygon. Draw a
scan line from the point to be test towards the left most of X direction.
Give the value 1 to all the edges which are going to upward direction and all other
-1 as direction values.
Check the edge direction values from which the scan line is passing and sum up
them.
If the total sum of this direction value is non-zero, then this point to be tested is
an interior point, otherwise it is an exterior point.
In the above figure, we sum up the direction values from which the scan line is
passing then the total is 1 – 1 + 1 = 1; which is non-zero. So the point is said to be
an interior point.
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 28
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Lecture 11
Character generation, character attributers, line attributes, area-fill
attributes
Basic attributes of a straight line segment are its type, its width, and its color. In some
graphics packages, lines can also be displayed using selected pen or brush options.
ATTRIBUTES
LINE ATTRIBUTES
Basic attributes of a straight line segment are its type, its width, and its color. In some
graphics packages, lines can also be displayed using selected pen or brush options.
Line Type
We modify a line drawing algorithm to generate such lines by setting the length and
spacing of displayed solid sections along the line path.
A dashed line could be displayed by generating an interdash spacing that is equalto the
length of the solid sections. Both the length of the dashes and the interdashspacing are
often specified as user options. A dotted line can be displayed bygenerating very short
dashes with the spacing equal to or greater than the dash size. Similar methods are used
to produce other line-type variations.
To set line type attributes in a PHICS application program, a user invokes the function
setLinetype (It)
Line Width
We set the line-width attribute with the command: Line-width parameter lr. is assigned
a positive number to indicate the relative width of the line to be displayed. A value of 1
specifies a standard-width line. On.
For lines with slope magnitude greater than 1, we can plot thick lines withhorizontal
spans, alternately picking up pixels to the right and left of the linepath.
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 29
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Problem with implementing width options using horizontal or vertical pixel spans is that
the method produces lines whose ends are horizontal or vertical regardless of the slope
of the line. This effect is more noticeable with very thick lines. We can adjust the shape
of the line ends to give them a better appearance by adding line caps
One kind of line cap is the butt cap obtained by adjusting the end positions of the
component parallel lines so that the thick line is displayed with square ends that are
perpendicular to the line path. If the specified line has slope m, the square end of the
thick line has slope - l / m .
Another line cap is the round cap obtained by adding a filled semicircle to eachbutt cap.
The circular arcs are centered on the line endpoints and have a diameterequal to the
line thickness.
A third type of line cap is the projecting square cap.Here, we simply extend the line and
add butt caps that are positioned one-half ofthe line width beyond the specified
endpoints.
We can generate thick polylines that are smoothly joined at the cost of additional
processing at the segment endpoints. A miter join is accomplished by extending the
outer boundaries of each of the two linesuntil they meet. A round join is produced by
capping the connection between the two segments with a circular boundary whose
diameter is equal to the line width.
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 30
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
And a bevel join is generated by displaying the line segments with butt caps and filling in
the triangular gap where the segments meet.
We can generate thick polylines that are smoothly joined at the cost of additional
processing at the segment endpoints.
A miter join is accomplished by extending the outer boundaries of each of the two
linesuntil they meet.
A round join is produced by capping the connection between the two segments with a
circular boundary whose diameter is equal to the line width. And a bevel join is
generated by displaying the line segments with butt caps and filling in the triangular gap
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 31
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
We can generate thick polylines that are smoothly joined at the cost of additional
processing at the segment endpoints.
A miter join is accomplished by extending the outer boundaries of each of the two
linesuntil they meet.
A round join is produced by capping the connection between the two segments with a
circular boundary whose diameter is equal to the linewidth. And a bevel join is
generated by displaying the line segments with butt caps and filling in the triangular gap
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 32
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
We can generate thick polylines that are smoothly joined at the cost of additional
processing at the segment endpoints.
A miter join is accomplished by extending the outer boundaries of each of the two lines
until they meet.
A round join is produced by capping the connection between the two segments with a
circular boundary whose diameter is equal to the line width.
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 33
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
And a bevel join is generated by displaying the line segments with butt caps and filling in
the triangular gap where the segments meet.
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 34
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Lecture 12
Aliasing and introduction to Anti-Aliasing (No anti-aliasing
algorithm)
Antialiasing is a technique used in digital imaging to reduce the visual defects that occur
when high-resolution images are presented in a lower resolution. Aliasing manifests
itself as jagged or stair-stepped lines (otherwise known as jaggies) on edges and objects
that should otherwise be smooth.
Antialiasing makes these curved or slanting lines smooth again by adding a slight
discoloration to the edges of the line or object, causing the jagged edges to blur and
melt together. If the image is zoomed out a bit, the human eye can no longer notice the
slight discoloration that antialiasing creates.
Jaggies appear when an output device does not have a high enough resolution to
represent a smooth line correctly. This is also an inherent problem on a computer
monitor. The pixels that make up the screen of the monitor are all shaped in rectangles
or squares. Because lighting up only half of one of these square pixels is not possible, the
result is a jagged line.
The jagged line effect can be minimized by increasing the resolution of the monitor,
making the pixels small enough that the human eye cannot distinguish them individually.
This is not a good solution, however, because images are displayed based on their
resolution. A single image pixel may take up many monitor pixels, making it impossible
for a higher resolution monitor to mask the jagged edges. This is where antialiasing is
required.
Antialiasing removes jagged edges by adding subtle color changes around the lines,
tricking the human eye into thinking that the lines are not jagged. The slight changes in
color around the edges of an image help the line blend around curves, giving the
impression that the line is true. These color changes are made on a very small scale that
the human eye cannot detect under normal circumstances. In order to be able to see
that an image has been antialiased, it would have to be magnified.
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 35
Unit-2 B.Tech. - V Semester Computer Graphics and Multimedia
Another way to state this is that the sampling interval should be no larger than one-half
the cycle interval (called the Nyquist sampling interval). For x-interval sampling, the
Nyquist sampling interval Ax, is
Notes By: - Arvind Sharma (Head, Department of Computer Science and Engineering) Page 36