100% found this document useful (1 vote)
55 views86 pages

CG Notes

Computer graphics involves using computers to create and manipulate visual images. It allows for the creation of 2D and 3D images that can be used across many fields like engineering, education, entertainment and more. Interactive computer graphics allow users to control images by sending input to modify them in real-time, while passive graphics do not allow for user control over pre-rendered images. The basic components of a computer graphics system include a frame buffer for storing pixel data, a monitor for displaying the image, and a display controller that transfers frame buffer contents to the monitor for display.

Uploaded by

Santosh Panda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
55 views86 pages

CG Notes

Computer graphics involves using computers to create and manipulate visual images. It allows for the creation of 2D and 3D images that can be used across many fields like engineering, education, entertainment and more. Interactive computer graphics allow users to control images by sending input to modify them in real-time, while passive graphics do not allow for user control over pre-rendered images. The basic components of a computer graphics system include a frame buffer for storing pixel data, a monitor for displaying the image, and a display controller that transfers frame buffer contents to the monitor for display.

Uploaded by

Santosh Panda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

Vikram Deb Autonomous College, Jeypore (K)

Department of Computer Science

Computer Graphics Tutorial


CC-X
According to CBCS Pattern

Prepared By
Santosh Panda
Asst. Prof. in Computer Science
UNIT-1
Introduction of Computer Graphics

It is difficult to display an image of any size on the computer screen. This method is simplified by using
Computer graphics. Graphics on the computer are produced by using various algorithms and techniques.
This tutorial describes how a rich visual experience is provided to the user by explaining how all these
processed by the computer.

Computer Graphics involves technology to access. The Process transforms and presents
information in a visual form. In today life, computer graphics has now become a common
element in user interfaces, T.V. commercial motion pictures.

Computer Graphics is the creation of pictures with the help of a computer. The end product of
the computer graphics is a picture it may be a business graph, drawing, and engineering.

In computer graphics, two or three-dimensional pictures can be created that are used for research.
Many hardware devices algorithm has been developing for improving the speed of picture
generation with the passes of time. It includes the creation storage of models and image of
objects. These models for various fields like engineering, mathematical and so on.

Today computer graphics is entirely different from the earlier one. It is not possible. It is an interactive
user can control the structure of an object of various input devices.

Definition of Computer Graphics:


It is the use of computers to create and manipulate pictures on a display device. It comprises of
software techniques to create, store, modify, represents pictures.

Why computer graphics used?


Suppose a shoe manufacturing company want to show the sale of shoes for five years. For this
vast amount of information is to store. So a lot of time and memory will be needed. This method
will be tough to understand by a common man. In this situation graphics is a better alternative.
Graphics tools are charts and graphs. Using graphs, data can be represented in pictorial form. A
picture can be understood easily just with a single look.

Interactive computer graphics work using the concept of two-way communication between
computer users. The computer will receive signals from the input device, and the picture is
modified accordingly. Picture will be changed quickly when we apply command.
Application of Computer Graphics
1. Education and Training: Computer-generated model of the physical, financial and economic
system is often used as educational aids. Model of physical systems, physiological system,
population trends or equipment can help trainees to understand the operation of the system.

For some training applications, particular systems are designed. For example Flight Simulator.

Flight Simulator: It helps in giving training to the pilots of airplanes. These pilots spend much
of their training not in a real aircraft but on the ground at the controls of a Flight Simulator.

Advantages:
1. Fuel Saving
2. Safety
3. Ability to familiarize the training with a large number of the world's airports.

2. Use in Biology: Molecular biologist can display a picture of molecules and gain insight into
their structure with the help of computer graphics.

3. Computer-Generated Maps: Town planners and transportation engineers can use computer-
generated maps which display data useful to them in their planning work.

4. Architect: Architect can explore an alternative solution to design problems at an interactive


graphics terminal. In this way, they can test many more solutions that would not be possible
without the computer.

5. Presentation Graphics: Example of presentation Graphics are bar charts, line graphs, pie
charts and other displays showing relationships between multiple parameters. Presentation
Graphics is commonly used to summarize

o Financial Reports
o Statistical Reports
o Mathematical Reports
o Scientific Reports
o Economic Data for research reports
o Managerial Reports
o Consumer Information Bulletins
o And other types of reports

6. Computer Art: Computer Graphics are also used in the field of commercial arts. It is used to
generate television and advertising commercial.

7. Entertainment: Computer Graphics are now commonly used in making motion pictures,
music videos and television shows.

8. Visualization: It is used for visualization of scientists, engineers, medical personnel, business


analysts for the study of a large amount of information.

9. Educational Software: Computer Graphics is used in the development of educational


software for making computer-aided instruction.

10. Printing Technology: Computer Graphics is used for printing technology and textile design.

Interactive and Passive Graphics


(a) Non-Interactive or Passive Computer Graphics:
In non-interactive computer graphics, the picture is produced on the monitor, and the user does
not have any controlled over the image, i.e., the user cannot make any change in the rendered
image. One example of its Titles shown on T.V.

Non-interactive Graphics involves only one-way communication between the computer and the
user, User can see the produced image, and he cannot make any change in the image.

(b) Interactive Computer Graphics:


In interactive Computer Graphics user have some controls over the picture, i.e., the user can
make any change in the produced image. One example of it is the ping-pong game.

Interactive Computer Graphics require two-way communication between the computer and the
user. A User can see the image and make any change by sending his command with an input
device.
Advantages:
1. Higher Quality
2. More precise results or products
3. Greater Productivity
4. Lower analysis and design cost
5. Significantly enhances our ability to understand data and to perceive trends.

Working of Interactive Computer Graphics:


The modern graphics display is very simple in construction. It consists of three components:

1. Frame Buffer or Digital Memory


2. A Monitor likes a home T.V. set without the tuning and receiving electronics.
3. Display Controller or Video Controller: It passes the contents of the frame buffer to the
monitor.

Frame Buffer: A digital frame buffer is large, contiguous piece of computer memory used to
hold or map the image displayed on the screen.

o At a minimum, there is 1 memory bit for each pixel in the raster. This amount of memory is
called a bit plane.
o A 1024 x 1024 element requires 220 (210=1024;220=1024 x 1024)sq.raster or 1,048,576 memory
bits in a single bit plane.
o The picture is built up in the frame buffer one bit at a time.
o ∵ A memory bit has only two states (binary 0 or 1), a single bit plane yields a black and white
(monochrome display).
o As frame buffer is a digital device write raster CRT is an analog device.

Properties of Video Monitor:


1. Persistence: Persistence is the duration of phosphorescence. Different kinds of phosphors are
available for use in CRT. Besides color, a major difference between phosphor in their persistence
how they continue to emit light after the electron beam is removed.

2. Resolution: Use to describe the number of pixels that are used on display image.

3. Aspect Ratio: It is the ratio of width to its height. Its measure is unit in length or number of
pixels.

Aspect Ratio =

Display Processor:
It is interpreter or piece of hardware that converts display processor code into pictures. It is one
of the four main parts of the display processor

Parts of Display Processor

1. Display File Memory


2. Display Processor
3. Display Generator
4. Display Console
Display File Memory: It is used for generation of the picture. It is used for identification of
graphic entities.

Display Controller:

