Computer Graphics
Computer Graphics
MODULE - I
Overview of Computer Graphics System: Video Display Devices – Raster Scan Systems – Random – Scan
Systems - Graphics Monitors and Workstations – Input Devices – Hardcopy Devices – Graphics Software.
Computer graphics is commonly seen as a computer science branch that deals with the computerized image
fusion theory and technology. As simple as a triangle outline, a computer-generated image may represent a
scene. The computer has become a powerful tool for producing images quickly and economically.
When a computer is used to create images, the same process is followed as creating images manually. The
process’s primary computational steps give a boost to several important computer graphics areas.
Also on computers, the term computer graphics covers almost everything. Here in the computer graphics
program’s classroom, we think of computer graphics as drawing images on machines, often known
as rendering. The images can be photos, sketches, animations, or pictures of items imagined. Or they may
be pictures, we cannot see directly, like internal body parts.
We have put a great deal of our time to develop how computer images can replicate real-world scenes. We
want objects on computers not only to look more real, but also their colors to be more realistic and how
different materials appear. We can call it “real synthesis of the image.”
The term computer graphics has been used to define “almost everything on the computer, including text or
sound.” Generally, the term computer graphics refer to the following things:
The next area of computer graphics that deals with the placement of a triangle is called transformation.
Here we can use matrices to get the mapping of a triangle in image space. We can also set up the
transformation matrix to control the location and orientation of the displayed image. We can also resize the
triangle.
Definition of Computer Graphics-Computer graphics can be a series of images which is most often called
a video or single image. Computer graphics is the technology that concerns with designs and pictures
on computers. That’s why, computer graphics are visual representations of data shown on a monitor made
on a computer.
“Computer graphics is the use of a computer to define, store, manipulate, interrogate, and represent the
pictorial output.” An image in computer graphics is made up of a number of pixels.
In interactive computer graphics, users have some controls over the image, i.e., the user can make any
changes to the image produced.
For Example:
Ping-pong game.
Drawing on touch screens.
Display weather forecast or other moving charts/graphs on the screen.
Animating pictures or graphics in movies.
Graphics animation in video games.
The modern display of graphics is very simple to build. It is composed of three components:
1. Display controller or video controller- It’s a Memory Buffer and TV Monitor interface. Its task is to
pass Frame Buffer’s contents to the monitor. The display controller reads each continuous byte of Memory
frame buffer data and converts 0’s and 1’s into appropriate video signals.
In today’s term, the display controller is recognized as a display card, and one of our choices can be a
VGA(Video Graphics Array) card with a resolution of 640×480. Display Controller is also capable of
displaying the image in colors.
2. Digital memory or frame buffer-This is a place where images and pictures are stored as an array (matrix
of 0 & 1, 0 represents darkness, and 1 represents image or picture). It is also called a frame buffer.
In today’s term frame buffer is called V-RAM (video RAM), and it helps to store the image in bit form. It
helps to increase the speed of graphics.
3. Television monitor- Monitor helps us to view the display, and they make use of CRT(Cathode ray tube)
technology.
Advantages
1. Superior Quality.
2. More accurate outcomes or products.
3. Increased Productivity.
4. Lower cost of development.
5. Increases the ability to understand information and interpret patterns significantly.
Non-interactive computer graphics are also known as passive computer graphics. It is a type of computer
graphics in which the user has no control over the image. The photo is completely controlled by the
instructions of the program, not by the user.
For Example:
Screen savers.
Map representation of the data.
Graphic elements are used in the text, document, and PDF presentation.
Static images are used in mobile applications and websites.
Business graphics are used as brochures, business cards, menu of the hotel.
Representation of graphics
1. Raster Graphics: In raster graphics, the image is presented as a rectangular grid of colored squares.
Raster images are also called bitmap images. Bitmap images are stored as the collection of small individual
dots called pixels.
Bitmap images require high resolution and anti-aliasing for a smooth appearance.
2. Vector Graphics: In vector graphics, the image is represented in the form of continuous geometric
objects: line, curve, etc.
Vector images are not based on pixel pattern. They use mathematical formulas to draw line and curves. The
lines and curves can be combined to create an image.
Raster images are the collection of the The Vector images are composed of
pixel. paths.
Raster image takes less space to store. Vector image takes more space.
Raster graphics can draw mathematical Vector graphics can only draw
curves, polygons, and boundaries. continuous and smooth lines.
File Extension: .BMP, .TIF, .JPG etc. File Extension: .SVG, .PDF, .AI etc.
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.
CRT stands for Cathode ray tube. It is a technology which is used in traditional computer monitor and
television.
Cathode ray tube is a particular type of vacuum tube that displays images when an electron beam collides
on the radiant surface.
Component of CRT:
Electron Gun: The electron gun is made up of several elements, mainly a heating filament (heater)
and a cathode.
The electron gun is a source of electrons focused on a narrow beam facing the CRT.
Focusing & Accelerating Anodes: These anodes are used to produce a narrow and sharply focused
beam of electrons.
Horizontal & Vertical Deflection Plates: These plates are used to guide the path of the electron
the beam. The plates produce an electromagnetic field that bends the electron beam through the area
as it travels.
Phosphorus-coated Screen: The phosphorus coated screen is used to produce bright spots when the
high-velocity electron beam hits it.
The main element of a video monitor is the Cathode Ray Tube CRT, shown in the following illustration.
There are two ways Random scan and Raster scan by which we can display an object on the screen.
Raster Scan
In a raster scan system, the electron beam is swept across the screen, one row at a time from top to bottom.
As the electron beam moves across each row, the beam intensity is turned on and off to create a pattern of
illuminated spots.
Picture definition is stored in memory area called the Refresh Buffer or Frame Buffer. This memory area
holds the set of intensity values for all the screen points. Stored intensity values are then retrieved from the
refresh buffer and “painted” on the screen one row scan line at a time as shown in the following illustration.
Each screen point is referred to as a pixel picture element or pel. At the end of each scan line, the electron
beam returns to the left side of the screen to begin displaying the next scan line.
In this technique, the electron beam is directed only to the part of the screen where the picture is to be drawn
rather than scanning from left to right and top to bottom as in raster scan. It is also called vector display,
stroke-writing display, or calligraphic display.
Picture definition is stored as a set of line-drawing commands in an area of memory referred to as the refresh
display file. To display a specified picture, the system cycles through the set of commands in the display
file, drawing each component line in turn. After all the line-drawing commands are processed, the system
cycles back to the first line command in the list.
Random-scan displays are designed to draw all the component lines of a picture 30 to 60 times each second.
Computer Graphics has numerous applications, some of which are listed below −
Computer graphics user interfaces GUIs − A graphic, mouse-oriented paradigm which allows the
user to interact with a computer.
Business presentation graphics − "A picture is worth a thousand words".
The basic idea behind the color CRT monitor is to combine three basic colors- Red, Green, and Blue. By
using these three colors, we can produce millions of different colors.
1. Beam–Penetration Method: It is used with a random scan monitor for displaying pictures. There are
two phosphorus layers- Red and Green are coated inside the screen. The color shown depends on how
far the electron beam penetrates the phosphorus surface.
A powerful electron beam penetrates the CRT, it passes through the red layer and excites the green layer
within. A beam with slow electrons excites only the red layer. A beam with the medium speed of electrons,
a mixture of red and green light is emitted to display two more colors- orange and yellow.
Advantages:
1. Better Resolution
2. Half cost
3. Inexpensive
Dr. D. UDAYA / Assistant Professor AAGASC / Department of Computer Science / KKL
COMPUTER GRAPHICS
Disadvantages:
[Link]–Mask Method: It is used with a raster scan monitor for displaying pictures. It has more range
of color than the beam penetration method. It is used in television sets and monitors.
Structure:
Working: A Shadow Mask is a metal plate with tiny holes present inside a color monitor.
A Shadow Mask directs the beam by consuming the electrons so that the beam hits only the desired point
and displays a resulting picture.
It has three different guns. These guns direct their beams to shadow mask, which allows them to pass. It is
a task of a shadow mask to direct the beam on its particular dot on the screen and produce a picture on the
screen.
A Shadow Mask can display a wider range of pictures than beam penetration.
Advantages:
Disadvantages:
Liquid crystal display (LCD): The LCD depends upon the light modulating properties of liquid crystals.
LCD is used in watches and portable computers. LCD requires an AC power supply instead of DC, so it is
difficult to use it in circuits. It generally works on flat panel display technology. LCD consumes less power
than LED. The LCD screen uses the liquid crystal to turn pixels on or off. Liquid Crystals are a mixture of
solid and liquid. When the current flows inside it, its position changes into the desired color.
Advantages:
Disadvantages:
Light Emitting Diode (LED): LED is a device which emits when current passes through it. It is a
semiconductor device. The size of the LED is small, so we can easily make any display unit by arranging a
large number of LEDs. LED consumes more power compared to LCD. LED is used on TV, smartphones,
motor vehicles, traffic light, etc. LEDs are powerful in structure, so they are capable of withstanding
mechanical pressure. LED also works at high temperatures.
Advantages:
Disadvantages:
Direct View Storage Tube (DVST): It is used to store the picture information as a charge distribution
behind the phosphor-coated [Link] are two guns used in DVST:
Advantages:
Disadvantages:
Plasma Display: It is a type of flat panel display which uses tiny plasma cells. It is also known as the Gas-
Discharge display.
1. Anode: It is used to deliver a positive voltage. It also has the line wires.
2. Cathode: It is used to provide negative voltage to gas cells. It also has fine wires.
3. Gas Plates: These plates work as capacitors. When we pass the voltage, the cell lights regularly.
4. Fluorescent cells: It contains small pockets of gas liquids when the voltage is passed to this neon gas. It
emits light.
Advantages:
1. Wall Mounted
2. Slim
3. Wider angle
Disadvantages:
3D Display: It is also called stereoscope display technology. This technology is capable of bringing depth
perception to the viewer. It is used for 3D gaming and 3D TVs.
Advantages:
Disadvantage:
Expensive
Binocular Fusion
Input Devices
Following are some of the important input devices which are used in a computer −
Keyboard
Mouse
Dr. D. UDAYA / Assistant Professor AAGASC / Department of Computer Science / KKL
COMPUTER GRAPHICS
Joy Stick
Light pen
Track Ball
Scanner
Graphic Tablet
Microphone
Magnetic Ink Card Reader(MICR)
Optical Character Reader(OCR)
Bar Code Reader
Optical Mark Reader(OMR)
Keyboard
Keyboard is the most common and very popular input device which helps to input data to the computer. The
layout of the keyboard is like that of traditional typewriter, although there are some additional keys provided
for performing additional functions.
Keyboards are of two sizes 84 keys or 101/102 keys, but now keyboards with 104 keys or 108 keys are also
available for Windows and Internet.
Typing Keys
1
These keys include the letter keys (A-Z) and digit keys (09) which generally give the
same layout as that of typewriters.
Numeric Keypad
2 It is used to enter the numeric data or cursor movement. Generally, it consists of a set
of 17 keys that are laid out in the same configuration used by most adding machines
and calculators.
3 The twelve function keys are present on the keyboard which are arranged in a row at
the top of the keyboard. Each function key has a unique meaning and is used for some
specific purpose.
Control keys
4 These keys provide cursor and screen control. It includes four directional arrow keys.
Control keys also include Home, End, Insert, Delete, Page Up, Page Down,
Control(Ctrl), Alternate(Alt), Escape(Esc).
Mouse
Mouse is the most popular pointing device. It is a very famous cursor-control device having a small palm
size box with a round ball at its base, which senses the movement of the mouse and sends corresponding
signals to the CPU when the mouse buttons are pressed.
Generally, it has two buttons called the left and the right button and a wheel is present between the buttons.
A mouse can be used to control the position of the cursor on the screen, but it cannot be used to enter text
into the computer.
Advantages
Easy to use
Not very expensive
Moves the cursor faster than the arrow keys of the keyboard.
Joystick
Joystick is also a pointing device, which is used to move the cursor position on a monitor screen. It is a stick
having a spherical ball at its both lower and upper ends. The lower spherical ball moves in a socket. The
joystick can be moved in all four directions.
The function of the joystick is similar to that of a mouse. It is mainly used in Computer Aided Designing
(CAD) and playing computer games.
Light Pen
Light pen is a pointing device similar to a pen. It is used to select a displayed menu item or draw pictures
on the monitor screen. It consists of a photocell and an optical system placed in a small tube.
When the tip of a light pen is moved over the monitor screen and the pen button is pressed, its photocell
sensing element detects the screen location and sends the corresponding signal to the CPU.
Track Ball
Track ball is an input device that is mostly used in notebook or laptop computer, instead of a mouse. This is
a ball which is half inserted and by moving fingers on the ball, the pointer can be moved.
Since the whole device is not moved, a track ball requires less space than a mouse. A track ball comes in
various shapes like a ball, a button, or a square.
Scanner
Scanner is an input device, which works more like a photocopy machine. It is used when some information
is available on paper and it is to be transferred to the hard disk of the computer for further manipulation.
Scanner captures images from the source which are then converted into a digital form that can be stored on
the disk. These images can be edited before they are printed.
Digitizer
Digitizer is an input device which converts analog information into digital form. Digitizer can convert a
signal from the television or camera into a series of numbers that could be stored in a computer. They can
be used by the computer to create a picture of whatever the camera had been pointed at.
Digitizer is also known as Tablet or Graphics Tablet as it converts graphics and pictorial data into binary
inputs. A graphic tablet as digitizer is used for fine works of drawing and image manipulation applications.
Microphone
Microphone is an input device to input sound that is then stored in a digital form.
The microphone is used for various applications such as adding sound to a multimedia presentation or for
mixing music.
MICR input device is generally used in banks as there are large number of cheques to be processed every
day. The bank's code number and cheque number are printed on the cheques with a special type of ink that
contains particles of magnetic material that are machine readable.
This reading process is called Magnetic Ink Character Recognition (MICR). The main advantages of MICR
is that it is fast and less error prone.
OCR scans the text optically, character by character, converts them into a machine readable code, and stores
the text on the system memory.
Bar Code Reader is a device used for reading bar coded data (data in the form of light and dark lines). Bar
coded data is generally used in labelling goods, numbering the books, etc. It may be a handheld scanner or
may be embedded in a stationary scanner.
Bar Code Reader scans a bar code image, converts it into an alphanumeric value, which is then fed to the
computer that the bar code reader is connected to.
OMR is a special type of optical scanner used to recognize the type of mark made by pen or pencil. It is
used where one out of a few alternatives is to be selected and marked.
It is specially used for checking the answer sheets of examinations having multiple choice questions.
Output Devices
An output device is a component of hardware or the main physical part of a computer that can be touched
and seen. An output device is an electromechanical device.
“The Computer gives instructions and data from input devices and processes it and returns the result
called as output.”
Printers:
A printer is a peripheral device which is used to represent the graphics or text on paper. The quality is
measured by its resolution. The resolution of any printer is measured in dot per inch (dpi).
The printer usually works with the computer and connected via a cable. In present, many digital device
support printer features so that we can use Bluetooth, Wi-fi, and cloud technology to print.
Types of Printers
Impact Printers
Non-impact Printers
Impact Printers
In impact printers, there is a physical contact established between the print head, ribbon, ink-cartridge, and
paper.
The printers hit print head on an ink-filled ribbon than the letter prints on the paper. Impact printers are
works like a typewriter.
Impact printers print the characters by striking them on the ribbon, which is then pressed on the paper.
Character printers
Line printers
Character Printers
Character printers are the printers which print one character at a time.
In the market, one of the most popular printers is Dot Matrix Printer. These printers are popular because of
their ease of printing and economical price. Each character printed is in the form of pattern of dots and head
consists of a Matrix of Pins of size (5*7, 7*9, 9*7 or 9*9) which come out to form a character which is why
it is called Dot Matrix Printer.
Advantages
Inexpensive
Widely Used
Other language characters can be printed
Disadvantages
Slow Speed
Poor Quality
Daisy Wheel
Head is lying on a wheel and pins corresponding to characters are like petals of Daisy (flower) which is why
it is called Daisy Wheel Printer. These printers are generally used for word-processing in offices that require
a few letters to be sent here and there with very nice quality.
Advantages
Disadvantages
Line Printers
Line printers are the printers which print one line at a time.
Drum Printer
Chain Printer
Drum Printer
This printer is like a drum in shape hence it is called drum printer. The surface of the drum is divided into a
number of tracks. Total tracks are equal to the size of the paper, i.e. for a paper width of 132 characters,
drum will have 132 tracks. A character set is embossed on the track. Different character sets available in the
market are 48 character set, 64 and 96 characters set. One rotation of drum prints one line. Drum printers
are fast in speed and can print 300 to 2000 lines per minute.
Advantages
Disadvantages
Very expensive
Characters fonts cannot be changed
Chain Printer
In this printer, a chain of character sets is used, hence it is called Chain Printer. A standard character set may
have 48, 64, or 96 characters.
Advantages
Disadvantages
Noisy
Non-impact Printers
Non-impact printers print the characters without using the ribbon. These printers print a complete page at a
time, thus they are also called as Page Printers.
Laser Printers
Inkjet Printers
Laser Printers
These are non-impact page printers. They use laser lights to produce the dots needed to form the characters
to be printed on a page.
Advantages
Disadvantages
Expensive
Cannot be used to produce multiple copies of a document in a single printing
Inkjet Printers
Inkjet printers are non-impact character printers based on a relatively new technology. They print characters
by spraying small drops of ink onto paper. Inkjet printers produce high quality output with presentable
features.
They make less noise because no hammering is done and these have many styles of printing modes available.
Color printing is also possible. Some models of Inkjet printers can produce multiple copies of printing also.
Advantages
Disadvantages
Monitors
Monitors, commonly called as Visual Display Unit (VDU), are the main output device of a computer. It
forms images from tiny dots, called pixels that are arranged in a rectangular form. The sharpness of the
image depends upon the number of pixels.
The CRT display is made up of small picture elements called pixels. The smaller the pixels, the better the
image clarity or resolution. It takes more than one illuminated pixel to form a whole character, such as the
letter ‘e’ in the word help.
A finite number of characters can be displayed on a screen at once. The screen can be divided into a series
of character boxes - fixed location on the screen where a standard character can be placed. Most screens are
capable of displaying 80 characters of data horizontally and 25 lines vertically.
Large in Size
High power consumption
The flat-panel display refers to a class of video devices that have reduced volume, weight and power
requirement in comparison to the CRT. You can hang them on walls or wear them on your wrists. Current
uses of flat-panel displays include calculators, video games, monitors, laptop computer, and graphics
display.
Emissive Displays − Emissive displays are devices that convert electrical energy into light. For
example, plasma panel and LED (Light-Emitting Diodes).
Non-Emissive Displays − Non-emissive displays use optical effects to convert sunlight or light from
some other source into graphics patterns. For example, LCD (Liquid-Crystal Device).
Plotters:
A plotter is a special type of output device. It is used to print large graphs, large designs on a large paper. For
Example: Construction maps, engineering drawings, architectural plans, and business charts, etc.
Types of Plotter
1. Flatbed Plotter: In a flatbed plotter, the paper is kept in a stationary position on a table or a tray. A
flatbed plotter has more than one pen and a holder. The pen rotates on the paper upside-down and
right-left by the using of a motor.
Every pen has a different color ink, which is used to draw the multicolor design.
We can quickly draw the following designs by using a flatbed printer.
For: Cars, Ships, Airplanes, Dress design, road and highway blueprints, etc.
2. Drum Plotter: It is also called “Roller plotter.” There is a drum in this plotter. We can apply the paper
on the drum. When the plotter works, these drums moves back and forth, and the image is drawn.
Drum plotter has more than one pen and penholders. The pens easily moves right to left and left to right.
The movement of pens and drums are controlled by graph plotting [Link] is used in industry to produce
large drawings (up to A0).
1. Very costly
Graphics Monitor:
i).The name itself giving some idea that, Monitor which is capable of displaying “Graphics”. Generally most
of the Monitors support Text modes.
ii).So Monitors which are capable of showing and supporting Graphics mode along with the Text modes.
iii).Graphic monitors who can display pictures on its screen, of course it acts like an output device. The
monitors which support the following Graphic applications are said to be Graphic Monitors.
Workstation:
i).Workstation is also a computer which varies generally with other General Computers
ii).Because these Workstations need good operating power of computer. They must be able to support high
power i.e. it must sustain good graphic capabilities.
iii).These kind of computers comes with the following specifications. Unlike normal general computers they
consists of,
A).Minimum of 64 Megabytes of RAM
B).Very good Resolution Graphics screen
C).High and Large Screen
D).GUI Graphical User Interface (which helps programs easier to use of the Computer’s Graphics)
E).Very good Mass storage Device like Disk Drive
F).Built-in Network Support and many factors
iv) We may also notice that, some of the workstations do not have any disk drives in it. So these kind of
disk drives are called as Diskless workstation.
v) Workstations took place of and they lie between Personal computer (General Computers) and
minicomputers as far as Computing power is concerned.
vi) These can be used as both types such as stand system (which only consists of one) and Local area
network. So basically in this LAN kind, workstations are typically connected together one and other.
If coordinate values for a picture are specified is some other reference frame they must be converted
to Cartesian coordinate before giving input to graphics package.
Special-purpose package may allow use of other coordinates which suits application.
In general several different Cartesian reference frames are used to construct and display scene.
We can construct shape of object with separate coordinate system called modeling coordinates or
sometimes local coordinates or master coordinates.
Once individual object shapes have been specified we can place the objects into appropriate
positions called world coordinates.
Finally the World-coordinates description of the scene is transferred to one or more output device
reference frame for display. These display coordinates system are referred to as “Device
Coordinates” or “Screen Coordinates”.
Generally a graphic system first converts the world-coordinates position to normalized device
coordinates. In the range from 0 to 1 before final conversion to specific device coordinates.
An initial modeling coordinates position ( Xmc,Ymc) in this illustration is transferred to a device
Xdc,Ydc).
Graphic Function
A general purpose graphics package provides user with Varity of function for creating and
manipulating pictures.
The basic building blocks for pictures are referred to as output primitives. They includes character,
string, and geometry entities such as point, straight lines, curved lines, filled areas and shapes
defined with arrays of color points.
Input functions are used for control & process the various input device such as mouse, tablet, etc.
Control operations are used to controlling and housekeeping tasks such as clearing display screen
etc.
All such inbuilt function which we can use for our purpose are known as graphics function
Software Standard
Primary goal of standardize graphics software is portability so that it can be used in any hardware
systems & avoid rewriting of software program for different system
Some of these standards are discuss below
Graphical Kernel System (GKS)
This system was adopted as a first graphics software standard by the international standard
organization (ISO) and various national standard organizations including ANSI.
GKS was originally designed as the two dimensional graphics package and then later extension was
developed for three dimensions.
Output Primitives: Line Drawing Algorithms – Loading the Frame Buffer – Line Function – Circle –
Generating Algorithms - Attributes of Output Primitives: Line Attributes – Curve Attributes – Color and
Gray scale levels– Area fill Attributes – Character Attributes – Bundled Attributes – Inquiry Functions.
Output Primitives
Point plotting is done by converting a single coordinate position furnished by an application program into
appropriate operations for the output device in use.
Line drawing is done by calculating intermediate positions along the line path between two specified
endpoint positions.
The output device is then directed to fill in those positions between the end points with some color.
For some device such as a pen plotter or random scan display, a straight line can be drawn smoothly from one
end point to other.
Digital devices display a straight line segment by plotting discrete points between the two endpoints.
Discrete coordinate positions along the line path are calculated from the equation of the line.
For a raster video display, the line intensity is loaded in frame buffer at the corresponding pixel positions.
Reading from the frame buffer, the video controller then plots the screen pixels.
Screen locations are referenced with integer values, so plotted positions may only approximate actual line
positions between two specified endpoints.
For example line position of (12.36, 23.87) would be converted to pixel position (12, 24).
This rounding of coordinate values to integers causes lines to be displayed with a stair step appearance
Fig. 2.1: - Stair step effect produced when line is generated as a series of pixel positions.
The stair step shape is noticeable in low resolution system, and we can improve their appearance somewhat
by displaying them on high resolution system.
More effective techniques for smoothing raster lines are based on adjusting pixel intensities along the line
paths.
For raster graphics device-level algorithms discuss here, object positions are specified directly in integer
device coordinates.
Pixel position will referenced according to scan-line number and column number which is illustrated by
following figure.
2
0 1 2 3 4 5 6
Fig. 2.2: - Pixel positions referenced by scan-line number and column number.
To load the specified color into the frame buffer at a particular position, we will assume we have
available low-level procedure of the form 𝑠𝑒𝑡𝑝𝑖𝑥𝑒𝑙(𝑥, 𝑦)
Similarly for retrieve the current frame buffer intensity we assume to have procedure 𝑔𝑒𝑡𝑝𝑖𝑥(𝑥, 𝑦).
The Line drawing algorithm is a graphical algorithm which is used to represent the line segment on discrete
graphical media, i.e., printer and pixel-based media.
An algorithm should be precise: Each step of the algorithm must be adequately defined.
Finiteness: An algorithm must contain finiteness. It means the algorithm stops after the execution of all
steps.
Easy to understand: An algorithm must help learners to understand the solution in a more natural way.
Correctness: An algorithm must be in the correct manner.
Effectiveness: The steps of an algorithm must be valid and efficient.
Uniqueness: All steps of an algorithm should be clearly and uniquely defined, and the result should be
based on the given input.
Input: A good algorithm must accept at least one or more input.
Output: An algorithm must generate at least one output.
We can define a straight line with the help of the following equation.
y= mx + a
Where,
(x, y) = axis of the line.
m = Slope of the line.
a = Interception point
Let us assume we have two points of the line (p1, q1) and (p2, q2).
Now, we will put values of the two points in straight line equation, and we get
y = mx + a
q2 = mp2 …(1)
q1 = mp1 + a …(2)
The Digital Differential Analyzer helps us to interpolate the variables on an interval from one point to another point.
We can use the digital Differential Analyzer algorithm to perform rasterization on polygons, lines, and triangles.
Digital Differential Analyzer algorithm is also known as an incremental method of scan conversion. In this
algorithm, we can perform the calculation in a step by step manner. We use the previous step result in the next step.
Now, we consider one point (xk, yk) and (xk+1, yk+1) as the next point.
Then the slope m = (yk+1 – yk)/ (xk+1 – xk)
Now, we have to find the slope between the starting point and ending point. There can be following three cases to
discuss:
Case 1: If m < 1
Then x coordinate tends to the Unit interval.
xk+1 = xk + 1
yk+1 = yk + m
Case 2: If m > 1
Then y coordinate tends to the Unit interval.
yk+1 = yk + 1
xk+1 = xk + 1/m
Case 3: If m = 1
Then x and y coordinate tend to the Unit interval.
xk+1 = xk + 1
yk+1 = yk + 1
We can calculate all intermediate points with the help of above three discussed cases.
Step 1: Start.
Step 2: We consider Starting point as (x1, y1), and endingpoint (x2, y2).
Step 3: Now, we have to calculate ▲x and ▲y.
▲x = x2-x1
▲y = y2-y1
m = ▲y/▲x
Step 4: Now, we calculate three cases.
If m < 1
Then x change in Unit Interval
y moves with deviation
(xk+1, yk+1) = (xk+1, yk+1)
If m > 1
Then x moves with deviation
y change in Unit Interval
(xk+1, yk+1) = (xk+1/m, yk+1/m)
If m = 1
Then x moves in Unit Interval
y moves in Unit Interval
(xk+1, yk+1) = (xk+1, yk+1)
Step 5: We will repeat step 4 until we find the ending point of the line.
Step 6: Stop.
Example: A line has a starting point (1,7) and ending point (11,17). Apply the Digital Differential Analyzer algorithm
to plot a line.
1 7 2 8 (2, 8)
3 9 (3, 9)
4 10 (4, 10)
5 11 (5, 11)
6 12 (6, 12)
7 13 (7, 13)
8 14 (8, 14)
9 15 (9, 15)
10 16 (10, 16)
11 17 (11, 17)
Step 4: We will repeat step 3 until we get the endpoints of the line.
Step 5: Stop.
This algorithm was introduced by “Jack Elton Bresenham” in 1962. This algorithm helps us to perform scan
conversion of a line. It is a powerful, useful, and accurate method. We use incremental integer calculations to draw a
line. The integer calculations include addition, subtraction, and multiplication.
In Bresenham’s Line Drawing algorithm, we have to calculate the slope (m) between the starting point and the ending
point.
As shown in the above figure let, we have initial coordinates of a line = (xk, yk). The next coordinates of a line = (xk+1,
yk+1). The intersection point between yk and yk+1 = y. Let we assume that the distance between y and yk = d1. The
distance between y and yk+1 = d2. Now, we have to decide which point is nearest to the intersection point.
If m < 1 then x = xk+1 { Unit Interval}
y = yk+1 { Unit Interval}
As we know the equation of a line-
y = mx +b
Now we put the value of x into the line equation, then
y = m(xk+1) +b …………. (1)
The value of d1 = y – yk
y = m (xk+1) +b – yk
Now, we again put the value of y in the previous equation then we got,
d2 = yk+1 – y
= yk + 1 – m (xk+1) – b
Similarly, if m >1, the new decision parameter for next coordinate will be
pk+1 = pk + 2▲y – 2▲x (xk+1 – xk) {New decision parameter when m >1}
If pk >= 0 {For coordinate y}
Then,
yk+1 = yk+1 {We will choose the nearest yk+1 pixel}
Then,
xk+1 = xk+1 {We will choose the nearest xk+1 pixel}
Then,
xk+1 = xk {We will choose the nearest xk pixel}
Step 1: Start.
Step 2: Now, we consider Starting point as (x1, y1) and ending point (x2, y2).
Step 3: Now, we have to calculate ▲x and ▲y.
▲x = x2-x1
▲y = y2-y1
m = ▲y/▲x
Step 4: Now, we will calculate the decision parameter pk with following formula.
pk = 2▲y-▲x
Step 5: The initial coordinates of the line are (xk, yk), and the next coordinates are (xk+1, yk+1). Now, we are going to
calculate two cases for decision parameter pk
Case 1: If
pk < 0
Then
pk+1 =pk +2▲y
xk+1 = xk +1
yk+1 = yk
Case 2: If
pk >= 0
Then
pk+1 =pk +2▲y-2▲x
xk+1 =xk +1
yk+1 =yk +1
Step 6: We will repeat step 5 until we found the ending point of the line and the total number of iterations =▲x-1.
Step 7: Stop.
Example: A line has a starting point (9,18) and ending point (14,22). Apply the Bresenham’s Line Drawing algorithm
to plot a line.
Thus
pk+1 = pk +2▲y-2▲x =3+ (2 x 4) – (2 x 5) = 1
xk+1 =xk +1 = 9 + 1 = 10
yk+1 =yk +1 = 18 +1 = 19
Step 4: Now move to next step. We will calculate the coordinates until we reach the end point of the line.
▲x -1 = 5 – 1 = 4
9 18
3 1 10 19
1 -1 11 20
-1 7 12 20
7 5 13 21
5 3 14 22
Step 5: Stop.
The Bresenham’s Line drawing algorithm only helps to draw the basic line.
The resulted draw line is not smooth.
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,YX,Y location and now need
to decide where to put the next pixel − at N X+1,YX+1,Y or at S X+1,Y−1X+1,Y−1.
Algorithm
Step 1 − Get the coordinates of the center of the circle and radius, and store them in x, y, and R respectively.
Set P=0 and Q=R.
Step 2 − Set decision parameter D = 3 – 2R.
Step 3 − Repeat through step-8 while P ≤ Q.
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
(x0, y0) = (0, r)
Step 2 − Calculate the initial value of decision parameter as
P0P0 = 5/4 – r
See the following description for simplification of this equation.
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
Step 3 − At each XKXK position starting at K=0, perform the following test −
If PK < 0 then next point on circle (0,0) is (XK+1,YK) and
PK+1 = PK + 2XK+1 + 1
Else
PK+1 = PK + 2XK+1 + 1 – 2YK+1
MODULE - III
2D Transformations
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 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 PX,YX,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 (tx, ty) to the original coordinate X,YX,Y to get the new
coordinate X′,Y′X′,Y′.
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 θ thetatheta from its origin. From the
following figure, we can see that the point PX,YX,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′X′,Y′.
Using standard trigonometric the original coordinate of point PX,YX,Y can be represented as
−
X=rcosϕ......(1)X=rcosϕ......(1)
Y=rsinϕ......(2)Y=rsinϕ......(2)
x′=rcos(ϕ+θ)=rcosϕcosθ−rsinϕsinθ.......(3)x′=rcos(ϕ+θ)=rcosϕcosθ−rsinϕsinθ.......(3)
y′=rsin(ϕ+θ)=rcosϕsinθ+rsinϕcosθ.......(4)y′=rsin(ϕ+θ)=rcosϕsinθ+rsinϕcosθ.......(4)
x′=xcosθ−ysinθx′=xcosθ−ysinθ
y′=xsinθ+ycosθy′=xsinθ+ycosθ
[X′Y′]=[XY][cosθ−sinθsinθcosθ]OR[X′Y′]=[XY][cosθsinθ−sinθcosθ]OR
P’ = P . R
R=[cosθ−sinθsinθcosθ]R=[cosθsinθ−sinθcosθ]
For positive rotation angle, we can use the above rotation matrix. However, for negative angle
rotation, the matrix will change as shown below −
R=[cos(−θ)−sin(−θ)sin(−θ)cos(−θ)]R=[cos(−θ)sin(−θ)−sin(−θ)cos(−θ)]
=[cosθsinθ−sinθcosθ](∵cos(−θ)=cosθandsin(−θ)=−sinθ)=[cosθ−sinθsinθcosθ](∵cos(−θ)=cosθ
andsin(−θ)=−sinθ)
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,YX,Y, the scaling factors are (SX, SY), and
the produced coordinates are X′,Y′X′,Y′. This can be mathematically represented as shown
below −
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 −
(X′Y′)=(XY)[Sx00Sy](X′Y′)=(XY)[Sx00Sy]
OR
P’ = P . S
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.
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.
Xsh=⎡⎣⎢100shx10001⎤⎦⎥Xsh=[1shx0010001]
Y' = Y + Shy . X
X’ = X
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.
Ysh⎡⎣⎢1shy0010001⎤⎦⎥Ysh[100shy10001]
X’ = X + Shx . Y
Y’ = Y
For translation,
P‘= P+T
x‘ = x + tx
y‘ y ty
For rotation,
x‘ = Cosθ -Sinθ . x
y‘ Sinθ Cosθ y
For scaling,
P‘= S.P
Composite Transformation
If a transformation of the plane T1 is followed by a second plane transformation T2, then the
result itself may be represented by a single transformation T which is the composition of T1
and T2 taken in that order. This is written as T = T1∙T2.
A combined matrix −
Translation
Scaling
Shearing
Rotation
Reflection
The change in the order of transformation would lead to different results, as in general matrix
multiplication is not cumulative, that is [A] . [B] ≠ [B] . [A] and the order of multiplication.
The basic purpose of composing transformations is to gain efficiency by applying a single
composed transformation to a point, rather than applying a series of transformation, one after
another.
For example, to rotate an object about an arbitrary point (Xp, Yp), we have to carry out three
steps −
We have learnt matrix representations of transformation. We can set up a matrix for any
sequence of transformations as a composite transform matrix by calculating the matrix
product of the individual transform.
For e.g. suppose we want to perform rotation of an object about an arbitrary point. This
can be performed by applying a sequence of three simple transforms a translation,
followed by a rotation followed by another translation. For e.g. suppose we are asked
to rotate the triangle through 900 .
This can be done by first translate the object to the origin. Rotate it by 900 and again translate
it by tx = 2, ty=0.
Here we have done one translation, one rotation , one translation again. Complex
transformation can be described as concatenation of simple ones. Suppose we wish to derive a
transformation which will rotate a point through a clockwise angle @ about the point (Rx, Ry).
The rotation transformation be applied to rotate points only about the origin. So we must
translate points so that (Rx, Ry) becomes the origin.
x‘ = x . 1 0 -Rx
y‘ y 0 1 -Ry
1 1 0 0 1
then rotation can be applied