Chapter One Application of Computer Graphics: Computer-Aided Design (CAD)
Chapter One Application of Computer Graphics: Computer-Aided Design (CAD)
Chapter One Application of Computer Graphics: Computer-Aided Design (CAD)
Chapter one
Application of Computer Graphics
Computer graphics refers to the creation, storage and manipulation of pictures and drawings using
a digital computer. With developments in computing technology interactive computer graphics
has become an effective tool for the presentation of information in such diverse fields as science,
engineering, medicine, business, industry, government, art, entertainment, advertising, education,
and training. There is virtually no field in which graphical displays cannot be used to some
advantage and that is the basic reason why application of computer graphics is so widespread
It is a fact that one picture is worth a thousand words. Therefore, interfaces empowered with
graphics enhance the communication between the computer and its users. Representation of a
huge set of numbers in the form of a graph or a picture helps in a better understanding and
interpretation of the characteristics or pattern of the data contained in the set of numbers. Graphic
displays also improve understanding of complex systems, and visualization of two-dimensional
(2D), three-dimensional (3D) objects: A major application of computer graphics are mentioned
below.
0
Computer Graphics Lecture note
Graphical Hardware
Graphic hardware can be divided into two major categories of devices:
(1) Input devices with which the user interacts to generate necessary instruction or data for creating
graphics
(2) Display systems where the graphics are rendered on the monitor screen.
Input Devices
Various devices are available for data input on graphics workstations. Most systems have a
keyboard and one or more additional devices specially designed for interactive input. These
include a mouse, trackball, spaceball, joystick, digitizers, dials, and button boxes. Some other
input devices used in particular applications are data gloves, touch panels, image scanners, and
voice systems.
Keyboards
An alphanumeric keyboard on a graphics system is used primarily as a device for entering text
strings. The keyboard is an efficient device for inputting such nongraphic data as picture labels
associated with a graphics display. Keyboards can also be provided with features to facilitate
entry of screen coordinates, menu selections, or graphics functions.
Cursor-control keys and function keys are common features on general purpose keyboards.
Function keys allow users to enter frequently used operations in a single keystroke, and cursor-
control keys can be used to select displayed objects or coordinate positions by positioning the
screen cursor. Other types of cursor-positioning devices, such as a trackball or joystick, are
included on some keyboards. Additionally, a numeric keypad is, often included on the keyboard
for fast entry of numeric data.
Mouse
A mouse is small hand-held box used to position the screen cursor. Wheels or rollers on the
bottom of the mouse can be used to record the amount and direction of movement. Another
method for detecting mouse motion is with an optical sensor. For these systems, the mouse is
moved over a special mouse pad that has a grid of horizontal and vertical lines. The optical sensor
detects movement across the lines in the grid.
Trackball and Spaceball
As the name implies, a trackball is a ball that can be rotated with the fingers or palm of the hand
to produce screen-cursor movement. Potentiometers, attached to the ball, measure the amount and
direction of rotation. Trackballs are often mounted on keyboards.
While a trackball is a two-dimensional positioning device, a spaceball provides six degrees of
freedom. Unlike the trackball, a spaceball does not actually move. Strain gauges measure the
amount of pressure applied to the spaceball to provide input for spatial positioning and orientation
1
Computer Graphics Lecture note
as the ball is pushed or pulled in various directions. Spaceballs are used for three-dimensional
positioning and selection operations in virtual-reality systems, modeling, animation, CAD, and
other applications.
Joysticks
A joystick consists of a small, vertical lever (called the stick) mounted on a base that is used to
steer the screen cursor around. Most joysticks select screen positions with actual stick movement;
others respond to pressure the stick. Some joysticks are mounted on a keyboard; others function
as stand-alone units.
The distance that the stick is moved in any direction from its center position corresponds to
screen-cursor movement in that direction. Potentiometers mounted at the base of the joystick
measure the amount of movement, and springs return the stick to the center position when it is
released. One or more buttons can be programmed to act as input switches to signal certain
actions once a screen position has been selected.
Data Glove
Data glove uses to grasp a "virtual" object. The glove is constructed with a series of sensors that
detect hand and finger motions. Electromagnetic coupling between transmitting antennas and
receiving antennas is used to provide information about the position and orientation of the hand.
The transmitting and receiving antennas can each be structured as a set of three mutually
perpendicular coils, forming a three-dimensional Cartesian coordinate system. Input from the
glove can be used to position or manipulate objects in a virtual scene. A two-dimensional
projection of the scene can be viewed on a video monitor, or a three-dimensional projection can
be viewed with a headset.
Digitizers
A common device for drawing, painting, or interactively selecting coordinate positions on an
object is a digitizer. These devices can be used to input coordinate values in either a two-
dimensional or a three-dimensional space. Typically, a digitizer is used to scan over a drawing or
object and to input a set of discrete coordinate positions, which can be joined with straight-line
segments to approximate the curve or surface shapes.
Image Scanners
Drawings, graphs, color and black-and-white photos, or text can be stored for computer
processing with an image scanner by passing an optical scanning mechanism over the information
to be stored.
Touch Panels
As the name implies, touch panels allow displayed objects or screen positions to be selected with
the touch of a finger.
Light Pens
Pencil-shaped devices are used to select screen positions by detecting the light coming from
points on the CRT screen.
Voice Systems
2
Computer Graphics Lecture note
Speech recognizers are used in some graphics workstations as input devices to accept voice
commands The voice-system input can be used to initiate graphics operations or to enter data.
These systems operate by matching an input against a predefined dictionary of words and phrases
Display Devices
The display medium for computer graphic-generated pictures has become widely diversified.
Typical examples are CRT-based display, Liquid Crystal, LED and Plasma based display. CRT
display is by far the most common display technology and most of the fundamental display
concepts are embodied in CRT technology. This unit focuses on CRT-based display technologies
explaining the related concepts followed by illustrations of structural and functional components
and working principles of each.
The most prominent part in a personal computer is the display system that makes graphic display
possible. The display system may be attached to a PC to display character, picture and video
outputs. Some of the common types of display systems available in the market are:
1. Raster Scan Displays
2. Random Scan Displays
3. Flat Panel Displays
The display systems are often referred to as Video Monitor or Video Display Unit (VDU). The
most common video monitor that normally comes with a PC is the Raster Scan type. However,
every display system has three basic parts – the display adapter that creates and holds the image
information, the monitor which displays that information and the cable that carries the image data
between the display adapter and the monitor. Before we discuss the major display systems let us
first know about some basic terms.
Pixel
A pixel may be defined as the smallest size object or colour spot that can be displayed and
addressed on a monitor. Any image that is displayed on the monitor is made up of thousands of
such small pixels (also known as picture elements). The closely-spaced pixels divide the image
area into a compact and uniform two-dimensional grid of pixel lines and columns. Each pixel has
a particular colour and brightness value. Though the size of a pixel depends mostly on the size of
3
Computer Graphics Lecture note
the electron beam within the CRT, they are too fine and close to each other to be perceptible by
the human eye. The finer the pixels the more the number of pixels displayable on a monitor
screen. However, it should be remembered that the number of pixels in an image is fixed by the
program that creates the image and not by the hardware that displays it.
Resolution
There are two distinctly different terms, which are often confused. One is Image Resolution and
the other is Screen Resolution. Strictly speaking image resolution refers to the pixel spacing, i.e.,
the distance from one pixel to the next pixel. A typical PC monitor displays screen images with a
resolution somewhere between 25 pixels per inch and 80 pixels per inch (ppi). In other words,
resolution of an image refers to the total number of pixels along the entire height and width of the
image. For example, a full-screen image with resolution 800 × 600 means that there are 800
columns of pixels, each column comprising 600 pixels, i.e., a total of 800 × 600 = 4,80,000 pixels
in the image area.
The internal surface of the monitor screen is coated with red, green and blue phosphor material
that glows when struck by a stream of electrons. This coated material is arranged into an array of
millions of tiny cells–red, green and blue, usually called dots. The dot pitch is the distance
between adjacent sets (triads) of red, green and blue dots.
Pixel therefore, is the smallest element of a displayed image, and dots (red, green and blue) are
the smallest elements of a display surface (monitor screen). The dot pitch is the measure of screen
resolution. The smaller the dot pitch, the higher the resolution, sharpness and detail of the image
displayed.
In order to use different resolutions on a monitor, the monitor must support automatic changing of
resolution modes. Originally, monitors were fixed at a particular resolution, but for most monitors
today display resolution can be changed using software control. This lets you use higher or lower
resolution depending on the need of your application. A higher resolution display allows you to
see more information on your screen at a time and is particularly useful for operating systems
such as Windows. However, the resolution of an image you see is a function of what the video
card outputs and what the monitor is capable of displaying. To see a high resolution image such
as 1280 × 1024 you require both a video card capable of producing an image this large and a
monitor capable of displaying it.
Cathode-Ray Tubes (CRT)
The primary output device in a graphical system is the video monitor. The main element of a
video monitor is the Cathode Ray Tube (CRT), shown in the following illustration.
The operation of CRT is very simple:
1. The electron gun emits a beam of electrons (cathode rays).
2. The electron beam passes through focusing and deflection systems that direct it towards
specified positions on the phosphor-coated screen.
3. When the beam hits the screen, the phosphor emits a small spot of light at each position
contacted by the electron beam.
4
Computer Graphics Lecture note
4. It redraws the picture by directing the electron beam back over the same screen points
quickly.
The light emitted by phosphor fades very rapidly, so it needs to redraw the picture repeatedly.
There are 2 kinds of redrawing mechanisms: Raster-Scan and Random-Scan
RASTER SCAN DISPLAY
This type of display basically employs a Cathode Ray Tube (CRT) or LCD Panel for display. The
CRT works just like the picture tube of a television set. Its viewing surface is coated with a layer
of arrayed phosphor dots. At the back of the CRT is a set of electron guns (cathodes) which
produce a controlled stream of electrons (electron beam). The phosphor material emits light when
struck by these high-energy electrons. The frequency and intensity of the light emitted depends on
5
Computer Graphics Lecture note
the type of phosphor material used and energy of the electrons. To produce a picture on the
screen, these directed electron beams start at the top of the screen and scan rapidly from left to
right along the row of phosphor dots.
They return to the left-most position one line down and scan again, and repeat this to cover the
entire screen. The return of the beam to the leftmost position one line down is called horizontal
retrace during which the electron flow is shut off. In performing this scanning or sweeping type
motion, the electron guns are controlled by the video data stream that comes into the monitor
from the video card. This varies the intensity of the electron beam at each position on the screen.
The instantaneous control of the intensity of the electron beam at each dot is what controls the
colour and brightness of each pixel on the screen. All this happens very quickly, and the entire
screen is drawn in a fraction (say, 1/60th) of a second. An image in raster scan display is basically
composed of a set of dots and lines; lines are displayed by making those dots bright (with the
desired colour) which lie as close as possible to the shortest path between the endpoints of a line.
In order to avoid flicker, the screen image must be redrawn fast enough so that the eye cannot tell
that refresh is going on. The refresh rate is the number of times per second that the screen is
refreshed. It is measured in Hertz (Hz), the unit of frequency. The refresh rates are somewhat
standardized.
Some monitors use a technique called interlacing to cheat a bit and allow them to display at a
higher resolution than is otherwise possible. Instead of refreshing every line of the screen, when
in an interlaced mode, the electron guns sweep alternate lines on each pass. In the first pass, odd-
numbered lines are refreshed, and in the second pass, even numbered lines are refreshed. This
allows the refresh rate to be doubled because only half the screen is redrawn at a time. The usual
6
Computer Graphics Lecture note
refresh rate for interlaced operation is 87 Hz, which corresponds to 43.5 Hz of ‘real’ refresh in
half-screen interlacing.
In the Figure above the odd-numbered lines represent scanning one half of the screen and the
even-numbered lines represent scanning of the other half. There are two separate sets of
horizontal and vertical retrace.
As we can observe in the figure below, The electron beam is swept across the screen one
row at a time from top to bottom. As it moves across each row, the beam intensity is turned on
and off to create a pattern of illuminated spots. This scanning process is called refreshing. Each
complete scanning of a screen is normally called a frame.
The refreshing rate, called the frame rate, is normally 60 to 80 frames per second, or described as
60 Hz to 80 Hz.
Picture definition is stored in a memory area called the frame buffer. This frame buffer
stores the intensity values for all the screen points. Each screen point is called a pixel (picture
element).
On black and white systems, the frame buffer storing the values of the pixels is called a bitmap.
Each entry in the bitmap is a 1 -bit data which determine the on (1) and off (0) of the intensity of
the pixel.
7
Computer Graphics Lecture note
On color systems, the frame buffer storing the values of the pixels is called a pixmap
(Though nowadays many graphics libraries name it as bitmap too). Each entry in the pixmap
occupies a number of bits to represent the color of the pixel. For a true color display, the number
of bits for each entry is 24 (8 bits per red/green/blue channel, each channel 28=256 levels of
intensity value, ie. 256 voltage settings for each of the red/green/blue electron guns).
Random-Scan (Vector Display)
The CRT's electron beam is directed only to the parts of the screen where a picture is to be
drawn. The picture definition is stored as a set of line-drawing commands in a refresh display file
or a refresh buffer in memory.
Random-scan generally have higher resolution than raster systems and can produce
smooth line drawings, however it cannot display realistic shaded scenes.
Display Controller
For a raster display device reads the frame buffer and generates the control signals for the screen,
ie. the signals for horizontal scanning and vertical scanning. Most display controllers include a
color map (or video look-up table). The major function of a color map is to provide a mapping
between the input pixel value to the output color.
Anti-Aliasing
On dealing with integer pixel positions, jagged or stair step appearances happen very usually.
This distortion of information due to under sampling is called aliasing. A number of ant aliasing
methods have been developed to compensate this problem.
One way is to display objects at higher resolution. However there is a limit to how big we can
make the frame buffer and still maintaining acceptable refresh rate.
GRAPHICS SOFTWARE
There are two general classifications for graphics software: general programming packages and
special-purpose applications packages. A general graphics programming package provides an
extensive set of graphics functions that can be used in a high-level programming language, such
as C or FORTRAN. An example of a general graphics programming package is the GL (Graphics
Library) system on Silicon Graphics equipment. Basic functions in a general package include
those for generating picture components (straight lines, polygons, circles, and other figures),
setting color and intensity values, selecting views, and applying transformations. By contrast,
application graphics packages are designed for nonprogrammers, so that users can generate
8
Computer Graphics Lecture note
displays without worrying about how graphics operations work. The interface to the graphics
routines in such packages allows users to communicate with the programs in their own terms.
Examples of such applications packages are the artist's painting programs and various business,
medical, and CAD systems.
Coordinate Representations
With few exceptions, general graphics packages are designed to be used with Cartesian
coordinate specifications. If coordinate values for a picture are specified in some other reference
frame (spherical, hyperbolic, etc.), they must be converted to Cartesian coordinates before they
can be input to the graphics package.
Special-purpose packages may allow use of other coordinate frames that are appropriate to the
application. In general; several different Cartesian reference frames are used to construct and
display a scene. We can construct the shape of individual objects, such as trees or furniture, in a
scene within separate coordinate reference frames called modeling coordinates, or sometimes
local coordinates or master coordinates. Once individual object shapes have been specified, we
can place the objects in to appropriate positions within the scene using a reference frame called
world coordinates. Finally, the world-coordinate description of the scene is transformed to one
or more output-device reference frames for display. These display coordinate systems are referred
to as device coordinates. Or screen coordinates in the case of a video monitor. Modeling and
world coordinate definitions allow us to set any convenient floating-point or integer dimensions
without being hampered by the constraints of a particular output device. For some scenes, we
might want to specify object dimensions in fractions of a foot, while for other applications we
might want to use millimeters, kilometers, or light-years.
9
Computer Graphics Lecture note
We can change the size, position, or orientation of an object within a scene using
geometric transformations. Similar modeling transformations are used to construct a scene using
object descriptions given in modeling coordinates.
Given the primitive and attribute definition of a picture in world coordinates, a graphics package
projects a selected view of the picture on an output device. Viewing transformations are used to
specify the view that is to be presented and the portion of the output display area that is to be
used.
Pictures can be subdivided into component parts, called structures or segments or objects,
depending on the software package in use. Each structure defines one logical unit of the picture.
A scene with several objects could reference each individual object in a-separate named structure.
Routines for processing structures carry out operations such as the creation, modification, and
transformation of structure.
Interactive graphics applications use various kinds of input devices, such as a mouse, a
tablet, or a joystick. Input functions are used to control and process the data flow from these
interactive devices
Software standards
The primary goal of standardized graphics software is portability. When packages are designed
with standard graphics functions, software can he moved easily from one hardware system to
another and used in different implementations and applications. Without standards, programs
designed for one hardware system often cannot be transferred to another system without extensive
rewriting of the programs.
International and national standards planning organizations in many countries have
cooperated in an effort to develop a generally accepted standard for computer graphics. After
considerable effort, this work on standards led to the development of the Graphical Kernel
System (GKS).This system was adopted as the first graphics software standard by the
International Standards Organization (ISO) and by various; national standards organizations,
including the American National Standards Institute (ANSI).Although GKS was originally
designed as a two-dimensional graphics package, a three-dimensional GKS extension was
subsequently developed. The second software standard to be developed and a p proved by the
standards organizations was PHIGS (Programmer's Hierarchical Interactive Graphics
standard), which is an extension of GKS .Increased capabilities for object modeling, color
specifications, surface rendering, and picture manipulations are provided In PHIGS.
Subsequently, an extension of PHIGS, called PHIGS+, was developed to provide three-
dimensional surface-shading capabilities not available in PHIGS.
Standard graphics Functions are defined as a set of Specifications that is Independent of
any programming language. A language binding is then defined for a particular high-level
programming language. This binding gives the syntax for accessing the various standard graphics
functions from this language.
10
Computer Graphics Lecture note
Chapter Two
Simple Drawing Algorithms
The major objective of computer graphics is to model graphic objects in a scene. Such
objects comprise entity primitives like point, line, circle, ellipse and curves. For displaying
these entities on a raster display the representative sets of pixels of the appropriate
intensity or colour must be identified. There are standard scan conversion algorithms to
calculate first the position coordinates of the representative pixels of each entity primitive
from basic input data and then store pixel-wise intensity information into the graphics
memory. This unit discusses the different approaches and issues for implementing line,
circle and ellipse in digital space.
11
Computer Graphics Lecture note
the adjacent pixels are so closely spaced that the approximated line-pixels lie very close to
the actual line path and hence the plotted lines appear to be much smoother — almost like
straight lines drawn on paper. In a low resolution system, the same approximation
technique causes lines to be displayed with a ‘stairstep appearance’ – not smooth (see Fig.
below (a)).
12
Computer Graphics Lecture note
DDA Algorithm
Assume that a line is to be rasterized between given endpoints (xstart, ystart) and (xend, yend).
Now let us consider the equation of the line as
y = mx + c
where m represents the slope of the line and c is the y intercept. This slope can be expressed as
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) and (X1, Y1).
Step 2: Calculate the difference between two end points.
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.
13
Computer Graphics Lecture note
Step 5: Put the pixel by successfully incrementing x and y coordinates accordingly and complete
the drawing of the line.
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.
14
Computer Graphics Lecture note
At sample position xk+1, the vertical separations from the mathematical line are labeled as dupper
and dlower.
From the above illustration, the y coordinate on the mathematical line at Xk+1 is:
Y = (Xk + 1) + b
So, dupper and dlower are given as follows:
And
15
Computer Graphics Lecture note
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.
Let us substitute m with dy/dx where dx and dy are the differences between the endpoints.
So, a decision parameter Pk for the kth step along a line is given by:
The sign of the decision parameter Pk is the same as that of dlower – dupper If Pk is negative, then
choose the lower pixel, otherwise choose the upper pixel. Remember, the coordinate changes
occur along the x axis in unit steps, so you can do everything with integer calculations. At step
k+1, the decision parameter is given as:
Then
16
Computer Graphics Lecture note
Step 3: Calculate the constants dx, dy, 2dy, and (2dy – 2dx) and get the first value for the
decision parameter as:
0=2 y– x
Step 4: At each Xk along the line, starting at k = 0, perform the following test:
If Pk < 0, the next point to plot is (Xk+1, Yk) and
PK+1 = k + 2dy otherwise,
Pk+1 = k + 2 y − 2 x
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 Pk will be very
similar, just the X and Y in the equation gets interchanged.
Mid-Point Algorithm
Mid-point algorithm is a modified Bresenham . Assume that you have already put the point P at
(x, y) coordinate and the slope of the line is 0 ≤ k ≤ 1 as shown in the following illustration.
Now you need to decide whether to put the next point at E or N. This can be chosen by
identifying the intersection point Q closest to the point N or E. If the intersection point Q is
closest to the point N then N is considered as the next point; otherwise E.
17
Computer Graphics Lecture note
CIRCLE-GENERATING ALGORITHMS
Drawing a circle on the screen is a little complex than drawing a line. There are two popular
algorithms for generating a circle: Bresenham’s Algorithm and Midpoint Circle Algorithm. These
algorithms are based on the idea of determining the subsequent points required to draw the circle.
Properties of Circles
A circle is defined as the set of points that are all at a given distance r from a center position
(xc,yc). This distance relationship is expressed by the Pythagorean theorem in Cartesian
coordinates as
We could use this equation to calculate the position of points on a circle circumference by
stepping along the x axis in unit steps from x-r to x+r and calculating the corresponding y values
at each position as
18
Computer Graphics Lecture note
Bresenham’s Algorithm
We cannot display a continuous arc on the raster display. Instead, we have to choose the nearest
pixel position to complete the arc.
From the following illustration, you can see that we have put the pixel at (X, Y) location and now
need to decide where to put the next pixel: at N (X+1, Y) or at S (X+1, Y-1).
19
Computer Graphics Lecture note
Step 2: Calculate the initial value of decision parameter as P0 = 5/4 – r (See the following
description for simplification of this equation.)
20
Computer Graphics Lecture note
21
Computer Graphics Lecture note
If the distances to the two foci from any point P = ( x , y) on the ellipse are labeled dl and d2, then
the general equation of an ellipse can be stated as
d1+ d2 = constant
Expressing distances d1 and d2 in terms of the focal coordinates F1 = (x1, y2) and F2= (x1, y2), we
have
22
Computer Graphics Lecture note
By squaring this equation, isolating the remaining radical, and then squaring
again, we can rewrite the general ellipse equation in the form
Ax2+ By2+ Cxy + Dx + Ey + F = 0
where the coefficients A, B, C, D, E , and F are evaluated in terms of the focal coordinates and the
dimensions of the major and minor axes of the ellipse. The major axis is the straight line segment
extending from one side of the ellipse to the other through the foci. The minor axis spans the
shorter dimension of the ellipse, bisecting the major axis at the halfway position (ellipse center)
between the two foci.
Chapter 3
Transformation
The graphics packages range from the simple Windows Paint to the specialized AutoCAD and
ANSYS. They all have the facility to change the shape or size or position or orientation of the
displayed objects. Animations are produced by resizing an object or moving the object or camera
along the animation path. All these concerns operate upon the object geometry by applying
various geometric transformations like translation, rotation, and scaling. Each of these
transformations is represented by specific transformation matrices, the nature and origin of which
are demonstrated in this unit. The 2D point object is considered as representative of any graphic
object.
In this course we will follow column matrix convention. As all graphic objects are built with
finite no. of points each such object can be uniquely represented by a optimum no. of definition
points lying on the object. Though there may be thousands of different adjacent points on a line
between its two end points, this particular line segment can be uniquely expressed by the end
1 3
points only. For example in column matrix format, may represent one and only one line
2 4
between points (1, 2) and (3, 4).
23
Computer Graphics Lecture note
A closer look at the line in the figure above it will reveal that it is basically a series of adjacent
points, maintaining the straight line connectivity between the definition points (1, 2) & (3, 4).
Similarly the arc segment ‘C’ is uniquely represented by 3 points (1, 1) – (5, 2) – (6, 4) in
1 5 6
column-matrix format
1 2 4
A triangle having vertices at (1, 1, 1), (3, 5, 5) and (5, 4, 6) in 3D space (Figure 33) can be
1 3 5
represented uniquely by 1 5 4
1 5 6
A 5 × 3 2D rectangle having its lower left vertex at (1, 1) in Figure 3.2 can be represented by
24
Computer Graphics Lecture note
The rectangular parallelopiped ABCDEFGH in 3D space (Figure 5.3) may be defined by the
matrix
TRANSLATION
Let us think of a point P on a 2D plane. Assume that the current position or location of P is
depicted by its coordinate (x, y) in a reference frame.
Now if we force P to move x distance horizontally and at the same time y distance vertically
then the changed location of P becomes (x +∆x, y+∆y). In the terms of object transformation we
can say that the original point object P(x, y) has been translated to become P´ (x´ y´) and amount
of translation applied is the
25
Computer Graphics Lecture note
In general, the above equation (1) may be expressed as [X´] = [X] + [TT], where [X´] is the
transformed object matrix, [X] is the original object matrix and [TT] is the transformation
(translation) matrix.
Consider the line (shown in Figure 3.5) with end points A (0,8) and B (9,12). If we have to move
this line AB to A´B´ we have to apply equal translation to each of the endpoints A and B and then
redraw the line between the new end points deleting the old line AB. The actual operation of
drawing a line between two endpoints depends on the display device used and the draw–algorithm
followed. Here, we consider only the mathematical operations on the position vectors of the
endpoints.
It is to be noted that whatever amount of translation we apply to a straight line, the length and
orientation (slope) of the translated line remains same as that of the original line.
6
It is implied from the Figrue 3.5 that this translation matrix is theoretically applied to (i.e.,
−3
added to) all the points forming the line AB. This can be tested with any intermediate point AB
between A & B. Think of the midpoint; before transformation it is
And this is the reason why we can express transformations in terms of any constituent point of the
object concerned.
26
Computer Graphics Lecture note
For changing the position of a circle or ellipse, we translate the centre coordinates and redraw the
figure in the new location.
Note from Figures 3.5 and 3.6 that we are transforming the objects without distorting the original
shape size and orientation. Thus we can define Translation as a rigid body transformation that
moves objects without deformation. Every point on the object is translated by the same amount
and there exists a one to one correspondence between the transformed points and original points.
ROTATION
27
Computer Graphics Lecture note
This transformation is used to rotate objects about any point in a reference frame. Unlike
translation rotation brings about changes in position as well as orientation. The point about which
the object is rotated is called the pivot point or rotation point. Conventionally anti-clockwise
rotation about the pivot point is represented by positive angular value. Such transformation can
also be visualized as rotation about an axis that is perpendicular to the reference plane and passes
through the pivot point.
where (r, ) is the polar coordinate of P. When this point P is rotated through an angle in anti-
clockwise direction, the new point P´(x´, y´) becomes,
Rewriting the above equations using laws of sines and cosines from trigonometry,
Replacing rcos∅ and rsin∅ with x and y respectively in (2) we get the simplified form,
In matrix rotation the above relation can be more compactly expressed as,
28
Computer Graphics Lecture note
Eqn. (3) is applicable only for rotation about the origin. But in many applications the pivot point
will not be the origin. It may be any point lying on the object(s) to be rotated or any point outside
the object simply anywhere in the same 2D plane. For example consider the cases when we want
to rotate any strait .line about one of its end points or any rectangle about one of the corner points
or any object lying on a circle about its centre.
Refer Figure 3.9. The Pivot Point is an arbitrary point PP having coordinates (xP, yP). After
rotating P (x, y) through a positive angle its new location is x´y´ (P´)
29
Computer Graphics Lecture note
SCALING
Scaling with Respect to the Origin
Scaling is a transformation that changes the size or shape of an object. Scaling with reference to
origin can be carried out by multiplying the coordinate values (x, y) of each vertex of a polygon,
or each endpoint of a line or arc or the centre point and peripheral definition points of closed
curves like a circle by scaling factors sx and sy respectively to produce the coordinates (x´ y´).
Sx expands or shrinks object dimensions along X direction whereas sy affects dimensions along Y
direction.
30
Computer Graphics Lecture note
We can represent the scaling transformation carried out on square ABCD in Figure 3.11 as,
Notice that in the 2nd case where , sx ≠ sy a distortion in shape has occurred – the square has
transformed into a rectangle.
In general, for uniform scaling, if sx = sy >1, a uniform expansion occurs; i.e. the object becomes
larger. If sx = sy < 1, then a uniform compression occurs; i.e. the object gets smaller. Non-
uniform expansions or compressions occur, depending on whether sx and sy are individually > 1
or < 1 but unequal, such scaling is also known as differential scaling. While the basic object
shape remains unaltered in uniform scaling, the shape and size both changes in differential
scaling. Another interesting point to be noted is that, there is always a translation associated with
scaling. Look at the figures, irrespective of the nature of scaling and the scale factors the scaled
objects have substantially moved from their respective original positions. This is easily
understood if we recall that during scaling transformation, the position vectors of the definition
31
Computer Graphics Lecture note
points are actually scaled with respect to the origin. For example, consider the position vector of
point Q (6, 2) of line PQ. Its magnitude with respect to origin is √6 + 2 =2√10.
The magnitude of the position vectors of the scaled points Q´ (3, 1), Q´´ (12, 4) are respectively
√10=√10 implying uniform scaling with scale factors 0.5 and 2 respectively.
By scaling an object we generally expect it to grow or shrink in size or shape based on its original
position (as shown in Figures 5.12 and 5.13). Apart from scaling, the movement of the object
(which is intrinsically associated in scaling) with respect to origin, is mostly unwanted and can be
eliminated by scaling the object with respect to a point conveniently chosen on the object itself.
The point so chosen, called the fixed point remains unaltered in position after the scaling
transformation when the scale factors are applied on the objects dimensions relative to that fixed
point. As a result the object seems to expand or shrink in size or change in shape without any
displacement of the object as a whole.
For example, consider the scaling transformation of PQ to PQ´ (not P´Q´) in Figure 3.12. Here P
is considered as the fixed point. So, instead of multiplying the scale factor (s = 2) to both P & Q
position vectors it is multiplied with Q – P and then added with P to obtain shifted Q´ and then the
line PQ´ is reconstructed.
32
Computer Graphics Lecture note
Note that Q – P is the dimension of the line PQ relative to P. Now compare the result with the
scaling of line PQ as shown in Figure 3.11 Instead of endpoint P if we consider the midpoint
ofPQ as the fixed point it will expand symmetrically in both direction forming P´Q´ (Figure 3.13),
the midpoint remaining unchanged in position. For scaling of a rectangle shown in Figure 5.13 the
fixed point is the centroid of the rectangle. Thus the fixed point need not necessary lie on the
object—it can be any point either on, within or outside the object. Here we derive the most
generalized expression for scaling any object (P) coordinate say (x, y) with respect to any
arbitrary point say, Pf (xf, yf).
33
Computer Graphics Lecture note
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.
34
Computer Graphics Lecture note
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
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).
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.
35
Computer Graphics Lecture note
36
Computer Graphics Lecture note
While processing an edge of a polygon with clipping window, an intersection point is found if
edge is not completely inside clipping window and the a partial edge from the intersection point
to the outside edge is clipped. The following figures show left, right, top and bottom edge
clippings:
37
Computer Graphics Lecture note
38