1. It handles interrupt
2. It maintains timings
3. It is used for interpretation of instruction.

Display Generator:

1. It is used for the generation of character.


2. It is used for the generation of curves.

Display Console: It contains CRT, Light Pen, and Keyboard and deflection system.

The raster scan system is a combination of some processing units. It consists of the control
processing unit (CPU) and a particular processor called a display controller. Display Controller
controls the operation of the display device. It is also called a video controller.

Working: The video controller in the output circuitry generates the horizontal and vertical drive
signals so that the monitor can sweep. Its beam across the screen during raster scans.
As fig showing that 2 registers (X register and Y register) are used to store the coordinate of the
screen pixels. Assume that y values of the adjacent scan lines increased by 1 in an upward
direction starting from 0 at the bottom of the screen to ymax at the top and along each scan line
the screen pixel positions or x values are incremented by 1 from 0 at the leftmost position to
xmax at the rightmost position.

The origin is at the lowest left corner of the screen as in a standard Cartesian coordinate system.
At the start of a Refresh Cycle:

X register is set to 0 and y register is set to ymax. This (x, y') address is translated into a memory
address of frame buffer where the color value for this pixel position is stored.

The controller receives this color value (a binary no) from the frame buffer, breaks it up into
three parts and sends each element to a separate Digital-to-Analog Converter (DAC).

These voltages, in turn, controls the intensity of 3 e-beam that are focused at the (x, y) screen
position by the horizontal and vertical drive signals.

This process is repeated for each pixel along the top scan line, each time incrementing the X
register by Y.

As pixels on the first scan line are generated, the X register is incremented throughx max.

Then x register is reset to 0, and y register is decremented by 1 to access the next scan line.

Pixel along each scan line is then processed, and the procedure is repeated for each successive
scan line units pixels on the last scan line (y=0) are generated.

For a display system employing a color look-up table frame buffer value is not directly used to
control the CRT beam intensity.

It is used as an index to find the three pixel-color value from the look-up table. This lookup
operation is done for each pixel on every display cycle.

As the time available to display or refresh a single pixel in the screen is too less, accessing the
frame buffer every time for reading each pixel intensity value would consume more time what is
allowed:
Multiple adjacent pixel values are fetched to the frame buffer in single access and stored in the
register.

After every allowable time gap, the one-pixel value is shifted out from the register to control the
warm intensity for that pixel.

The procedure is repeated with the next block of pixels,and so on, thus the whole group of pixels
will be processed.

Display Devices:
The most commonly used display device is a video monitor. The operation of most video
monitors based on CRT (Cathode Ray Tube). The following display devices are used:

1. Refresh Cathode Ray Tube


2. Random Scan and Raster Scan
3. Color CRT Monitors
4. Direct View Storage Tubes
5. Flat Panel Display
6. Lookup Table

Cathode Ray Tube (CRT):


CRT stands for Cathode Ray Tube. CRT is a technology used in traditional computer monitors
and televisions. The image on CRT display is created by firing electrons from the back of the
tube of phosphorus located towards the front of the screen.

Once the electron heats the phosphorus, they light up, and they are projected on a screen. The
color you view on the screen is produced by a blend of red, blue and green light.

Components of CRT:
Main Components of CRT are:

1. Electron Gun: Electron gun consisting of a series of elements, primarily a heating filament
(heater) and a cathode. The electron gun creates a source of electrons which are focused into a
narrow beam directed at the face of the CRT.

2. Control Electrode: It is used to turn the electron beam on and off.

3. Focusing system: It is used to create a clear picture by focusing the electrons into a narrow
beam.

4. Deflection Yoke: It is used to control the direction of the electron beam. It creates an electric
or magnetic field which will bend the electron beam as it passes through the area. In a
conventional CRT, the yoke is linked to a sweep or scan generator. The deflection yoke which is
connected to the sweep generator creates a fluctuating electric or magnetic potential.
5. Phosphorus-coated screen: The inside front surface of every CRT is coated with phosphors.
Phosphors glow when a high-energy electron beam hits them. Phosphorescence is the term used
to characterize the light given off by a phosphor after it has been exposed to an electron beam.

Random Scan and Raster Scan Display:


Random Scan Display:
Random Scan System uses an electron beam which operates like a pencil to create a line image
on the CRT screen. The picture is constructed out of a sequence of straight-line segments. Each
line segment is drawn on the screen by directing the beam to move from one point on the screen
to the next, where its x & y coordinates define each point. After drawing the picture. The system
cycles back to the first line and design all the lines of the image 30 to 60 time each second. The
process is shown in fig:

Random-scan monitors are also known as vector displays or stroke-writing displays or


calligraphic displays.

Advantages:
1. A CRT has the electron beam directed only to the parts of the screen where an image is to be
drawn.
2. Produce smooth line drawings.
3. High Resolution
Disadvantages:
1. Random-Scan monitors cannot display realistic shades scenes.

Raster Scan Display:


A Raster Scan Display is based on intensity control of pixels in the form of a rectangular box
called Raster on the screen. Information of on and off pixels is stored in refresh buffer or Frame
buffer. Televisions in our house are based on Raster Scan Method. The raster scan system can
store information of each pixel position, so it is suitable for realistic display of objects. Raster
Scan provides a refresh rate of 60 to 80 frames per second.

Frame Buffer is also known as Raster or bit map. In Frame Buffer the positions are called picture
elements or pixels. Beam refreshing is of two types. First is horizontal retracing and second is
vertical retracing. When the beam starts from the top left corner and reaches the bottom right
scale, it will again return to the top left side called at vertical retrace. Then it will again more
horizontally from top to bottom call as horizontal retracing shown in fig:

Types of Scanning or travelling of beam in Raster Scan

1. Interlaced Scanning
2. Non-Interlaced Scanning

In Interlaced scanning, each horizontal line of the screen is traced from top to bottom. Due to
which fading of display of object may occur. This problem can be solved by Non-Interlaced
scanning. In this first of all odd numbered lines are traced or visited by an electron beam, then in
the next circle, even number of lines are located.
For non-interlaced display refresh rate of 30 frames per second used. But it gives flickers. For
interlaced display refresh rate of 60 frames per second is used.

Advantages:
1. Realistic image
2. Million Different colors to be generated
3. Shadow Scenes are possible.

Disadvantages:
1. Low Resolution
2. Expensive

Differentiate between Random and Raster Scan Display:


Random Scan Raster Scan

1. It has high Resolution 1. Its resolution is low.

2. It is more expensive 2. It is less expensive

3. Any modification if needed is easy 3.Modification is tough

4. Solid pattern is tough to fill 4.Solid pattern is easy to fill

5. Refresh rate depends or resolution 5. Refresh rate does not depend on the picture.

6. Only screen with view on an area is displayed. 6. Whole screen is scanned.

7. Beam Penetration technology come under it. 7. Shadow mark technology came under this.

8. It does not use interlacing method. 8. It uses interlacing

9. It is restricted to line drawing applications 9. It is suitable for realistic display.


Color CRT Monitors:
The CRT Monitor display by using a combination of phosphors. The phosphors are different
colors. There are two popular approaches for producing color displays with a CRT are:

1. Beam Penetration Method


2. Shadow-Mask Method

1. Beam Penetration Method:


The Beam-Penetration method has been used with random-scan monitors. In this method, the
CRT screen is coated with two layers of phosphor, red and green and the displayed color
depends on how far the electron beam penetrates the phosphor layers. This method produces four
colors only, red, green, orange and yellow. A beam of slow electrons excites the outer red layer
only; hence screen shows red color only. A beam of high-speed electrons excites the inner green
layer. Thus screen shows a green color.

Advantages:
1. Inexpensive

Disadvantages:
1. Only four colors are possible
2. Quality of pictures is not as good as with another method.

2. Shadow-Mask Method:
o Shadow Mask Method is commonly used in Raster-Scan System because they produce a much
wider range of colors than the beam-penetration method.
o It is used in the majority of color TV sets and monitors.

Construction: A shadow mask CRT has 3 phosphor color dots at each pixel position.

o One phosphor dot emits: red light


o Another emits: green light
o Third emits: blue light

This type of CRT has 3 electron guns, one for each color dot and a shadow mask grid just behind
the phosphor coated screen.

Shadow mask grid is pierced with small round holes in a triangular pattern.

Figure shows the delta-delta shadow mask method commonly used in color CRT system.
Working: Triad arrangement of red, green, and blue guns.

The deflection system of the CRT operates on all 3 electron beams simultaneously; the 3 electron
beams are deflected and focused as a group onto the shadow mask, which contains a sequence of
holes aligned with the phosphor- dot patterns.
When the three beams pass through a hole in the shadow mask, they activate a dotted triangle,
which occurs as a small color spot on the screen.

The phosphor dots in the triangles are organized so that each electron beam can activate only its
corresponding color dot when it passes through the shadow mask.

Inline arrangement: Another configuration for the 3 electron guns is an Inline arrangement in
which the 3 electron guns and the corresponding red-green-blue color dots on the screen, are
aligned along one scan line rather of in a triangular pattern.

This inline arrangement of electron guns in easier to keep in alignment and is commonly used in
high-resolution color CRT's.

Advantage:
1. Realistic image
2. Million different colors to be generated
3. Shadow scenes are possible

Disadvantage:
1. Relatively expensive compared with the monochrome CRT.
2. Relatively poor resolution
3. Convergence Problem

Direct View Storage Tubes(DVST) :


DVST terminals also use the random scan approach to generate the image on the CRT screen.
The term "storage tube" refers to the ability of the screen to retain the image which has been
projected against it, thus avoiding the need to rewrite the image constantly.

Function of guns: Two guns are used in DVST

1. Primary guns: It is used to store the picture pattern.


2. Flood gun or Secondary gun: It is used to maintain picture display.

Advantage:
1. No refreshing is needed.
2. High Resolution
3. Cost is very less

Disadvantage:
1. It is not possible to erase the selected part of a picture.
2. It is not suitable for dynamic graphics applications.
3. If a part of picture is to modify, then time is consumed.

Flat Panel Display:


The Flat-Panel display refers to a class of video devices that have reduced volume,
weight and power requirement compare to CRT.
Example: Small T.V. monitor, calculator, pocket video games, laptop computers, an
advertisement board in elevator.

1. Emissive Display: The emissive displays are devices that convert electrical energy into
light. Examples are Plasma Panel, thin film electroluminescent display and LED (Light
Emitting Diodes).

2. Non-Emissive Display: The Non-Emissive displays use optical effects to convert sunlight
or light from some other source into graphics patterns. Examples are LCD (Liquid Crystal
Device).

Plasma Panel Display:


Plasma-Panels are also called as Gas-Discharge Display. It consists of an array of small lights.
Lights are fluorescent in nature. The essential components of the plasma-panel display are:

1. Cathode: It consists of fine wires. It delivers negative voltage to gas cells. The voltage is released
along with the negative axis.
2. Anode: It also consists of line wires. It delivers positive voltage. The voltage is supplied along
positive axis.
3. Fluorescent cells: It consists of small pockets of gas liquids when the voltage is applied to this
liquid (neon gas) it emits light.
4. Glass Plates: These plates act as capacitors. The voltage will be applied, the cell will glow
continuously.

The gas will slow when there is a significant voltage difference between horizontal and vertical
wires. The voltage level is kept between 90 volts to 120 volts. Plasma level does not require
refreshing. Erasing is done by reducing the voltage to 90 volts.

Each cell of plasma has two states, so cell is said to be stable. Displayable point in plasma panel
is made by the crossing of the horizontal and vertical grid. The resolution of the plasma panel
can be up to 512 * 512 pixels.

Figure shows the state of cell in plasma panel display:

Advantage:
1. High Resolution
2. Large screen size is also possible.
3. Less Volume
4. Less weight
5. Flicker Free Display

Disadvantage:
1. Poor Resolution
2. Wiring requirement anode and the cathode is complex.
3. Its addressing is also complex.

LED (Light Emitting Diode):


In an LED, a matrix of diodes is organized to form the pixel positions in the display and picture
definition is stored in a refresh buffer. Data is read from the refresh buffer and converted to
voltage levels that are applied to the diodes to produce the light pattern in the display.

LCD (Liquid Crystal Display):


Liquid Crystal Displays are the devices that produce a picture by passing polarized light from the
surroundings or from an internal light source through a liquid-crystal material that transmits the
light.

LCD uses the liquid-crystal material between two glass plates; each plate is the right angle to
each other between plates liquid is filled. One glass plate consists of rows of conductors arranged
in vertical direction. Another glass plate is consisting of a row of conductors arranged in
horizontal direction. The pixel position is determined by the intersection of the vertical &
horizontal conductor. This position is an active part of the screen.

Liquid crystal display is temperature dependent. It is between zero to seventy degree Celsius. It
is flat and requires very little power to operate.
Advantage:
1. Low power consumption.
2. Small Size
3. Low Cost

Disadvantage:
1. LCDs are temperature-dependent (0-70°C)
2. LCDs do not emit light; as a result, the image has very little contrast.
3. LCDs have no color capability.
4. The resolution is not as good as that of a CRT.

Look-Up Table:
Image representation is essentially the description of pixel colors. There are three primary colors:
R (red), G (green) and B (blue). Each primary color can take on intensity levels produces a
variety of colors. Using direct coding, we may allocate 3 bits for each pixel, with one bit for each
primary color. The 3-bit representation allows each primary to vary independently between two
intensity levels: 0 (off) or 1 (on). Hence each pixel can take on one of the eight colors.

Bit 1:r Bit 2:g Bit 3:b Color name

0 0 0 Black

0 0 1 Blue

0 1 0 Green

0 1 1 Cyan

1 0 0 Red

1 0 1 Magenta

1 1 0 Yellow

1 1 1 White

A widely accepted industry standard uses 3 bytes, or 24 bytes, per pixel, with one byte for each
primary color. The way, we allow each primary color to have 256 different intensity levels. Thus
a pixel can take on a color from 256 x 256 x 256 or 16.7 million possible choices. The 24-bit
format is commonly referred to as the actual color representation.

Lookup Table approach reduces the storage requirement. In this approach pixel values do not
code colors directly. Alternatively, they are addresses or indices into a table of color values. The
color of a particular pixel is determined by the color value in the table entry that the value of the
pixel references. Figure shows a look-up table with 256 entries. The entries have addresses 0
through 255. Each entry contains a 24-bit RGB color value. Pixel values are now 1-byte. The
color of a pixel whose value is i, where 0 <i<255, is persistence by the color value in the table
entry whose address is i. It reduces the storage requirement of a 1000 x 1000 image to one
million bytes plus 768 bytes for the color values in the look-up table.
Input Devices
The Input Devices are the hardware that is used to transfer transfers input to the computer. The
data can be in the form of text, graphics, sound, and text. Output device display data from the
memory of the computer. Output can be text, numeric data, line, polygon, and other objects.
These Devices include:

1. Keyboard
2. Mouse
3. Trackball
4. Spaceball
5. Joystick
6. Light Pen
7. Digitizer
8. Touch Panels
9. Voice Recognition
10. Image Scanner
Keyboard:
The most commonly used input device is a keyboard. The data is entered by pressing the set of
keys. All keys are labeled. A keyboard with 101 keys is called a QWERTY keyboard.

The keyboard has alphabetic as well as numeric keys. Some special keys are also available.

1. Numeric Keys: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
2. Alphabetic keys: a to z (lower case), A to Z (upper case)
3. Special Control keys: Ctrl, Shift, Alt
4. Special Symbol Keys: ; , " ? @ ~ ? :
5. Cursor Control Keys: ↑ → ← ↓
6. Function Keys: F1 F2 F3....F9.
7. Numeric Keyboard: It is on the right-hand side of the keyboard and used for fast entry of
numeric data.

Function of Keyboard:
1. Alphanumeric Keyboards are used in CAD. (Computer Aided Drafting)
2. Keyboards are available with special features line screen co-ordinates entry, Menu selection or
graphics functions, etc.
3. Special purpose keyboards are available having buttons, dials, and switches. Dials are used to
enter scalar values. Dials also enter real numbers. Buttons and switches are used to enter
predefined function values.

Advantage:
1. Suitable for entering numeric data.
2. Function keys are a fast and effective method of using commands, with fewer errors.

Disadvantage:
1. Keyboard is not suitable for graphics input.
Mouse:
A Mouse is a pointing device and used to position the pointer on the screen. It is a small palm
size box. There are two or three depression switches on the top. The movement of the mouse
along the x-axis helps in the horizontal movement of the cursor and the movement along the y-
axis helps in the vertical movement of the cursor on the screen. The mouse cannot be used to
enter text. Therefore, they are used in conjunction with a keyboard.

Advantage:
1. Easy to use
2. Not very expensive

Trackball
It is a pointing device. It is similar to a mouse. This is mainly used in notebook or laptop
computer, instead of a mouse. This is a ball which is half inserted, and by changing fingers on
the ball, the pointer can be moved.
Advantage:
1. Trackball is stationary, so it does not require much space to use it.
2. Compact Size

Spaceball:
It is similar to trackball, but it can move in six directions where trackball can move in two
directions only. The movement is recorded by the strain gauge. Strain gauge is applied with
pressure. It can be pushed and pulled in various directions. The ball has a diameter around 7.5
cm. The ball is mounted in the base using rollers. One-third of the ball is an inside box, the rest is
outside.

Applications:
1. It is used for three-dimensional positioning of the object.
2. It is used to select various functions in the field of virtual reality.
3. It is applicable in CAD applications.
4. Animation is also done using spaceball.
5. It is used in the area of simulation and modeling.
Joystick:
A Joystick is also a pointing device which is used to change cursor position on a monitor screen.
Joystick is a stick having a spherical ball as its both lower and upper ends as shown in fig. The
lower spherical ball moves in a socket. The joystick can be changed in all four directions. The
function of a joystick is similar to that of the mouse. It is mainly used in Computer Aided
Designing (CAD) and playing computer games.

Light Pen
Light Pen (similar to the pen) is a pointing device which 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 its tip is moved over the monitor screen, and pen button is pressed, its
photocell sensing element detects the screen location and sends the corresponding signals to the
CPU.
Uses:
1. Light Pens can be used as input coordinate positions by providing necessary arrangements.
2. If background color or intensity, a light pen can be used as a locator.
3. It is used as a standard pick device with many graphics system.
4. It can be used as stroke input devices.
5. It can be used as valuators

Digitizers:
The digitizer is an operator input device, which contains a large, smooth board (the appearance is
similar to the mechanical drawing board) & an electronic tracking device, which can be changed
over the surface to follow existing lines. The electronic tracking device contains a switch for the
user to record the desire x & y coordinate positions. The coordinates can be entered into the
computer memory or stored or an off-line storage medium such as magnetic tape.
Advantages:
1. Drawing can easily be changed.
2. It provides the capability of interactive graphics.

Disadvantages:
1. Costly
2. Suitable only for applications which required high-resolution graphics.

Touch Panels:
Touch Panels is a type of display screen that has a touch-sensitive transparent panel covering the
screen. A touch screen registers input when a finger or other object comes in contact with the
screen.

When the wave signals are interrupted by some contact with the screen, that located is recorded.
Touch screens have long been used in military applications.
Voice Systems (Voice Recognition):
Voice Recognition is one of the newest, most complex input techniques used to interact with the
computer. The user inputs data by speaking into a microphone. The simplest form of voice
recognition is a one-word command spoken by one person. Each command is isolated with
pauses between the words.

Voice Recognition is 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.

Advantage:
1. More efficient device.
2. Easy to use
3. Unauthorized speakers can be identified

Disadvantages:
1. Very limited vocabulary
2. Voice of different operators can't be distinguished.

Image Scanner
It is an input device. The data or text is written on paper. The paper is feeded to scanner. The
paper written information is converted into electronic format; this format is stored in the
computer. The input documents can contain text, handwritten material, picture extra.

By storing the document in a computer document became safe for longer period of time. The
document will be permanently stored for the future. We can change the document when we need.
The document can be printed when needed.

Scanning can be of the black and white or colored picture. On stored picture 2D or 3D rotations,
scaling and other operations can be applied.

Types of image Scanner:


1. Flat Bed Scanner: It resembles a photocopy machine. It has a glass top on its top. Glass top
in further covered using a lid. The document to be scanned is kept on glass plate. The light is
passed underneath side of glass plate. The light is moved left to right. The scanning is done the
line by line. The process is repeated until the complete line is scanned. Within 20-25 seconds a
document of 4" * 6" can be scanned.
2. Hand Held Scanner: It has a number of LED's (Light Emitting Diodes) the LED's are
arranged in the small case. It is called a Hand held Scanner because it can be kept in hand which
performs scanning. For scanning the scanner is moved over document from the top towards the
bottom. Its light is on, while we move it on document. It is dragged very slowly over document.
If dragging of the scanner over the document is not proper, the conversion will not correct.

Output Devices
It is an electromechanical device, which accepts data from a computer and translates them into
form understand by users.

Following are Output Devices:

1. Printers
2. Plotters

Printers:
Printer is the most important output device, which is used to print data on paper.

Types of Printers: There are many types of printers which are classified on various criteria as
shown in fig:
1. Impact Printers: The printers that print the characters by striking against the ribbon and onto
the papers are known as Impact Printers.

These Printers are of two types:

1. Character Printers

2. Line Printers

2. Non-Impact Printers: The printers that print the characters without striking against the
ribbon and onto the papers are called Non-Impact Printers. These printers print a complete page
at a time, therefore, also known as Page Printers.

Page Printers are of two types:


1. Laser Printers
2. Inkjet Printers

Dot Matrix Printers:


Dot matrix has printed in the form of dots. A printer has a head which contains nine pins. The
nine pins are arranged one below other. Each pin can be activated independently. All or only the
same needles are activated at a time. When needless is not activated, and then the tip of needle
stay in the head. When pin work, it comes out of the print head. In nine pin printer, pins are
arranged in 5 * 7 matrixes.
Advantage:
1. Dot Matrix Printers prints output as dots, so it can print any shape of the character. This allows
the printer to print special character, charts, graphs, etc.
2. Dot Matrix Printers come under the category of impact printers. The printing is done when the
hammer pin strikes the inked ribbon. The impressions are printed on paper. By placing multiple
copies of carbon, multiple copies of output can be produced.
3. It is suitable for printing of invoices of companies.

Daisy Wheel Printers:


Head is lying on a wheel and Pins corresponding to characters are like petals of Daisy, that's why
called Daisy wheel printer.

Advantage:
1. More reliable than DMPs
2. Better Quality
Disadvantage:
1. Slower than DMPs

Drum Printers:
These are line printers, which prints one line at a time. It consists of a drum. The shape of the
drum is cylindrical. The drum is solid and has characters embossed on it in the form of vertical
bands. The characters are in circular form. Each band consists of some characters. Each line on
drum consists of 132 characters. Because there are 96 lines so total characters are (132 * 95) =
12, 672.

Drum contains a number of hammers also.

Chain Printers:
These are called as line printers. These are used to print one line at a line. Basically, chain
consists of links. Each link contains one character. Printers can follow any character set style,
i.e., 48, 64 or 96 characters. Printer consists of a number of hammers also.

Advantages:
1. Chain or Band if damaged can be changed easily.
2. It allows printing of different form.
3. Different Scripts can be printed using this printer.

Disadvantages:
1. It cannot print charts and graphs.
2. It cannot print characters of any shape.
3. Chain Printers is impact printer, hammer strikes so it is noisy.

Non-Impact Printers:
Inkjet Printers:
These printers use a special link called electrostatic ink. The printer head has a special nozzle.
Nozzle drops ink on paper. Head contains up to 64 nozzles. The ink dropped is deflected by the
electrostatic plate. The plate is fixed outside the nozzle. The deflected ink settles on paper.
Advantages:
1. These produce high quality of output as compared to the dot matrix.
2. A high-quality output can be produced using 64 nozzles printed.
3. Inkjet can print characters in a variety of shapes.
4. Inkjet can print special characters.
5. The printer can print graphs and charts.

Disadvantages:
1. Inkjet Printers are slower than dot matrix printers.
2. The cost of inkjet is more than a dot matrix printer.

Laser Printers:
These are non-impact page printers. They use laser lights to produces the dots needed to form the
characters to be printed on a page & hence the name laser printers.

The output is generated in the following steps:


Step1: The bits of data sent by processing unit act as triggers to turn the laser beam on & off.

Step2: The output device has a drum which is cleared & is given a positive electric charge. To
print a page the modulated laser beam passing from the laser scans back & forth the surface of
the drum. The positive electric charge on the drum is stored on just those parts of the drum
surface which are exposed to the laser beam create the difference in electric which charges on the
exposed drum surface.

Step3: The laser exposed parts of the drum attract an ink powder known as toner.

Step4: The attracted ink powder is transferred to paper.

Step5: The ink particles are permanently fixed to the paper by using either heat or pressure
technique.

Step6: The drum rotates back to the cleaner where a rubber blade cleans off the excess ink &
prepares the drum to print the next page.

Plotters
Plotters are a special type of output device. It is suitable for applications:
1. Architectural plan of the building.
2. CAD applications like the design of mechanical components of aircraft.
3. Many engineering applications.

Advantage:
1. It can produce high-quality output on large sheets.
2. It is used to provide the high precision drawing.
3. It can produce graphics of various sizes.
4. The speed of producing output is high.

Drum Plotter:
It consists of a drum. Paper on which design is made is kept on the drum. The drum can rotate in
both directions. Plotters comprised of one or more pen and penholders. The holders are mounted
perpendicular to drum surface. The pens are kept in the holder, which can move left to the right
as well as right to the left. The graph plotting program controls the movement of pen and drum.
Flatbed Plotter:
It is used to draw complex design and graphs, charts. The Flatbed plotter can be kept over the
table. The plotter consists of pen and holder. The pen can draw characters of various sizes. There
can be one or more pens and pen holding mechanism. Each pen has ink of different color.
Different colors help to produce multicolor design of document. The area of plotting is also
variable. It can vary A4 to 21'*52'.
It is used to draw

1. Cars
2. Ships
3. Airplanes
4. Shoe and dress designing
5. Road and highway design

Graphics Software:
There are two types of Graphics Software.

1. General Purpose Packages: 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.

Example of general purpose package is the GL (Graphics Library), GKS, PHIGS, PHIGS+ etc.
2. Special Purpose Packages: These packages are designed for non programmers, so that these
users can use the graphics packages, without knowing the inner details.

Example of special purpose package is

1. Painting programs
2. Package used for business purpose
3. Package used for medical systems.
4. CAD packages

Computer Graphics Packages (Software):


1. LOGO
2. COREL DRAW
3. AUTO CAD
4. 3D STUDIO
5. CORE
6. GKS (Graphics Kernel System)
7. PHIGS
8. CAM (Computer Graphics Metafile)
9. CGI (Computer Graphics Interface)
UNIT-2
UNIT-3
UNIT-4
2D Viewing and Clipping Techniques

Computer Graphics Window:


The method of selecting and enlarging a portion of a drawing is called windowing. The
area chosen for this display is called a window. The window is selected by world-
coordinate.

Sometimes we are interested in some portion of the object and not in full object. So we
will decide on an imaginary box. This box will enclose desired or interested area of the
object. Such an imaginary box is called a window.

Viewport: An area on display device to which a window is mapped [where it is to


displayed].

Basically, the window is an area in object space. It encloses the object. After the user
selects this, space is mapped on the whole area of the viewport. Almost all 2D and 3D
graphics packages provide means of defining viewport size on the screen. It is possible
to determine many viewports on different areas of display and view the same object in a
different angle in each viewport.

The size of the window is (0, 0) coordinate which is a bottom-left corner and toward
right side until window encloses the desired area. Once the window is defined data
outside the window is clipped before representing to screen coordinates. This process
reduces the amount of data displaying signals.

The window size of the Tektronix 4.14 tube in Imperial College contains 4.96 points
horizontally and 3072 points vertically.

Viewing transformation or window to viewport transformation or windowing


transformation: The mapping of a part of a world-coordinate scene to device
coordinates is referred to as a viewing transformation etc.
Viewing transformation in several steps:

First, we construct the scene in world coordinate using the output primitives and
attributes.

To obtain a particular orientation, we can set up a 2-D viewing coordinate system in the
window coordinate plane and define a window in viewing coordinates system.

Once the viewing frame is established, are then transform description in world
coordinates to viewing coordinates.

Then, we define viewport in normalized coordinates (range from 0 to 1) and map the
viewing coordinates description of the scene to normalized coordinates.

At the final step, all parts of the picture that (i.e., outside the viewport are dipped, and
the contents are transferred to device coordinates).

By changing the position of the viewport:We can view objects at different locations
on the display area of an output device as shown in fig:
By varying the size of viewports: We can change the size and proportions of displayed
objects. We can achieve zooming effects by successively mapping different-sized
windows on a fixed-size viewport.

As the windows are made smaller, we zoom in on some part of a scene to view details
that are not shown with larger windows.
Computer Graphics Window to Viewport Co-
ordinate Transformation
Once object description has been transmitted to the viewing reference frame, we
choose the window extends in viewing coordinates and selects the viewport limits in
normalized coordinates.

Object descriptions are then transferred to normalized device coordinates:

We do this thing using a transformation that maintains the same relative placement of
an object in normalized space as they had in viewing coordinates.

If a coordinate position is at the center of the viewing window:

It will display at the center of the viewport.

Fig shows the window to viewport mapping. A point at position (xw, yw) in window
mapped into position (xv, yv) in the associated viewport.
In order to maintain the same relative placement of the point in the viewport as in the
window, we require:

Solving these impressions for the viewport position (xv, yv), we have

xv=xvmin+(xw-xwmin)sx
yv=yvmin+(yw-ywmin)sy ...........equation 2

Where scaling factors are


Equation (1) and Equation (2) can also be derived with a set of transformation that
converts the window or world coordinate area into the viewport or screen coordinate
area. This conversation is performed with the following sequence of transformations:

1. Perform a scaling transformation using a fixed point position (xwmin,ywmin) that


scales the window area to the size of the viewport.
2. Translate the scaled window area to the position of the viewport. Relative
proportions of objects are maintained if the scaling factors are the same (sx=sy).

From normalized coordinates, object descriptions are mapped to the various display
devices.

Any number of output devices can we open in a particular app, and three windows to
viewport transformation can be performed for each open output device.

This mapping called workstation transformation (It is accomplished by selecting a


window area in normalized space and a viewport area in the coordinates of the display
device).

As in fig, workstation transformation to partition a view so that different parts of


normalized space can be displayed on various output devices).
Matrix Representation of the above three steps of
Transformation:
Step1:Translate window to origin 1
Tx=-Xwmin Ty=-Ywmin

Step2:Scaling of the window to match its size to the viewport


Sx=(Xymax-Xvmin)/(Xwmax-Xwmin)
Sy=(Yvmax-Yvmin)/(Ywmax-Ywmin)

Step3:Again translate viewport to its correct position on screen.


Tx=Xvmin
Ty=Yvmin

Above three steps can be represented in matrix form:


VT=T * S * T1

T = Translate window to the origin

S=Scaling of the window to viewport size

T1=Translating viewport on screen.

Viewing Transformation= T * S * T1

Advantage of Viewing Transformation:


We can display picture at device or display system according to our need and choice.

o World coordinate system is selected suits according to the application program.


o Screen coordinate system is chosen according to the need of design.
o Viewing transformation is selected as a bridge between the world and screen
coordinate.

Clipping:
When we have to display a large portion of the picture, then not only scaling &
translation is necessary, the visible part of picture is also identified. This process is not
easy. Certain parts of the image are inside, while others are partially inside. The lines or
elements which are partially visible will be omitted.

For deciding the visible and invisible portion, a particular process called clipping is used.
Clipping determines each element into the visible and invisible portion. Visible portion is
selected. An invisible portion is discarded.

Types of Lines:
Lines are of three types:

1. Visible: A line or lines entirely inside the window is considered visible


2. Invisible: A line entirely outside the window is considered invisible
3. Clipped: A line partially inside the window and partially outside is clipped. For clipping
point of intersection of a line with the window is determined.
Clipping can be applied through hardware as well as software. In some computers,
hardware devices automatically do work of clipping. In a system where hardware
clipping is not available software clipping applied.

Following figure show before and after clipping

The window against which object is clipped called a clip window. It can be curved or
rectangle in shape.

Applications of clipping:
1. It will extract part we desire.
2. For identifying the visible and invisible area in the 3D object.
3. For creating objects using solid modeling.
4. For drawing operations.
5. Operations related to the pointing of an object.
6. For deleting, copying, moving part of an object.

Clipping can be applied to world co-ordinates. The contents inside the window will be
mapped to device co-ordinates. Another alternative is a complete world co-ordinates
picture is assigned to device co-ordinates, and then clipping of viewport boundaries is
done.
Types of Clipping:
1. Point Clipping
2. Line Clipping
3. Area Clipping (Polygon)
4. Curve Clipping
5. Text Clipping
6. Exterior Clipping

Point Clipping:
Point Clipping is used to determining, whether the point is inside the window or not. For
this following conditions are checked.

1. x ≤ xmax
2. x ≥ xmin
3. y ≤ ymax
4. y ≥ ymin

The (x, y) is coordinate of the point. If anyone from the above inequalities is false, then
the point will fall outside the window and will not be considered to be visible.

Program1:
To implement Point Clipping:
1. #include<stdio.h>
2. #include<conio.h>
3. #include<graphics.h>
4. inttlx,tly,brx,bry,px,py;
5. void point_clip()
6. {
7. intwxmin,wymin,wxmax,wymax;
8. wxmin=tlx;
9. wxmax=brx;
10. wymin=tly;
11. wymax=bry;
12. if(px>=wxmin&&px<=wxmax)
13. if(py>=wymin&&py<=wymax)
14. putpixel(px,py,RED);
15. getch();
16. closegraph();
17. }
18. void main()
19. {
20. intgd=DETECT,gm,xc,yc,r;
21. clrscr();
22. printf("Enter the top left coordinate");
23. scanf("%d%d",&tlx,&tly);
24. printf("Enter the bottom right coordinate");
25. scanf("%d%d",&brx,&bry);
26. printf("\n Enter the point");
27. scanf("%d%d",&px,&py);
28. initgraph(&gd,&gm,"c:\\tc\\bgi");
29. setbkcolor(BLUE);
30. setcolor(RED);
31. rectangle(tlx,tly,brx,bry);
32. point_clip();
33. }
Output:

Program2:
To implement point clipping with respect to rectangular window:

1. #include<stdio.h>
2. #include<conio.h>
3. #include<graphics.h>
4. void main()
5. {
6. int gm,gr,xcmin,ycmin,xcmax,ycmax,x,y,c;
7. clrscr();
8. detectgraph(&gm,&gr);
9. initgraph(&gm,&gr,"c:\\tc\\BGI");
10. printf("Enter the clipmin coordinate :\n");
11. scanf("%d%d",&xcmin,&ycmin);
12. printf("Enter the clipmax coordinate :\n");
13. scanf("%d%d",&xcmax,&ycmax);
14. rectangle(xcmin,ycmax,xcmax,ycmin);
15. printf("Enter the coordinate of the point:\n");
16. scanf("%d%d",&x,&y);
17. detectgraph(&gm,&gr);
18. initgraph(&gm,&gr,"c:\\tc\\BGI");
19. putpixel(x,y,15);
20. printf("\n1.Point clipping\n2.Exit\nEnter your choice:\n");
21. scanf("%d",&c);
22. switch(c)
23. {
24. case 1:
25. detectgraph(&gm,&gr);
26. initgraph(&gm,&gr,"d:\\tc\\BGI");
27. rectangle (xcmin,ycmax,xcmax,ycmin);
28. printf("*******POINT CLIPPING******\n");
29. if ((xcmin<x) && (x<xcmax))
30. {
31. if ((ycmin<y) && (y<ycmax))
32. {
33. printf("The point is inside the clip window\n");
34. putpixel(x,y,15);
35. }
36. }
37. else
38. printf("The point is outside the clipwindow \nThe point is clipped\n");
39. break;
40. case 2: exit(0);
41. }
42. getch();
43. }

Output:
Line Clipping:
It is performed by using the line clipping algorithm. The line clipping algorithms are:

1. Cohen Sutherland Line Clipping Algorithm


2. Midpoint Subdivision Line Clipping Algorithm
3. Liang-Barsky Line Clipping Algorithm

Cohen Sutherland Line Clipping Algorithm:


In the algorithm, first of all, it is detected whether line lies inside the screen or it is
outside the screen. All lines come under any one of the following categories:

1. Visible
2. Not Visible
3. Clipping Case

1. Visible: If a line lies within the window, i.e., both endpoints of the line lies within the
window. A line is visible and will be displayed as it is.

2. Not Visible: If a line lies outside the window it will be invisible and rejected. Such
lines will not display. If any one of the following inequalities is satisfied, then the line is
considered invisible. Let A (x1,y2) and B (x2,y2) are endpoints of line.

xmin,xmax are coordinates of the window.

ymin,ymax are also coordinates of the window.


x1>xmax
x2>xmax
y1>ymax
y2>ymax
x1<xmin
x2<xmin
y1<ymin
y2<ymin

3. Clipping Case: If the line is neither visible case nor invisible case. It is considered to
be clipped case. First of all, the category of a line is found based on nine regions given
below. All nine regions are assigned codes. Each code is of 4 bits. If both endpoints of
the line have end bits zero, then the line is considered to be visible.

The center area is having the code, 0000, i.e., region 5 is considered a rectangle window.

Following figure show lines of various types

Line AB is the visible case


Line OP is an invisible case
Line PQ is an invisible line
Line IJ are clipping candidates
Line MN are clipping candidate
Line CD are clipping candidate
Advantage of Cohen Sutherland Line Clipping:
1. It calculates end-points very quickly and rejects and accepts lines quickly.
2. It can clip pictures much large than screen size.

Algorithm of Cohen Sutherland Line Clipping:


Step 1: Calculate positions of both endpoints of the line

Step 2: Perform OR operation on both of these end-points

Step 3: If the OR operation gives 0000


Then
line is considered to be visible
else
Perform AND operation on both endpoints
If And ≠ 0000
then the line is invisible
else
And=0000
Line is considered the clipped case.

Step 4: If a line is clipped case, find an intersection with boundaries of the window
m=(y2-y1 )(x2-x1)

(a) If bit 1 is "1" line intersects with left boundary of rectangle window
y3=y1+m(x-X1)
where X = Xwmin
where Xwminis the minimum value of X co-ordinate of window

(b) If bit 2 is "1" line intersect with right boundary


y3=y1+m(X-X1)
where X = Xwmax
where X more is maximum value of X co-ordinate of the window

(c) If bit 3 is "1" line intersects with bottom boundary


X3=X1+(y-y1)/m
where y = ywmin
ywmin is the minimum value of Y co-ordinate of the window

(d) If bit 4 is "1" line intersects with the top boundary


X3=X1+(y-y1)/m
where y = ywmax
ywmax is the maximum value of Y co-ordinate of the window

Example of Cohen-Sutherland Line Clipping Algorithm:


Let R be the rectangular window whose lower left-hand corner is at L (-3, 1) and upper
right-hand corner is at R (2, 6). Find the region codes for the endpoints in fig:

The region code for point (x, y) is set according to the scheme
Bit 1 = sign (y-ymax)=sign (y-6) Bit 3 = sign (x-xmax)= sign (x-2)
Bit 2 = sign (ymin-y)=sign(1-y) Bit 4 = sign (xmin-x)=sign(-3-x)

Here
So

A (-4, 2)→ 0001 F (1, 2)→ 0000


B (-1, 7) → 1000 G (1, -2) →0100
C (-1, 5)→ 0000 H (3, 3) → 0100
D (3, 8) → 1010 I (-4, 7) → 1001
E (-2, 3) → 0000 J (-2, 10) → 1000

We place the line segments in their appropriate categories by testing the region codes
found in the problem.

Category1 (visible): EF since the region code for both endpoints is 0000.

Category2 (not visible): IJ since (1001) AND (1000) =1000 (which is not 0000).

Category 3 (candidate for clipping): AB since (0001) AND (1000) = 0000, CD since
(0000) AND (1010) =0000, and GH. since (0100) AND (0010) =0000.

The candidates for clipping are AB, CD, and GH.

In clipping AB, the code for A is 0001. To push the 1 to 0, we clip against the boundary
line xmin=-3. The resulting intersection point is I1 (-3,3 ). We clip (do not
display) AI 1 and I1 B. The code for I1is 1001. The clipping category for I 1 B is 3 since
(0000) AND (1000) is (0000). Now B is outside the window (i.e., its code is 1000), so we
push the 1 to a 0 by clipping against the line y max=6. The resulting intersection is l2 (-1
,6). Thus I2 B is clipped. The code for I2 is 0000. The remaining segment I1 I2 is displayed
since both endpoints lie in the window (i.e., their codes are 0000).

For clipping CD, we start with D since it is outside the window. Its code is 1010. We push
the first 1 to a 0 by clipping against the line ymax=6. The resulting intersection I3 is (
,6),and its code is 0000. Thus I3 D is clipped and the remaining segment CI 3 has both
endpoints coded 0000 and so it is displayed.

For clipping GH, we can start with either G or H since both are outside the window. The
code for G is 0100, and we push the 1 to a 0 by clipping against the line y min=1.The
resulting intersection point is I4 (2 ,1) and its code is 0010. We clip GI 4 and work
on I 4 H. Segment I 4 H is not displaying since (0010) AND (0010) =0010.

Program to perform Line Clipping using Cohen Sutherland


