Com 422 Note Module 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 26

COM 422: COMPUTER GRAPHICS AND ANIMATION

MODULE ONE

1.1 THE BASIC CONCEPT OF COMPUTER GRAPHICS

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 is a consciously managed and documented technology directed


toward communicating information accurately and descriptively.

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.

1.2 THE ORIGIN OF COMPUTER GRAPHICS

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

1.4 THE CLASSIFICATIONS OF COMPUTER GRAPHICS


There are two kinds of computer graphics, viz:
(i) Bit-Mapped
(ii) Object-Oriented.

(i) Bitmapped Graphics:


Bit mapped graphics are graphics that are stored in the form of a bitmap. They are a
sequence of bits that get drawn onto the screen. You create bit mapped graphics using a
4
painting program. You cannot edit the components of a bitmapped image once you
drew them. For example, if you use your painting program to draw a line, you will not
be able to edit that line as a separate object. It becomes part of the image. From now
on, that line is a pattern of pixels. Bit mapped graphics are usually easier to work with.
Bit mapped graphics tend to create larger files than object oriented graphics.

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.

Original object oriented image and same image scaled up

1.5 THE CARTESIAN COORDINATE SYSTEMS


A point is a single location anywhere. It could be on a two-dimensional surface
or plane (for example a dot on a sheet of paper) or in three-dimensional space (such as
the position of an aircraft in flight at a given instant in time).

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.

On a two-dimensional plane, a point can be described by a pair of coordinates, within


a coordinate system, such as (x, y). In a three-dimensional space, a point can be
described by three coordinates, such has (x, y, z).

1.5.1 Two-Dimensional (2D) Cartesian Coordinates

A Cartesian coordinate system on a two-dimensional plane is defined by two


perpendicular axes. In other words, two lines drawn at right angles to each other on a
flat surface (for example a flat sheet of paper or the surface of a football field). This is
also called or referred to as a rectangular or orthogonal coordinate system, because the
reference axes are perpendicular.

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.

DETERMINING THE COORDINATES OF A 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.

The coordinates of Point A are therefore (2, 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.

1.5.2 Three-Dimensional (3D) Cartesian Coordinates

In a three-dimensional Cartesian coordinate system, the position of the point in space


needs to be described by three coordinates, typically (x, y, z). In a two-dimensional
system, the point is somewhere on a flat plane. However, a plane has only a length and
a breadth, whereas a three-dimensional space must also have a height or a depth. In this
case you can imagine the point as being somewhere within a rectangular box.

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.

In mathematical terms, a point P in a typical three-dimensional Cartesian coordinate


system has shown in the diagram below. 

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.

The DDA Algorithm


Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm
which is explained step by step below.
Step 1: Get the input of two end points (x0, y0) and (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.
if(absolute(dx) > absolute(dy))
Steps = absolute(dx);
else
Steps = absolute(dy);
Step 4: Calculate the increment in x coordinate and y coordinate.
Xincrement = dx / (float) steps;
Yincrement = dy / (float) steps;
Step 5: Put the pixel by successfully incrementing x and y coordinates accordingly and
complete the drawing of the line.
for (int v=0; v < Steps; v++)
{
x = x + Xincrement;
y = y + Yincrement;
12
putpixel(Round(x), Round(y));
}
The steps above can also be put together as:

1.7 THE TECHNIQUES OF CLIPPING

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.

The primary use of clipping in computer graphics is to remove objects/points, lines, or


line segments, text or string or character that are outside the viewing pane. The
viewing transformation is insensitive to the position of points relative to the viewing
volume, especially those points behind the viewer and it is necessary to remove these
points before generating the view.

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.

Cohen-Sutherland Line Clippings

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.

There are 3 possibilities for the line:

 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 1 − Assign a region code for each endpoints.

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.1 − If the result is not 0000, then reject the line.

Step 3.2 − Else you need clipping.

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.

Step 4 − Repeat step 1 for other lines.

Polygon Clipping:  Sutherland Hodgman Algorithm

A polygon can also be clipped by specifying the clipping window. Sutherland


Hodgeman polygon clipping algorithm is used for polygon clipping. In this algorithm,
all the vertices of the polygon are clipped against each edge of the clipping window.

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.

 All or none string clipping

 All or none character clipping

 Text clipping

The following figure shows all or none string 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.

This clipping method is based


on characters rather than the
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

 You reject only the portion of string being outside.


 If the character is on the boundary of the clipping window, then we discard only
that portion of character that is outside of the clipping window.

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.

Transformations play an important role in computer graphics to reposition the graphics


on the screen and change their size or orientation.

Homogenous Coordinates

To perform a sequence of transformation such as translation followed by rotation and


scaling, we need to follow a sequential process −

 Translate the coordinates,

 Rotate the translated coordinates, and then

 Scale the rotated coordinates to complete the composite transformation.

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.

We can write it as:


P’ = P + T

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

Representing the above equation in matrix form,

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy