Comp Graphics - Notes - All - Chaps
Comp Graphics - Notes - All - Chaps
1
storage hardwares – Hard disk and present different documents using text,
drives, flash memory, etc tables, graphs, images, pictures, etc.
o Software – different types of image - For this, many office automation softwares
processing softwares like Auto CAD, (MS-Word, Excel, Lotus Pro, Powerpoint) and
MATLAB, etc DTP softwares (Coral Draw, Page Maker,
o Algorithms – different graphics Photoshop, etc) are commonly used which
processing algorithms like Bresenham requires computer graphics.
Algorith, Sutherland algorithm, etc 4. Computer Aided Drafting and design – This
- Working of Computer graphics can be field of uses Computer graphics to design
classified as; components for different systems like electrical
o One-Way Communication – In old days, mechanical, electro-mechanical, automobile
Computer Graphics was working only in parts, structure of building, airplane, ships,
One-Way communication mode. E.g. VLSI Chips, optical systems, computer
Digital Clock at railway station, digital network, etc
display boards, etc. 5. Simulation and animation- C.G is commonly
- Two- Way communication - due to recent used to design models for mathematic and
advancement in computer and hardware mechanical system in more realistic forms.
technologies, now it is working in Two-Way - It also uses help of interactive animation to
Communicating modes also. produce animated and cartoon movies.
- In this user can provide input in graphical form 6. Art and commerce- C.G in this field, helps to
& also gets output in graphics form. user to crate artistic pictures to express
E.g.ATM Screen, Smart phone screen, messages for more attention.
etc. - Such pictures are needed in commercial market
for better advertising.
1.2 Application areas of Computer Graphics 7. Process control – With the help of computer
- As Computer Graphics is one of the important graphics, it is possible to design process model
field of computer technology, it is widely used/applied of various industrial departments like
in different fields of society like production, manufacturing, logistics, etc.
Industry - With the help of remote access such control can
Business be easily controlled and monitored.
Government organizations 8. Cartography – C.G. also used to present
Education field different types of maps like geographic maps,
Entertainment & weather maps, oceanographic charts, contour
Home & domestic field maps, population density maps, rainfall maps,
- Some very common application areas of crop production maps etc
Computer graphics are 9. Motion Dynamics(user and object both
1. User Interfaces – for any software it is moving) – C.G. can be used to show user and
necessary to provide user friendly interface so object location by collecting movement of both.
that any user can understand it and use it easily. E.g GPS location.
- Hence, now a days graphical interfaces are 10. Update dynamics - C.G. is used to show how
commonly designed with user controls like the different properties of an object like it’s
buttons, menus, icons, scroll bars, etc. shape, size, color, etc can be changed during the
2. Plotting of graphics and chart – for any running process.
organization preparing and presenting different
types of activities is common. 1.3 Advantages of computer graphics.
- Different functions like mathematical, physical - Due to it’s power and efficiency, field of
and economical functions to be presented in computer graphics provides many advantages
histograms, bars, pie-charts, etc. like
- For these operations, Computer graphics is very 1. Communicating with computer – due to
commonly required. graphical interface, for any user it becomes
3. Office automation and desktop publishing – easy to interact with computer software to
for many organizations it is required to create perform different tasks, e.g. ATM
2
2. Producing pictures – C.G. provides o Less memory.
powerful tools which helps to produce real- - But also it show following disadvantages –
world objects, 4D-synthetic objects, o It is difficult to use, understand
3. Animation and interactive graphics - o Time consuming
C.G. helps to produce moving pictures with o Error prone, etc
background i.e. Animation. - To solve these problems, instead of CLI, it is
- It also can interact with user to make it more more recommended to use GUI.
user friendly. - GUI – it is an graphical interactive interface in
4. Animation control - C.G. tool can also be which user is presented with all the features on
used to control the animation by adjusting screen and user can select the required option.
speed, background, foreground area, color. - It uses many graphical components like
etc o Icons
5. Motion Dynamics(user and object both o Menus
moving) – C.G. can be used to show user o Images
and object location by collecting movement o Buttons, etc
of both. E.g GPS location. - GUI presents all the features of software to user
6. Update dynamics - C.G. is used to show in graphical form.
how the different properties of an object - Due to this, user can select the required option
like it’s shape, size, color, etc can be to complete task e.g.
changed during the running process.
7. DSP – Digital Signal Processing
- Digital signals of audio and video can be
processed to make high-end visual, e.g.
advertisements, VFX (Visual Effects)
8. Environment simulation – virtual
environment can be created to train people -
- In Notepad like application, to create a new file,
(military org) and different chemical user will just click on New option in File menu.
industries where no human can work. - GUI uses following components:
o Mouse Pointer – it is arrow shape moving
1.4 Graphical user interface. symbol in GUI which helps user to move and
- When a software is developed, it must enable user to select the required option.
interact with it. o Selection and pointing device – it is one
- If user interacts with software, then only, the software hardware device like Mouse, Trackball, etc
will be in use. o Icons – it is mall size image show
- In computers field, the technique using which user corresponding action like
and software interacts with each other, is called
interface.
- in simple words, interface can also be defined as an
working environment of that software.
- This interface, based on working environment, can be
classified in following types:- o Desktop – it is the display screen where other
CLI components can be displayed.
GUI Advantages
- In CLI, to complete each and every task, user must - It is easy to understand
type proper command in proper format and in correct - It is easy to learn and use
spelling e.g. DOS - Time saving
- To create a new file, following cmd must by - Less chances of error
typed: - Can generate more interest in user
C:\> copy con f1.txt <Enter> - User friendly software can be created.
- CLI Interface shows following advantages: Dis-Advantages –
o It needs very less or minimum hardware - Requires more advance and costly softwares.
components. - Requires more memory
3
4. X & Y Deflect – when the electrons are travelling as
1.6 Display devices: Cathode Ray Tubes, beam, there are great chances that these electron beam
Color CRT monitors, Direct View Storage Tube. may get deflected or diverted and may causes poor
- With computer systems, as like input devices, it is display.
also necessary to use output devices also called display - to avoid this X & Y Deflect components are used to
devices. properly guide the electron to travel and hit the
- these devices are responsible for showing or phosphor spot.
displaying output produced by processor. 5. Phosphor coated screen - in CRT monitor, the
- these devices are also called Screen / Monitor or backside of glass is coated with a chemical material i.e.
VDU (Visual Display Unit). phosphor.
- the different types of display devices in use are : - - This Phosphor is one chemical compound which has
1) CRT 2. Color CRT the property to glow and reflect light when electron hit
3) DVST it.
Cathode Ray Tube – - when appropriate sports of phosphor coats are hit be
- It is one of most commonly used primary output electrons then those spots start glowing and reflects the
devices used with computers or any graphics system. light so that user can see the output.
- since the beginning of the computer systems till date
CRT monitors are commonly used output devices. Color CRT Monitors
- the working of CRT can be given as:- - Color CRT monitors are mainly used to
show/display output in colors.
- In this also, the screen is coated with phosphor,
but this phosphor is in combination of colors.
- Color CRT working uses one of the following
technique
1. Beam Penetration 2. Shadow Mask
1. Beam Penetration – It uses random scan technique
to display any output on screen
- In this, the monitor uses two layers of colored
phosphor, one is red and other is green.
4
- Electron beam with high speed – such beam can - Hard copy – When the generated output is
penetrate red layer and also strikes to green layer hence printed on paper or any other printing material, it
can produce output n green color. makes hardcopy.
- for this, different hardware are available like Printer,
Advantages – plotter, etc.
i. As compare to B/w CRT, it gives more colored - computers and computers like systems, uses two
output. types of graphics:
ii. More graphical and user friendly output can be 1. Raster Graphics – It is also known as
displayed. bitmaps.
iii. Relatively in-expensive - In this is made of individual pixel of color
Disadvantages combination.
i. Only four colors can be produced. Eg. JPG, GIF, PNG etc.
ii. Output quality is poor. - As it is purely created using collection of pixels,
2. Shadow Masking- hence quality of picture depends on number of pixels,
- Shadow mask method in Color CRT uses Raster-Scan more the pixels , quality will be high.
Display technique to produce high quality output. - As the number of pixels are fixed, hence when image
- The working of Shadow masking can be given as: is enlarged, there are chances that, it may get distorted.
In this 3 separate Electron Guns are used, one of Red, 2. Vector Graphics - in this, instead of pixels,
second for Green and third for Blue electron beam. the picture data is stored in the form of mathematical
- The screen is coated with phosphor which can emits formula i.e Vector
red, green or blue light as per the electron beam. e.g.
in C Lang program if line or circle to be drawn,
following function with formula can be used:
DVST circle(int x,int y,int radius)
if a line to be drawn following vector/formula can be
used
line(int x1,int y1,int x3,int 2)
- Hence whenever such image is displayed, it executes
such vector/formula to give output.
- As it is not dependent on pixels, it gives high
resolution.
- Whenever such vector graphics to be shown it
executes the formula to draw the image.
e.g. CorelDraw, InkSpace like commercially used
graphics softwares creates such vector graphics.
- Though, plotter is like, printer, but they both shows
following considerable differences:
Printer Plotter
https://www.goeduhub.com/10442/direct-view-storage-
- Uses Toner to print - Uses pen, pencil,
tubes-dvst
marker to print.
- Uses collection of - Uses multiple
1.5 Random scan displays, Raster scan
dots to print continuous lines to
displays print
- Can print on small - Can print on large
size of paper like sheets.
1.7 Plotter. A3, A4, Legal, etc
- Computer graphics deals with displaying output in
both forms either - Plotter in market available in following types:
- Soft copy – digital output on screen. For this 1. Drum Plotter – in this a drum is used on which
different display devices like CRT, LCD, LED, etc can paper is rolled to print.
be used.
5
- It uses single or multiple pens to print on paper
by moving in left to right as well as top to
bottom directions.
2. Flatbed Plotter – in this, one or more pens are
used to draw any graphics.
- It can be used by keeping on table. It gives flat
surface on which paper is kept to print.
- Plotter can be used to draw
- Cars, ships, airplanes
- Shoe and dress designs
- Road and highway design
- Huge building designs etc
Advantages – can give hardcopy output of large size
on large size sheets with high resolution.
can print on different flat materials like plywood, - Different types of joysticks are available in
aluminum sheet, cardboard, plastic, flex banner, market like
etc can produce graphics on various size - Digital Joystick
Disadvantages - expensive - Paddle Joystick
- Analog Joystick
1.8 Joystick, - PC Analog Joystick
- C.G deals with high quality output, but to get such - Joypad
output proper input is also necessary. - Due to it’s advantageous features, joystick can be
- With computer different input devices are used, these useful in many applications like
input devices are broadly classified as: Gaming applications
1. Manual Data Entry – Keyboard, Mouse, Cranes, trucks, wheelchairs
Joystic, Light Pen, Touch screen, etc Industrial machines
2. Direct Data Entry – Scanner, Barcode reader,
MICR, OCT, etc 1.9 light pen.
- Joystick is one input device that is commonly for - A light pen is light-sensitive point and selecting inut
manual data entry. device.
- Joystick also called as Control Column - It is mainly used to highlight text, object on screen
- it is specifically used in gaming application, graphics and also to alter data on screen.
applications, etc. - It allows user to interact with user different options
- It was invented at U.S.Naval Research Laboratry by available on screen with more accuracy.
C.B.Mirick. - It is used with any CRT based display with required
It mainly consist of a stick and base. software for light pen installed in it.
Stick – which can be rotated in any direction and - Light pen was originally developed at
can help to move the cursor for pointing and selection. Massachusetts Institute of Tech during 1955 to
Base – consist of two potentiometers, one for X 1960 for Military Airspace Surveillance.
and one for Y axis and different function buttons like - This light pen now in market is available for both
Forward types of terminals / monitors like
Back o Text-only terminals
Side o Graphics terminals
- Apart from these basic functions, joystick also - The light pen works by detecting the change in
have other advance functions also. brightness of nearby pixels, which indicates that
the CRT's electron beam is scanning in that area.
- It then sends the timing of this event to the
computer.
- Due to this, time at when light pen is touched and
time when electron beam hit the screen is
compared to decide the selected pixel.
6
- Tell recently, light pen was very commonly used as i) Horizontal Retrace -
stylus with many smart phones and other touch- - After finishing scanning of one line, the electron beam is
sensitive devices. returned to left side to scan next line.
- Light Pen gives many advantages ii) Vertical retrace – once all the lines are scanned,
1. Precision Selection tool – the options on GUI the beam moves back to top left corner.
can be very accurately selected. - Thus, this display technique uses set or collection
2. Light Artistic Application – due to this of pixels to show picture or image hence the image
applications to be used in the field of Arts like formed as Raster image.
drawing, sketching, Cartoon, etc can be - In Raster scanning, two types of scanning is
developed and can be easily used. possible-
3. Minimizes Desk Space – as it takes very less a) Interlaced Scanning b) Non-interlaced scanning
space as oppose to keyboard, it requires a) Interlaced Scanning – In this each horizontal line is
minimum space on desk. scanned from top to bottom.
- It may cause, display fading of output object.
1.5 Random scan displays, Raster scan displays b) Non-interlaced scanning – in this alternate
scanning is done, in first phase only all odd
- C.G deals with operation of giving output or displaying numbered lines are scanned and then even
output on output device. numbered lines are scanned.
- This display technique can be of following types – Advantages :-
1. Raster Scan - Raster scan gives realistic image.
2. Random Scan - Million of different colors can be used to give
1. Raster Scan – In this technique of display, electron output.
beam is swept/moved on whole screen. - Shadow scenes are possible.
- this movement is one row at a time from top to bottom Dis Advantage:-
and left to right. - Image displayed may suffer from Low Resolution
- as the electron beams moves, beam intensity is turned on - It is expensive
or off to create output pattern by glowing the spot. 2) Random Scan
- In this a special type of memory is used i.e. Refresh Buffer - In this technique, the electron beam is moved or allow to
of Frame Buffer. strike only to the part of the screen where the picture is to
- This Refresh Buffer or Frame Buffer is used to store : be displayed.
output or picture definition which is to be - As in this only selected pointes are scanned, hence it is
displayed. also called Vector display or Stroke Writing Display or
Set of intensity for screen points. Calligraphic Display.
- It also used “Scanline” technique to read above values - The picture to be displayed, it’s definition is stored as set
and draw output on screen. of line-drawing commands.
- To draw the output on screen the smallest unit used is - These line drawing commands are stored in a special
Pixel which is also called picture-element or pel. memory area called Refresh Display File.
- in cyclic fashion all the display writing commands are
executed to give the output.
- It can display the output by drawing the output 30 to 60
times per second.
- Instead of moving electron beam on whole screen, it is
moved only to selected points using X and Y co-ordinates.
- As in this, to display output, specific calculations are
carried out hence this display is called Vector Display.
Advantages –
- Raster Scan also involves following two supporting - Only selected part of screen can be scanned.
techniques:- - Produce line and other drawing.
7
- High resolution
Dis Advantage –
- Can not display realistic shades scenes.
8
UNIT - II
Raster Scan Graphics and Transformation:
2.1 Introduction
- Raster Scan graphics is most common type of
graphics monitor which uses CRT.
- It is based on television technology.
- In raster scan system electron beam sweeps across - the end point of original line and it’s segment can be
the screen, from top to bottom covering one row at a same but the Origin points are different.
time. e.g.
- A pattern of illuminated pattern of spots is created
by turning beam intensity on and off as it moves
across each row.
- A memory area called refresh buffer or frame
buffer stores picture definition.
- This memory area holds intensity values for all
screen points.
-Stored intensity values are restored from frame buffer
and painted on screen taking one row at a time. e.g. of C Prog
- Each screen point is referred to as pixels. #include <graphics.h>
- In raster scan systems refreshing is done at done at a #include <conio.h>
rate of 60-80 frames per second.
- The return to the left of screen after refresh of each main()
scan line is known as horizontal retrace of electron {
beam. At the end of each frame electron beam returns int gd = DETECT, gm;
to top left corner and begins the next frame.
- Transformation is a process of modifying and re- //init graphics
positioning the existing graphics. initgraph(&gd, &gm, "d:/Tc/BGI");
line(100,100,200,100); //will draw a horizontal line
2.2 Line, Line Segment getch();
closegraph();
* Line – C.G deals with showing different types of
return 0;
output such as text, numbers, images, pictures and also
}
drawing shapes like line, circle, rectangle, etc.
- Line, in computer graphics is collection or set of 2.3 Line drawing algorithms –
points. - Line is one of the most basic drawing object to be
- Every line has one origin or start point & one end drawn on output screen.
point. - While drawing a line, every line drawing algorithm
- Between these two points the number of pixels or uses a special process i.e. Rasterization.
points collected is used to determine the length of line. - It means selecting some specific pixels for drawing
- In other words, the distance between origin and end which are best to draw the line.
points is called length of line. - While drawing lines following factors are always
* Line Segment – A piece or part of whole line, it important :-
represents the line segment. straight line must appear as straight line.
- A line segment also have it’s own origin and end line must start and end accurately.
points. displayed line must use constant brightness
- These points of line segment shows following line must be drawn rapidly
characteristics
- the origin point of original line and it’s a) Digital Differential Algorithm
segment can be same but the end points are different. - This algorithm follows incremental method to draw
e.g. the given line.
- It increments number of points on co-ordinates step-
by-step.
9
- It calculates and considers the difference between X 5 1 4
& Y co-ordinate.
- Based on this difference slope of line can be decided. -Based on above points, if the line is drawn it will be:
- The difference is calculated using following formula
as:
Δx=x2-x1
Δy=y2-y1
- This algorithm will calculate the above difference
using:
Source End Δx Δy
0,0 1,1 0 0
1,1 1,1 0 0 - Thus in above set, the difference is greater than zero
1,2 2,1 1 -1 (>0), hence it will draw vertical straight line.
2.6 Translation .
- OR
2.7 Rotation .
o P’ = P . S
- Rotation is one type of 2D transformation - Where S is the scaling matrix. The scaling
process by which the display object can be process is shown in the following figure.
viewed in different angle.
- In rotation, the object is rotated at particular
angle θ theta from its origin.
- From the following figure, we can see that the
point PX,Y located at angle φ from the
12
- The points of original object on X and Y axis
can be given as
a 3,3
b 7,3
c 5,8
- The points of reflected image on X and Y axis
can be given as
a' 3,-3
b’ 7,-7
c’ 5,-8
-
2. Reflection about the y-axis - in this, value of y
remains same, but the value of x becomes
- From above following can be concluded:-
negative.
i) If scaling factor S is less than 1, then size of the
object is reduced.
ii) If scaling factor S is greater than 1, then the size
of the object is increased/expanded.
2.9 Reflection
- Reflection is one type of 2D transformation
process by which mirror image of object can be
produced.
- To produce such mirror image, it also performs
rotation in 1800, but the size of object remains
same.
Types of Reflection:
1. Reflection about the x-axis – in this, value of
x remains same, but the value of y becomes
- The points of original object on X and Y axis
negative. can be given as:
- a 3,3
b 3,7
c 7,5
13
- The points of reflected image on X and Y axis
can be given as Original triangle coordinates of A, B, C are given as
a (3 4)
a' -3,3 b (6 4)
b’ -3,7 c (4 8)
c’ -7,5
Reflected triangle coordinates of A, B, C are given as
a' (7 3)
3. Reflection about an axis perpendicular to xy b’ (8 5)
plane and passing through the origin - in this, c’ (15 4)
value of both x and y becomes negative.
2.10 Shear
- Shearing is one type of 2D transformation process by
which shape of output object can be changed.
- To complete the shearing process, sliding of layers is
carried out.
- A transformation that slants the shape of an object is
called the shear transformation.
- Shearing is also termed as Skewing.
- Shearing can be performed in following ways:
i) Shearing in the X-direction ( X-Shear)
ii) Shearing in the Y-direction (Y-Shear)
- The points of original object on X and Y axis
can be given as:
- a 5,3 i) Shearing in the X-direction: In
this horizontal shearing,
b 3,7 sliding of layers occurs at X axis.
c 7,5 - The X-Shear preserves the Y coordinate and changes
- The points of reflected image on X and Y axis are made to only X coordinates
can be given as - Due to this, it causes the vertical lines to tilt right or
left as shown in below figure.
a' -5,-3
b’ -7,-7
c’ -3,-7
14
2.5 Matrix representation.
15
UNIT - III Visualization of particular part of picture.
3. Segmented Display Files and Clipping and Scaling, rotation and translation of picture.
Windowing:
3.1 Segment table – Computer graphics deals with
displaying pictures on display devices.
- This display can be of:
Static display – in this, once the output is
shown, it is not changed till the output is closed.
Dynamic display – in this, as long as output is
visible on screen, there can be changes in it.
- The current computing environment demands
dynamic display of pictures instead of static display.
- This dynamic display involves speed of regeneration
of successive pictures.
- This dynamic display involves-
- sometimes, either the whole picture is
changed and need to display whole picture again and
again. 3.2 Functions for segmenting display file
- in some cases, only a part of picture is - Computer graphics to display & maintain the output
changed and to be displayed but the whole picture to be uses a special file called as display file.
displayed repeatedly. - This display file contains all the required instructions
- To draw the output or picture on output device, a to display the picture and functions to manipulate it.
special memory is used to store all the required - This display file is divided into smaller logical unit
instructions called as Display file or Display list. called as segment.
- For dynamic output, this display file is regularly used - Each segment associated with instructions and
and also to be manipulated. segment name.
- To view the image or part of image with various - As like a disk file which supports different functions
attributes, the contents of display file must be like Open file, read,Write,Edit/update, Rename, delete,
organized & loaded in memory. etc, display file also supports different functions for
- To complete this process successfully, C.G uses segmenting.
concept of segment. - The basic functions supported by segment are
- Segment is logical unit of display file used to display 1) Creating/opening segment
the given object on display device. 2) renaming segment
- The process of creating such logical units of display 3)Closing segment
file is called as Segmentation. 4) Deleting segment
- In memory the contents of segment may be allocated 1) Creating/opening segment –
contiguously or non-contiguously. - This is the very first function to be performed
- For dynamic display, along with display file, whenever output to be drawn on display device.
following also needed: - New segment is necessary to load the required
i) Functions to manipulate instruction in display instructions in memory.
file. - while creating new segment following algorithm is
ii) naming scheme – to name each segment followed-
unambiguously. 1) If any segment is open, give error message
: “Segment is still open” and go to step 8.
- Each segment corresponds to: 2) Read the name of the new segment.
3) If the segment name is not valid, give error message
a part of image and is : “Segment name not a valid name” and go to step 8.
associated set of attributes and 4) If given segment name already exists, give error
image transformation parameters like message : “Segment name already exists in name
scaling, rotation, etc list” and go to step 8.
Benefits of segment - 5) Make next free storage area in display file as start of
Subdivision of picture. new segment.
16
6) Initialize size of new segment to 0 and all its - But if, any in between segment is to be deleted, then
attributes to their default values. the next segment must be shifted to the deleted
7) Inform that the new segment is now open. segment position.
8) Stop.
2) Renaming segment
- When C.G needs to display same output for long
duration, it required the instructions to be repeatedly
called.
- for this it uses technique of Double Buffering.
- Double Buffering is tech by which two images are
stored, one to show and other is for manipulation.
- After successful changes, the first image is replaced
by second one.
- Hence it needs two segments with proper name.
- For renaming following algorithm is used.
1. If both old and new segment names are not valid,
give error message : “Segment names are not valid
names” and go to step 6.
2. If any of two segments is open, give error message Algorithm :
: “Segments are still open” and go to step 6. 1. Read the name of the segment to be deleted.
3. If new segment name given already exists in the 2. If segment name is not valid, give error message
display list, give error message : “Segment name : “Segment name is not a valid name” and go to step
already exists” and go to step 6. 8.
4. The old segment table entry are copied into new 3. If the segment is open, give error message
position. : “Can’t delete an open segment” and go to step 8.
5. Delete the old segment. 4. If size of segment is less than 0, no processing is
6. Stop. required and go to step 8.
5. The segments which follow the deleted segment
3)Closing segment are shifted by its size.
6. Recover deleted space by resetting index of next
- After completing entry of all display file instructions, free instruction.
the segment needs to be closed. 7. Stop.
- But before closing it has to be renamed, which is
done by changing the name of currently open segment
as 0.
- Now the segment with name 0 is open i.e. unnamed
segment is open and if two unnamed segments are
present in display file one needs to be deleted.
Algorithm :
1. If any segment is not open, give error message
: “No segment is open now” and go to step 6.
2. Change the name of currently opened segment to
any unnamed segment, lets say 0.
3. Delete any other unnamed segment instruction
which may have been saved and initialize above
unnamed segment with no instructions.
4. Make the next free storage area available in
display file as start of the unnamed segment.
5. Initialize size of unnamed segment to 0.
6. Stop.
18
DeleteSegment() – if the segment is currently
open, close it and then delete it, if no existing segment,
no effect.
PostSegment() – if the segment to be posted is
closed, open such segment then post, if segment
already posted or not-existing, no effect.
UnpostSegment() - if the segment to be
unposted is closed, open such segment then unpost, if
segment already unposted or not-existing, no effect.
- When for default error conditions, above default
execution flow is considered, the error condition can be
avoided.
- More error free execution can be considered as
OpenSegment(1)
3.5 Default error conditions drawLine(10,20,10,100)
- Display file is used to display the given output and PostSegment(1)
also to maintain the output on screen.
- Display file in memory is loaded into smaller pieces 3.6 Appending to segments
i.e Segment. - In Dynamic graphics, C.G deals to show such data
- To complete all the jobs of segments, different which is subjected to change frequently.
segmenting functions are used like: - In such case, the display file used for such
OpenSegment(n) dynamic/changeable output also to be frequently
CloseSegment(n) changed and hence the corresponding segment also to
DeleteSegment(n) be updated.
PostSegment(n) - For this, following are possible ways to show the
UnpostSegment(n) dynamic display
- But while calling such functions, the output showing - as per current data, create display file and
software or program may generate errors like segment and complete the output
already segment is open - when new data arrives, re-construct the
invalid segment name display file and re-built the new segment.
duplicate segment name - Above process is good if very few changes are to be
no segment is opened done.
non-existing segment - But when, data to be collected more frequently, then
the segment which already visible, again above process is not efficient.
tried for posting e.g.
Trying to unpost such segment which is not a chart showing data of sale of different
yet posted. products in Shopping mall.
- Above all errors are considered as default errors while - To solve this problem, C.G. suggest the solution of
showing output. appending segment.
- the situation or condition when such errors occurs is - By this, in an existing segment the new collected data
called as Default Error Condition. & it’s display file instructions can be added.
- To handle these situations, the standard practice is to - To achieve this, consider there is an existing segment
how error messages. 2, and in this contents to be appended, following code
- the above functions to be defined in such a way that can be used:
they can implicitly handle the default error conditions AppendToSegment(2)
like MoveTo(lastx, lasty)
OpenSegment() – if any of the segment is drawLine(newx,newy)
currently opened, close it. PostSegment(2)
CloseSegment() – if no segment is currently
opened, no effect
19
3.7 Viewing transformation - During clipping, for above possibilities, following
actions are taken:
3.8 2-D clipping the portion which is completely inside is
- Any output displayed on output screen is using two selected to display
dimensions. - the portion which is completely outside of the
- On any output screen, when output is shown using region, is discarded to display.
pixel, every pixel associated with two co-ordinates i.e. - the portion which is on boundary, then the
x and y. intersection area to be calculated, and from this, area
- This output is subjected to various types of which is coming in region is displayed and the portion
operations, one such common operation is clipping. which remains outside is discarded as:
- Whenever an output is viewed, it uses a specific
region i.e. clip window or clipping window, which is
generally a rectangle in shape.
20
i) If both end points are outside window, then the i) If the line is completely visible, accept it.
line is completely invisible e.g. line ij,kl ii) If the line is completely invisible, reject it.
ii) If both end-points are inside the window the, iii) If the line is partial, follow some other steps to
line is completely visible e.g line ab reject invisible part and accept only the visible part.
- But, the factor no.1 is always not working, - To complete the steps, this algo considers a viewing
some times, end points of line might be outside windows that is region window.
the window, but still some part of line is inside Based on this region window, for each end point of line
the window e.g. ling gh 4 bit region code is assigned in sequence of TBRL
- In such case, line is considered as partially (Top-Bottom-Right-Left)
visible.
- Hence, instead of above basic factors, modified
factors to be considered for complete
invisibility like:
i) Both end points completely out of left
ii) Both end points completely out of right
e.g. line ij
iii) Both end points completely out of
bottom e.g. line pq
iv) Both end points completely out of top
- This algo considers following different conditions
using x & y co-ordinates of given by considering
following boundaries
ab = Above|Top
bl = Below|Bottom
l=Left
r=right - This algo follows following steps to complete the
1) if(xa> xl and xa> xr) and (xb> xr and xb< xr) – task:
when this condition is true, line is completely 1) Assign the region code TBRL for each end point
inside hence visible (line ab). of line
a. Line ab fulfills above condition hence 2) if region code of both points is 0000, accept the
visible, but line and line is completely visible.
b. But line ij, don’t, hence invisible. 3) else: perform logical and operation on both end
points,
2) if(xa< xab and xa> xbl) and (xb< xab and xb> xbl) a) if result is non-zero, reject the line and line is
– when this condition is true, line is completely completely invisible.
inside hence visible. b) else
a. Line ab fulfills above condition hence i) choose end point of the line that is
visible, but outside given region.
b. Line pq don’t , hence invisible. ii) find intersection
iii) replace end-point with intersection
3.10 End point codes / Cohen-Sutherland line iv) repeat step 2
clipping Algorithm) e.g.
- On display device, any output is considered as
collection of lines.
- hence whenever visible or invisible part to be
considered, the line or portion of line to be decided
whether it is visible or invisible.
- to solve this problem, two renowned computer
engineers Danny Cohen and Ivan Sutherland
developed an algorithm based on the end-points of
any given line.
- This algorithm helps to decide:
21
- End Point Algorithm or Cohen-Sutherland algorithm
is very useful to decide about the visible and invisible
part of partial lines.
- But, Cohen-Sutherland algorithm considers only the
intersection point of such partial line.
- Instead, this, Mid-point sub division algorithm is
special of case of Cohen-Sutherland algorithm.
- The initial working part of this algorithm is as same
as Cohen-Sutharland algorithm i.e.
-This algo considers a viewing windows that is region
window.
Based on this region window, for each end point of line
4 bit region code is assigned in sequence of TBRL
(Top-Bottom-Right-Left)
- This algo follows following steps to complete the
task:
1) Assign the region code TBRL for each end point
- in above e.g. 3 lines are considered
of line
Line ab
2) if region codes of both points is 0000, accept the
Line cd
line and line is completely visible.
Line jk
3) else: perform logical and operation on both end
For line ab
points,
Find the region codes for both end-points i.e.
a) if the result is non-zero, then line is
a=0000, b=0000
completely invisible.
as the final result of both end-points is zero,
c) if the result is non-zero but the line is partial,
hence this line is accepted and hence it is completely
then consider following steps:
visible.
i) divide such line in two equal parts
For line cd
ii) check the visibility of each part based on
Find the region codes for both end-points i.e.
region codes. If region codes zero then accept else
c=0101, b=0100
repeat step i and ii till whole line is processed.
after logical and operation, the result is non-
e.g.
zero, hence this line is rejected and hence it is
completely invisible.
For line jk
Find the region codes for both end-points i.e.
j=0000, k=0000
after logical and operation, the result is non-
zero, hence this line is rejected but it is not possible, as
this line shows partial visibility. -Above line pr is a partial line, hence it can not be
- In such case, this algorithm suggest to find the either completely rejected or accepted.
intersection point where the line is crossing to - for such line, mid-point subdivision algorithm can be
the boundary e.g. applied as:
- the intersection point found is suppose j’, now the i) divide the line in two equal parts with mid-
updated line is j to j’ and j’ to k point Pm1 as:
- as the region codes of j and j’ belongs to 0000 codes,
hence this portion of line is accepted and declared as
visible.
- Line portion j’ to k belongs the non-zero region code,
hence it is rejected and declared as invisible.
22
- Now the updated line considered as P to Pm1.
- Check the region codes of both end-points i.e.
P=0000, Pm1=0000
- As the final result is zero hence this portion of line is
accepted and declared as visible.
- The second half of line is Pm1 to q which is still
partial, hence above steps to be repeated as:
Divide line in two equal parts with Pm2 as mid
point as:
23
Case Output
3.12 Polygon clipping algorithm (Sutherland-
Hodgman algorithm)
- A polygon is viewed as object of connected lines i.e. Out → A’ B [2 Vertices, Point of intersect
edges and vertices. In with window and ending edge]
- Alternatively it is also called as 2-D architecture
made up of number of lines. In →
- As C.G uses line clipping algorithms, to decide the In C [1 ending vertex ]
visible and invisible parts, similarly for polygon also it
is necessary to decide the visible and invisible parts. In →
- For this, Sutharland and Hodgman suggested this Out D’ [Point of intersect with window]
polygon clipping algorithm which efficiently decides
the visible and invisible parts of polygon after clipping. Out →
- This algorithm is based on following working rules Out N/A [Nothing is included]
i) it considers a viewing or clipping window
against which clipping is to be done.
ii) the clipping window having four boundaries - To complete the clipping, this algorithm
i.e. Left, Right, Top and bottom performs clipping from all four boundaries if
iii) Each line processed as edge and vertex. required i.e. Left, Top, Right & Bottom
- This algorithm considers following different cases:- e.g.
Case 1: out → in :
If the starting vertex is outside the window boundary
and ending vertex is inside then we preserve or save
both point of intersection of polygon edge with
window boundary and ending vertex in the output
vertex list.
Case 2 : in → in :
If both the starting and ending vertices are inside the
window boundary then only the ending vertex is
preserved or saved in output vertex list.
1) Left Clipping
Case 3: in → out :
If the starting vertex is inside the window and ending
vertex is outside then only the point of intersection of
2) Right Clipper
polygon edge with window boundary is saved in output
list.
Case 4: out → out :
If both the starting and ending vertices are outside the
window boundary then nothing is added or saved in the
output vertex list.
24
3) Bottom Clipping
4) Top Clipping
25
UNIT - IV - Geometric modeling is the process of defining the
4. Geometric Models and Simple Graphics Package: properties of an object or a system using mathematical
4.1 Simple modeling example formulae.
- C.G tech helps to show different output on any - Computer geometric modeling is the field that
display device. discusses the mathematical methods behind the
- Many times, to show complex output modeling tech modeling of realistic objects for computer graphics and
is used which is a process that describes the use computer aided design.
of computers to simulate objects or events. - Computerized model can be prepared for both:
- There are different areas of field where this modeling 1) Physical Object 2) Process
tech is commonly used. - Physical object always represents physical or
- Many computer models consist of a mixture of data geometric properties like length, width, height, weight,
structure and procedures. etc.
- In models of solid objects, lot of data is used and very e.g. any solid object like Mobile Phone, Car, Airplane,
less procedure part is involved. etc.
- In some models like Weather systems, Economics, - The model of process is considered as Non-geometric
along with data, more procedure part is also involved. model as it doesn’t involves any physical properties.
- Digital electronic circuit, is one example of computer e.g. Admission Process, Security Checking, Tourism
model which is created for following important model, etc
reasons: - Geometric modeling stores all the required geometric
- to produce documentary diagrams. parameters in Data Structure.
- To teach students about documentary - In this modeling, Output of one component is treated
diagrams in more easy way. as input of other object.
- circuit model consists of a data structure as well as e.g. SMPS in Computer CPU
some procedures. - The output or display of geometric modeling is
- Data structure defines each of the components and dependent on 3 factors:
connecting wires in circuit diagram like diode, 1) Purpose of Display - it defines how &
capacitor, inductor, resistor, etc. what output should be displayed, either in 2 D form,
- Data in data structure show identification of the each 3D Form, whether whole object to be presented or
type of component and it’s co-ordinate position in partial object to be shown?
model. 2) Hardware used for display – simple models
- This helps to decide whether the wire and component to be displayed needs regular hardware components,
are connected with each other or not? but some specialized 3D models with high-end
- also it is necessary to test whether two wires are graphics needs extra hardware components like
connected or not? graphics card, etc.
- This model also uses a process fan-out to test 3) Software used for display –Software’s are
multiple input components connected to the output of necessary to create as well as display model. For
single component. simple objects regularly & license free software can be
- In this test, following will be checked? used like Ms-Paint, Picture Manager, Picasa, etc
- how many wires leading from given But for models with high-end graphics,
component’s output connector? specialized licensed softwares are needed like Coral
- how many are input to other components? Draw, Maya, Flash etc
- This representation makes easy to construct the - Geometric modeling also considers another fact that,
diagram on display screen. in many cases different objects shares common
properties.
- For this reason, geometric modeling uses common
4.2 Geometric modeling methods like:
1) Basic Data Element
- A computerized model is a virtual object or simulated
2) Structure Imposing
object that represents the real-world object.
- The computer tech by which such object is created is 3) Transformation
1) Basic Data Element – In this method, data
called modeling.
elements of different models are collected to compare
for common parts like lines, angle, shape, color, etc.
26
2) Structure Imposing – In many cases there exist - in above example 4 symbols are defined which are
relationship between data elements of different objects, repeatedly used in difft forms.
e.g. based on CPU/Mobile handset cabinet size, size of - Thus, to use symbols, it is necessary that it has to be
internal parts are decided like SIM Card. transformed from master coordinate system to world
3) Transformations – Many times a model to be coordinate system.
presented by applying transformation like translation, - For this transformation, following functions are used:
reflections, shearing, scaling and rotation. i) Scale(sx,sy) – by this, suze of symbols can be
increased or decreased to be used in map with scaling
4.3 Symbols & instances. factor sx and sy.
- Graphical output uses different components like ii) Rotate() – by this, as per requirement, symbol can
images, icons, pictures, animation, etc. be rotated in given angle.
- Similarly, Symbol is one such graphical output iii) Translate(tx,ty) – by this symbol relocated on
component also called as small sized pictorial data. given line from old points to new points.
e.g toilet symbols, road symbols, etc
- For complete and successful transformation, the
calling sequence of above functions should be
Scale Rotate Translate
27
ii) Forming the instance transformation matrix – - The specialized software used in any graphics system
When two or more transformation applied they is called Graphics software.
executed sequentially. - Every graphics software is sub-routine or functions
- Hence result of each transformation to be used by an application program to generate pictures for
maintained separately. any display device, plotter and also to handle graphics
- E.g. if 3 transformation applied Scaling, interaction.
Rotation & Translation, then the corresponding - While designing any graphics software following
matrices will be fundamental rules are to be considered:
o Scaling S 1) Simplicity – Graphics software uses many complex
o Rotation R features/algorithm like face recognition system, but
o Translation T these features must be presented in simple and easy to
- Using these 3 matrices, the resultant matrix use way to user.
formed is Q as - For this, all features/functionalities of graphics
Q=S R T software must be explained in user’s manual.
- In some cases, the symbol is multi-level i.e. one
symbol using multiple components. 2) Consistency – This rule defines that, the working of
- Then, such symbol is sub-pictured and graphics software must in normal and predictable
transformation is applied to each part and result fashion.
of each part transformation is concatenated. - There must not be any unhandled exception which
e.g. causes abnormal termination of application.
- Also it defines that, proper function names are used,
function calling sequence, error handling, etc.
- For this, first a conceptual model is created and then
implemented.
29
– While designing any graphics software it is necessary
to study the internal design of each function to be
included in graphics software.
- Graphics package consists of mainly 2 components:
i) Display Code Generator
ii) Transformation Processor
i) Display Code Generator – this function helps the
output device to show the output generated after
execution of given commands ( e.g. line draw
command)
- It is recommended to use separate display code
generator for each output so that output drawing will be
fast.
- With this function it is also necessary to include the
feature of Device Independence i.e. the output must
not be dependent on specific type of hardware, instead
it must be supporting all types of hardware.
ii) Transformation processor – this function helps to
perform different transformation operations on output
like
translation – moving the object from old to new
point
rotation – changing the viewing angle
scaling – increasing or decreasing the output
size.
Reflection – creating mirror images of output.
Shearing – sliding the layer of output either on
x or y axis.
30