Algorithm:
1. #include <iostream.h>
2. #include <conio.h>
3. #include <graphics.h>
4. #include <dos.h>
5. class data
6. {
7. int gd, gmode, x, y, xmin,ymin,ymax,xmax;
8. int a1,a2;
9. float x1, y1,x2,y2,x3,y3;
10. int xs, ys, xe, ye;
11. float maxx,maxy;
12. public:
13. void getdata ();
14. void find ();
15. void clip ();
16. void display (float, float,float,float);
17. void checkonof (int);
18. void showbit (int);
19. };
20. void data :: getdata ()
21. {
22. cout<<"Enter the minimum and maximum coordinate of window (x, y) ";
23. cin >>xmin>>ymin>>xmax>>ymax;
24. cout<<"Enter the end points of the line to be clipped";
25. cin >>xs>>ys>>xe>>ye;
26. display (xs, ys, xe,ye);
27. }
28. void data :: display (float, xs, float, ys,float xe, float ye)
29. {
30. int gd=DETECT;
31. initgraph (&gd,&gmode, "");
32. maxx=getmaxx();
33. maxy=getmaxy();
34. line (maxx/2,0,maxx/2,maxy);
35. line (0, maxy/2,maxx,maxy/2);
36. rectangle (maxx/2+xmin,maxy/2-ymax,maxx/2+xmax,maxy/2-ymin);
37. line (maxx/2+xs,maxy/2-ys,maxx/2+xe,maxy/2-ye);
38. getch();
39. }
40. void data :: find ()
41. {
42. a1=0;
43. a2=0;
44. if ((ys-ymax)>0)
45. a1+=8;
46. if ((ymin-ys)>0)
47. a1+=4;
48. if ((xs-xmax)>0)
49. a1+=2;
50. if ((xmin-xs)>0)
51. a1+=1;
52. if ((ye-ymax)>0)
53. a2+=8;
54. if ((ymin-ye)>0)
55. a2+=4;
56. if ((xe-xmax)>0)
57. a2+=2;
58. if ((xmin-xe)>0)
59. a2+=1;
60. cout<<"\nThe area code of Ist point is ";
61. showbit (a1);
62. getch ();
63. cout <<"\nThe area code of 2nd point is ";
64. showbit (a2);
65. getch ();
66. }
67. void data :: showbit (int n)
68. {
69. int i,k, and;
70. for (i=3;i>=0;i--)
71. {
72. and =1<<i;
73. k = n?
74. k ==0?cout<<"0": cout<<"1\"";
75. }
76. }
77. void data ::clip()
78. {
79. int j=a1&a2;
80. if (j==0)
81. {
82. cout<<"\nLine is perfect candidate for clipping";
83. if (a1==0)
84. {
85. else
86. {
87. checkonof(a1);
88. x2=x1;y2=y1;
89. }
90. if (a2=0)
91. {
92. x3=xe; y3=ye;
93. }
94. else
95. {
96. checkonof (a2);
97. x3=x1; y3=y1;
98. }
99. xs=x2; ys=y2;xe=x3;ye=y3;
100. cout << endl;
101. display (xs,ys,xe,ye);
102. cout<<"Line after clipping";
103. getch ()
104. }
105. else if ((a1==0) && (a2=0))
106. {
107. cout <<"\n Line is in the visible region";
108. getch ();
109. }
110. }
111. void data :: checkonof (int i)
112. {
113. int j, k,l,m;
114. 1=i&1;
115. x1=0;y1=0;
116. if (1==1)
117. {
118. x1=xmin;
119. y1=ys+ ((x1-xs)/ (xe-xs))*(ye-ys);
120. }
121. j=i&8;
122. if (j>0)
123. {
124. y1=ymax;
125. x1=xs+(y1-ys)/(ye-ys))*(xe-xs);
126. }
127. k=i & 4;
128. if (k==1)
129. {
130. y1=ymin;
131. x1=xs+((y1-ys)/(ye-ys))*(xe-xs);
132. }
133. m= i&2;
134. if (m==1)
135. {
136. x1=xmax;
137. y1=ys+ ((x1-xs)/ (xe-xs))*(ye-ys);
138. }
139. main ()
140. {
141. data s;
142. clrscr();
143. s.getdata();
144. s.find();
145. getch();
146. closegraph ();
147. return ();
148. }

Output:
Mid Point Subdivision Line Clipping Algorithm:
It is used for clipping line. The line is divided in two parts. Mid points of line is
obtained by dividing it in two short segments. Again division is done, by finding
midpoint. This process is continued until line of visible and invisible category is
obtained. Let (xi,yi) are midpoint

x5lie on point of intersection of boundary of window.

Advantage of midpoint subdivision Line Clipping:


It is suitable for machines in which multiplication and division operation is not
possible. Because it can be performed by introducing clipping divides in hardware.

Algorithm of midpoint subdivision Line Clipping:


Step1: Calculate the position of both endpoints of the line
Step2: Perform OR operation on both of these endpoints

Step3: If the OR operation gives 0000


then
Line is guaranteed to be visible
else
Perform AND operation on both endpoints.
If AND ≠ 0000
then the line is invisible
else
AND=6000
then the line is clipped case.

Step4: For the line to be clipped. Find midpoint


Xm=(x1+x2)/2
Ym=(y1+y2)/2
Xmis midpoint of X coordinate.
Ymis midpoint of Y coordinate.

Step5: Check each midpoint, whether it nearest to the boundary of a window or not.

Step6: If the line is totally visible or totally rejected not found then repeat step 1 to 5.

Step7: Stop algorithm.

Example: Window size is (-3, 1) to (2, 6). A line AB is given having co-ordinates of
A (-4, 2) and B (-1, 7). Does this line visible. Find the visible portion of the line using
midpoint subdivision?

Solution:

Step1: Fix point A (-4, 2)


Step2: Find b"=mid of b'and b

So (-1, 5) is better than (2, 4)


Find b"&bb"(-1, 5) b (-1, 7)

So B""to B length of line will be clipped from upper side


Now considered left-hand side portion.

A and B""are now endpoints

Find mid of A and B""

A (-4, 2) B ""(-1, 6)
Polygon:
Polygon is a representation of the surface. It is primitive which is closed in nature. It is
formed using a collection of lines. It is also called as many-sided figure. The lines
combined to form polygon are called sides or edges. The lines are obtained by
combining two vertices.

Example of Polygon:
1. Triangle
2. Rectangle
3. Pentagon
4. Hexagon
5. Quadrilaterals

Following figures shows some polygons.


Types of Polygons
1. Concave
2. Convex

A polygon is called convex of line joining any two interior points of the polygon lies
inside the polygon. A non-convex polygon is said to be concave. A concave polygon has
one interior angle greater than 180°. So that it can be clipped into similar polygons.
A polygon can be positive or negative oriented. If we visit vertices and vertices visit
produces counterclockwise circuit, then orientation is said to be positive.
Sutherland-Hodgeman Polygon Clipping:
It is performed by processing the boundary of polygon against each window corner or
edge. First of all entire polygon is clipped against one edge, then resulting polygon is
considered, then the polygon is considered against the second edge, so on for all four
edges.

Four possible situations conditions while processing

1. Case-1 (Out->In)

If the first vertex is an outside the window, the second vertex is inside the
window. Then second vertex is added to the output list. The point of intersection
of window boundary and polygon side (edge) is also added to the output line.

2. Case-2 (In->In)

If both vertexes are inside window boundary. Then only second vertex is added to
the output list.
3. Case-3 (In->Out)

If the first vertex is inside the window and second is an outside window. The edge
which intersects with window is added to output list.

4. Case-4 (Out->Out)

If both vertices are the outside window, then nothing is added to output list.
Following figures shows original polygon and clipping of polygon against four windows.

Disadvantage of Cohen Hodgmen Algorithm:


This method requires a considerable amount of memory. The first of all polygons are
stored in original form. Then clipping against left edge done and output is stored. Then
clipping against right edge done, then top edge. Finally, the bottom edge is clipped.
Results of all these operations are stored in memory. So wastage of memory for storing
intermediate polygons.

You might also like