Com 422 Note Module 1
Com 422 Note Module 1
Com 422 Note Module 1
MODULE ONE
Today there are very few aspects of our lives not affected by computers. Practically
every cash or monetary transaction that takes place daily involves a computer. In many
cases, the same is true of computer graphics. Whether you see them on television, in
newspapers, in weather reports or while at the doctor’s surgery, computer images are
all around you. “A picture is worth a thousand words” is a well-known saying and
highlights the advantages and benefits of the visual presentation of our data.
Computer graphics is an art of drawing pictures on computer screens with the help of
programming. It involves computations, creation, and manipulation of data. In other
words, we can say that computer graphics is a rendering tool for the generation and
manipulation of images.
Computer graphics generally means creation, storage and manipulation of models and
images. Such models come from diverse and expanding set of fields including
physical, mathematical, artistic, biological, and even conceptual (abstract) structures.
Computer graphics are any types of images created using any kind of computer. There
is a vast amount of types of images a computer can create. Also, there are just as many
ways of creating those images. Images created by computers can be very simple, such
as lines and circles, or extremely complex such as complicated rendered animations.
Computer graphics is concerned with producing images and animations (or sequences
of images) using a computer. This includes the hardware and software systems used to
1
make these images. The task of producing photo-realistic images is an extremely
complex one, but this is a field that is in great demand because of the nearly limitless
variety of applications. The field of computer graphics has grown enormously over the
past 10–20 years, and many software systems have been developed for generating
computer graphics of various sorts. This can include systems for producing 3-
dimensional models of the scene to be drawn, the rendering software for drawing the
images, and the associated user-interface software and hardware.
The field of computer graphics dates back to the early 1960’s with Ivan Sutherland, one
of the pioneers of the field. This began with the development of the (by current
standards) very simple software for performing the necessary mathematical
transformations to produce simple line-drawings of 2-dimensional and 3-dimensional
scenes. As time went on, and the capacity and speed of computer technology improved,
successively greater degrees of realism were achievable. Today it is possible to produce
images that are practically indistinguishable from photographic images (or at least that
create a pretty convincing illusion of reality).
Today most graphicist want an Intel PC with at least 256 MB of memory and a 10 GB
hard drive. Their display should have graphics board that supports real-time texture
mapping. A flatbed scanner, color laser printer, digital video camera, DVD, and MPEG
encoder/decoder are the peripherals one wants. The environment for program
development is most likely Windows and Linux, with Direct 3D and OpenGL, but Java
3D might become more important. Programs would typically be written in C++ or Java.
What will happen in the near future, difficult to say, but high definition TV (HDTV) is
poised to take off (after years of hype). Ubiquitous, untethered, wireless computing
should become widespread, and audio and gestural input devices should replace some
of the functionality of the keyboard and mouse.
2
1.3 THE PICTURE ELEMENT: BLOCK PIXEL AND LINE
A pixel (short for picture element, using the common abbreviation “pix” for “picture”)
is one of the many tiny dots that make up the representation of a picture in
a computer memory. Each such information element is not really a dot, nor a square,
but an abstract sample.
With care, pixels in an image can be reproduced at any size without the appearance of
visible dots or squares, but in many contexts, they are reproduced as dots or squares
and can be visibly distinct when not fine enough.
A pixel is the most basic component of any computer graphics. It corresponds to the
smallest thing that can be drawn on a computer screen. Every computer graphics is
made up of a grid of pixels. When these pixels are painted onto the screen, they form an
image. This grid of pixels is called a bitmap.
A bitmap is a collection of pixels that describes an image, in human terms, a complete
picture. A bitmap can be of various bit depth and resolution. Basically, a bitmap is an
array of pixels.
In black and white, each pixel can be represented by 1 bit (0, 1), a ‘1’ if the pixel is
black, or a ‘0’ if the pixel is white. The computer opens a black and white bitmapped
image, then it starts looking for numbers that describe image information. Every time it
comes to a ‘0’ it draws a white pixel. When it comes to a ‘1’ it draws a black pixel.
3
The bits below is the Binary data describing the above image
00000000000000000011110000000000000000
00000000000000001100001100000000000000
00000000000000010000000010000000000000
00000000000000100000000001000000000000
00000000000000100010001001000000000000
00000000000001000111011100100000000000
00000000000001000010001000100000000000
00000000000001000000000000100000000000
00000000000001000000000000100000000000
00000000000001001000000100100000000000
00000000000000100100001001000000000000
00000000000000100011110001000000000000
00000000000000010000000010000000000000
00000000000000001100001100000000000000
00000000000000000011110000000000000000
00011110010000000000000000000000000000
01100010010000000000000000000000000000
11000100100000000000000000000000000000
00000100100001110001011000101100100100
00111111110010010001101000110101100100
00001001000100100111001011100101001000
00010010000101101010010101001011011010
00010010000110110111111011111101101100
00000000000000000100000010000000011000
00000000000000001100000110000000110000
00000000000000001000000100000000100000
PIXELATION
Pixelation is a process or event that occurs when an original bitmapped graphic image
lost its details when the image gets scaled-up. When you enlarge a bit mapped image,
you will get a pixelated look. For example, if you are planning to print out an image
that was originally 3 inches by 3 inches as 6 inches by 6 inches, you will get a pixelated
look.
The bitmapped graphics images/pictures below demonstrate the occurrence of
Pixelation as the original images/pictures were scaled-up or enlarged.
5
(ii) Object Oriented Graphics:
You create object oriented graphics in a drawing program. When you create objects in a
drawing program, you can still edit them after you have done something else. For
example, if you draw a circle in one place, then draw a rectangle in another place, you
can still select the circle and change its size and location. This is possible because
object oriented graphics are stored as dimensions and formulas, unlike bit mapped
graphics which are stored as individual pixels. When a drawing program opens a
6
drawing file, it will look for objects, not pixels. A drawing file may be thought of as a
series of instructions like the ones below, but in a computer language which most
normal people cannot understand.
Draw a circle at the point that is 100 pixels to the right and 140 pixels down from
•the top-left corner of the screen with the radius of 25 pixels. There are advantages as
well as disadvantages to object oriented graphics over bitmapped graphics. As already
mentioned, object oriented graphics can still be modified as separate objects after being
modified, unlike bitmapped which cannot. Second, object oriented graphic files
(drawing files) are usually much smaller in size than bitmapped graphics. Third, you
can enlarge an object oriented graphic to any size, and it will not loose detail. That is
because most object oriented graphics are resolution-independant. A disadvantage is
that they are usually harder to create, and cannot have many interesting special effects
done to them, such as bluring for example.
7
Every point you can think of, every atom in space, has its own unique place occupied
only by itself. This place might change with time (the aircraft flies from point A to
point B), but at any given instant, it has a unique location. Every point has an address,
called its coordinates, which describes its location relative to another known location.
A typical Cartesian coordinate system is defined by x and y axes. Each axis has a unit
of length or distance (such as metres or miles). The axes cross at the point where the
value of both x and y is zero; this is called the origin (0,0).
Below is an example showing the coordinates of five different points within a two-
dimensional Cartesian system with the axes conventionally labelled as x (horizontal)
and y (vertical). Each of the five points is defined by two numbers, the first of which is
its distance perpendicular to the y-axis (its x value) and the second is its distance
perpendicular to the x axis (its y value). Note that the direction from the origin is also
important, as this will determine whether the values of x and y are positive or negative.
8
When you come across a diagram such as the one above, for example a map or perhaps
a collection of data, you are likely to need to do one of two things:
Either you have a point on a chart and you need to determine its coordinates;
Or you have the coordinates and you need to work out the location of the point.
To determine the coordinates of a point, consider Point A in the diagram (marked in red
in the positive x and y quadrant, or Quadrant 1). First, measure how far it is along the x-
axis from the origin, i.e. its perpendicular distance from the y-axis. This provides your x
coordinate, which has a value of 2. Next, measure how far the point is along the y-axis,
in a perpendicular direction from the x axis. This gives your y coordinate, which has a
value of 3.
9
FINDING THE LOCATION OF A POINT FROM ITS COORDINATES
In the second instance, you might be given the coordinates (−5.5, −1.5) and need to find
the position of that point on the graph or map. In this case, you first travel along the
negative x-axis until you reach the value −5.5. Then from that position, move in a
perpendicular direction −1.5 units, i.e. 1.5 units parallel to the negative y axis, and mark
your point. Alternatively you can draw a vertical line at x=−5.5 and horizontal line at
y=−1.5.
Where the two lines intersect is the point (−5.5, −1.5), which is shown on the diagram
as Point B, in Quadrant 3.
The first two coordinates, x and y, are determined in the same way as in a two-
dimensional system. These describe the position of the point if it were projected
downwards (or upwards) at right angles onto the x-y plane. The three-dimensional
system also has a z-axis, which lies perpendicular to the x-y plane. The origin of a
three-dimensional Cartesian system is the point at which x, y and z are all equal to zero (0,
0, 0).
It is unlikely that you will need to use 3D Cartesian coordinate systems in everyday life
unless you are involved with engineering, physics, architecture or other applications of
computer-aided design.
10
11
1.6 LINE GENERATION ALGORITHM: THE INCREMENTAL METHODS
A line connects two points. It is a basic element in graphics. To draw a line, you need
two points between which you can draw a line. In the line generation algorithms, we
refer to one point of line as x0, y0 and the second point of line as x1, y1.
Any procedure that identifies those portions of a picture that are either inside or
outside of a specified region or space is known as clipping.
Point Clipping
Clipping a point from a given window is very easy. Consider the following figure,
where the rectangle indicates the window.
Point clipping tells us whether the given point X, Y is within the given window or not,
and decides whether we will use the minimum and maximum coordinates of the
window.
The X-coordinate of the given point is inside the window, if X lies in between
Wx1 ≤ X ≤ Wx2. Same way, Y coordinate of the given point is inside the window, if Y
lies in between Wy1 ≤ Y ≤ Wy2.
13
Line Clipping
The concept of line clipping is same as point clipping. In line clipping, we will cut the
portion of line which is outside of window and keep only the portion that is inside the
window.
Generally, this method speeds up the processing of line segments, by performing initial
tests that reduce the number of intersections that must be calculated. Every line
endpoint in a picture is assigned a 4-digit binary code, called a region code that
identifies the location of the point relative to the boundaries of the clipping rectangle.
This algorithm uses the clipping window as shown in the following figure. The
minimum coordinate for the clipping region is (XWmin, YWmin) and the maximum
coordinate for the clipping region is (XWmax, YWmax).
14
We will use 4-bits to divide the entire region. These 4 bits represent the Top, Bottom,
Right, and Left of the region as shown in the following figure. Here,
the TOP and LEFT bit is set to 1 because it is the TOP-LEFT corner.
Line can be completely inside the window. This line should be accepted.
Line can be completely outside of the window. This line will be completely
removed from the region.
15
Line can be partially inside the window. We will find intersection point and
draw only that portion of line that is inside region.
Algorithm
Step 2 − If both endpoints have a region code 0000 then accept this line.
Step 3 − Else, perform the logical AND operation for both region codes.
Step 3.2.1 − Choose an endpoint of the line that is outside the window.
Step 3.2.2 − Find the intersection point at the window boundary base on region code.
Step 3.2.3 − Replace endpoint with the intersection point and update the region code.
Step 3.2.4 − Repeat step 2 until we find a clipped line either trivially accepted or
trivially rejected.
First the polygon is clipped against the left edge of the polygon window to get new
vertices of the polygon. These new vertices are used to clip the polygon against right
edge, top edge, bottom edge, of the clipping window as shown in the following figures.
16
While processing an edge of a polygon with clipping window, an intersection point is
found if edge is not completely inside clipping window and then a partial edge from the
intersection point to the outside edge is clipped. The following figures show left, right,
top and bottom edge clippings.
17
Text Clipping
Various techniques are used to provide text clipping in a computer graphics. It depends
on the methods used to generate characters and the requirements of a particular
application. There are three methods for text clipping which are listed below.
Text clipping
In all or none string clipping method, either we keep the entire string or we reject entire
string based on the clipping window. As shown in the above figure, STRING2 is
entirely inside the clipping window so we keep it and STRING1 being only partially
inside the window, we reject.
The following figure shows all or none character clipping.
This clipping method is based on characters rather than entire string. In this method if
the string is entirely inside the clipping window, then we keep it. If it is partially
outside the window, then
18
You reject only the portion of the string being outside
If the character is on the boundary of the clipping window, then we discard that
entire character and keep the rest string.
The following figure shows text clipping.
GEOMETRIC TRANSFORMATION
In many cases a complex picture can always be treated as a combination of
straight line, circles, ellipse etc., and if we are able to generate these basic figures, we
can also generate combinations of them. Once we have drawn these pictures, the need
arises to transform these pictures.
We are not essentially modifying the pictures, but a picture in the center of the screen
needs to be shifted to the top left hand corner, say, or a picture needs to be increased
to twice its size or a picture is to be turned through 900 . In all these cases, it is
possible to view the new picture as really a new one and use algorithms to
draw them, but a better method is, given their present form, try to get their new
counterparts by operating on the existing data. This concept is called transformation.
19
Transformation means changing some graphics into something else by applying rules.
We can have various types of transformations such as translation, scaling up or down,
rotation, shearing, etc. When a transformation takes place on a 2D plane, it is called 2D
transformation.
Homogenous Coordinates
To shorten this process, we have to use 3×3 transformation matrix instead of 2×2
transformation matrix. To convert a 2×2 matrix to 3×3 matrix, we have to add an extra
dummy coordinate W.
In this way, we can represent the point by 3 numbers instead of 2 numbers, which is
called Homogenous Coordinate system. In this system, we can represent all the
transformation equations in matrix multiplication. Any Cartesian point P X, Y can be
converted to homogenous coordinates by P’ (Xh, Yh, h).
Translation
A translation moves an object to a different position on the screen. You can translate a
point in 2D by adding translation coordinate (t x, ty) to the original coordinate X, Y to
get the new coordinate X′, Y′
20
From the above figure, you can write that:
X’ = X + tx
Y’ = Y + ty
The pair (tx, ty) is called the translation vector or shift vector. The above equations can
also be represented using the column vectors.
Rotation
In rotation, we rotate the object at particular angle θ theta from its origin. From the
following figure, we can see that the point P X, Y is located at angle φ from the
horizontal X coordinate with distance r from the origin.
Let us suppose you want to rotate it at the angle θ. After rotating it to a new location,
you will get a new point P’ X′, Y′.
21
Using standard trigonometric the original coordinate of point P X, Y can be
represented as
22
The rotation angle can be positive and negative.
For positive rotation angle, we can use the above rotation matrix. However, for
negative angle rotation, the matrix will change as shown below
Scaling
To change the size of an object, scaling transformation is used. In the scaling process,
you either expand or compress the dimensions of the object. Scaling can be achieved
by multiplying the original coordinates of the object with the scaling factor to get the
desired result.
Let us assume that the original coordinates are X, Y the scaling factors are (SX, SY),
and the produced coordinates are X′,Y′. This can be mathematically represented as
shown below:
X' = X . SX and Y' = Y . SY
The scaling factor SX, SY scales the object in X and Y direction respectively. The above
equations can also be represented in matrix form as below:
OR
P’ = P . S
23
Where S is the scaling matrix. The scaling process is shown in the following figure.
If we provide values less than 1 to the scaling factor S, then we can reduce the size of
the object. If we provide values greater than 1, then we can increase the size of the
object.
Reflection
Reflection is the mirror image of original object. In other words, we can say that it is a
rotation operation with 180°. In reflection transformation, the size of the object does
not change. The following figures show reflections with respect to X and Y axes, and
about the origin respectively.
24
Shear
A transformation that slants the shape of an object is called the shear transformation.
There are two shear transformations X-Shear and Y-Shear. One shifts X coordinates
values and other shifts Y coordinate values. However; in both the cases only one
coordinate changes its coordinates and other preserves its values. Shearing is also
termed as Skewing.
X-Shear
The X-Shear preserves the Y coordinate and changes are made to X coordinates, which
causes the vertical lines to tilt right or left as shown in below figure.
25
Y-Shear
The Y-Shear preserves the X coordinates and changes the Y coordinates which causes
the horizontal lines to transform into lines which slopes up or down as shown in the
following figure.
26
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: