Computer Graphics Note
Computer Graphics Note
np
Computer graphics.
Book: computer Graphics Motivation of CG:
Author: Donald Heam M Pauline baker. - Appealing picture produce.
- Humans respond better to pictorial information.
Date: 2065/4/12 - Human brain recognizes visual patterns.
- “If it looks right , it is right”, Jim Blinn (CG pioneer)
What is computer Graphics? Reasons to study CG:
- information presentation.
- Use a computer to create pictures. - Job in CG ( Games, movies etc)
- Started early 60s . Ivan Sutherland (MIT) - New medium for artistic expression.
- CG has many concept. - Communicate ideas better.
- Computer scientists create libraries, tools that artist /non - Take animation course.
techines can use to create pretty pictures.
- Artists use CG tools to creates pretty Pictures. Use of CG:
CG tools: - Art. Entertainment, publishing
- CG tools include hardware and software tools. - Movies , TV, books, magazines, game
Hardware Tools: - Image processing
- Output devices video monitor , printer - Alter images, remove noise
- Input devices keyboard , mouse , touch panel, - Processing monitoring
- Graphics cards/ Accelerator - Large systems or plants
Software tools: - Display simulations:
- Flight simulators, virtual worlds.
- Operating system - Computer- aided design, architecture, electric circuit
- Complier design
- Editor - Scientific analysis and visualization.
- Debuggers - Molecular biology(human brain), matlab,
- Graphics library
CG Example:
CG libraries: - Biggest CG consumers today are:
- Functions/ routine to draw line or circle etc. - Movies (Hollywood)
- Ellaborate : pull -down menu, 3D coordinate system etc. - Computer Games: eg Mdden NFL football 2004.
1
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
- Animated movies: E.g Toy story, e.g Finding Nemo - The beginning of modern interactive graphics, however
- Special effects: e.g spider man 2,Spider man 3,Matrix were found in IVAN SUTHER LAND’S seminal doctoral
Reloaded. work on the sketchpad drawing systems. He introduced
Elements of CG: data structures for storing symbol hierarchies built up via
- Poly lines connected st lines( edger, vertices) replication of standard components ( used for drawing
- Text; font, typeface circuit symbols). He also developed interaction technique
- Filled regions; colors , patterns. that use the keyboard ad light pen for making choices,
- Raster images: pixels have values (pixmax) pointing and drawing and formulating many other ides and
technique still in use today.
- By the mid- sixties, a number of research projects and
Date:2065/4/13 commercial products had appeared as the potentially of
CAD activities in computer, automobile and aerospace
1.1 HISTROY OF COMPUTER GRAPHICS: The grew enormously for automating drafting-insensitive
fundamental principal and technique derive in the past are activities. The general motor system for automobile design
still applicable in today’s computer graphics technology and and Intek Digitek system for lens design were pioneers in
generally will be applicable in the future too. showing the efforts utilizing graphics interaction in the
The history of the computer graphics can be study interactive cycles common in engineering.
as a chronical development of hardware and software. The - Due to the high cost of graphics hardware , expensive
evolution of graphics under various terms are expect on computing resources, difficulty in wring large interactive
following points. program and due to many other reasons the human-
computer interaction was still done primarily in both mode
- Crude plotting on hardcopy devices such as teletypes and using punched cards. After the advent of graphics based
line printers dates from the early days of computing. personal computers such as Apple Macintosh and IBM
- The whirlwind computer developed in 1950 at PC, the costs of both hardware and software droven down.
Massachusetts institute of Technology ( MIT) had Millions of graphics computer were sold exclusively for
computer-drive CRT displays for output, both for operator offices and home. Thus the interactive graphics (GUI) as
use and for cameras producing hard copy. “the window on the computer” became an integral part of
- The SAGE air-defence system developed in the middle PC featuring graphical interaction.
1950’s was the first to use command and control CRT The reason for making interactive graphics
displays console on which operators identified targets affordable was the advent of direct-view storage tube (DVST)
with the light pens. which replace buffer and refresh process and eliminated all
2
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
flicker in the system. Before this, buffer memory and
processors were enough only to refresh at 30HZ and only few Date: 2065/4/14
thousand lines could be drawn without noticeable flicker.
Application of computer graphics:
- Another major hardware advance of late sixties was Computer graphics started with the display of
attaching a display is a minicomputer, relieving heavy data or hard copy plotter and CRT screens had grown include the
demands of refreshed display devices (like user- creation, storage and manipulation of mode is of images of
interaction handling and updating image on the screen) objects. These models come from a diverse set of fields and
with the central-time sharing computer. include physical mathematical, engineering , architectural,
- In 1968, another such devices was invented. The refresh natural phenomena and so on. There is virtually no area in which
display hardware for geometric transformations could graphical displays cannot be used to some advantages.
scale, rotate and translate points and lines on the screen at Today al most all application
real time; perform the 2D and 3D clipping and could programs even for manipulating text or numerical data uses
produce parallel and perspective projections. graphics extensively in user interface for visualizing and
- The development of inexpensive raster graphics, based on manipulating the application specific objects. Graphical
television technology in early seventies contributed more interaction has replaced textual interaction with alphanumeric
to the growth of the field. The Raster displays stores terminal. Even people who do not use computer encounter
displays stores display primitives (lines, characters or computer graphics in TV commercial or special effects. It is an
areas) in a refresh buffer. integral part of all computer user interfaces and is indepensible
The development of graphics cannot be for visualizing 2D, 3D and higher- dimensional objects. We find
stand-off without the study of graphics input technology. The computer graphics used in a diverse areas as science, engineering
clumsy, fragile light pen has been replaced by mouse, the tablet, , medicine business, industry, government, art, entertainment ,
touch panel, digitizers and other devices. Interaction to computer education and others.
using devices require no knowledge of programming and only a
little keyboard use; the use makes choices by selecting menus, COMPUTER AIDED DESING (CAD):
icons , check options, places predefined symbols on screen and In CAD, interactive graphics is used to design components and
draws by indicating consecutive end points to be connected by systems of mechanical, electrical, electromechanical and
lines or interpolated by smooth curves and fills closed areas electronic devices including structures such as buildings,
bounded by polygons or point contours with shades of gray, automobile bodies, airplane, VLSI chips, optical systems and
colors on various patterns. Now computer graphics have become telephone and computer networks. The emphasis is on
integral and infamous technology in the computers system. interacting with a computer-based model of the component or
3
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
system being designed in order to test, for example its structural,
electrical or thermal properties. The model is interpreted by a Date: 2065/4/15
simulator that feeds back the behavior of system to the user for Computer Art:
further interactive design and test cycles. Computer graphics is used to generate arts. They are widely
Some mechanical parts are manufactured by describing how used in both fine art and commercial art applications. Fine arts is
the surfaces are to be formed with machine tools. Numerically drawn by artist hand and this kind of art is perfect to the artist
controlled machine tools are then set up to manufacture the parts skill. Artist use a variety of computer methods including special-
according to these construction layouts. purpose hardware, artists paints brush program, other paint
Architects are interactive graphics method to layout floor packages, specially developed software. Mathematics packages,
plans that shows positioning of rooms, doors, windows, stairs, CAD packages, desktop publishing software and animation
shelves and other building features. An electrical designer then packages providing facilities.
try out arrangements for wiring, electrical outlets and other Moreover, artists uses a touchpad or a stylus or digitizer to
system to determine space utilization on a building. The realistic draw pictures. The movement of object is captured by some
displays then allows architects and their clients to study input hardware. These arts are usually generated by using
appearance of building and even go for a simulated “walk” mathematical functions or algorithms.
through rooms or around building. Computer art is not as realistic as fine arts. Mostly the
commercial art is used to produce animations to demonstrate or
PRESENTATION GRAPHICS: present commercial products to the public. Find artists uses a
Another major application areas of computer graphics is the variety of computer techniques to produce images. These images
“Presentation Graphics”. Presentation Graphics are used to are created using a combination of 3D modeling package, texture
provide illustrations for reports or to generate transparencies for mapping, drawing programs and CAD software.
use with graphics. These technique for generating electronic images are
Presentation Graphics is commonly used to summarize also applied in commercial art for logos and other design, page
financial, statistical, mathematical, scientific and economic data layouts combining text and graphics, TV advertising sports, and
for research reports, managerial reports and other types of other areas. Animations are also used frequently in advertising
reports. Typical examples are bar charts, line graphs, surface and TV commercial and produce frame by frame, where each
graphs, pie charts and other displays showing relationship frame of the motion is rendered and saved as an image file.
between multiple variables. A common graphics method exployed in many
The 3D graphics are usually used simply for effects, they can commercials is morphing, where one object is transformed into
provide a more digramatic or more attractive presentation of data another.
relationship.
4
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
Education and training: to visualize large amount of information graphical computer
Computer graphics is used in education and systems are used.
training for making it more effective and more illustrative. E.g if
a teacher is to teach bonding of molecules or electron jump form Image Processing: Image can be created using simple point
higher energy state to lower energy state or the structure of gene. program or can be fed into computer by scanning the image.
Then he can demonstrate these concepts using computer graphics These picture/ images need to be changed to improve the quality.
software or presentations. Form image/pattern recognition systems, images need to be
Another example could be taken for surgery. A changed in specified format so that the system can recognize the
student can learn surgery using data gloves and realistic meaning of the picture. For example scanners with OCR features
computer graphics. This way the cost of education will be low must have letters similar to standard font set.
and risk of human life as well. Other examples could be flight
simulator and driving simulator for pilot and driving training. Graphical user Interface: GUIs have become key factors for
Modes of physical systems, physiological systems, the success of the software or operating system. GUI uses
population trends or equipments such as the color coded diagram graphical objects called gizmos to represent certain objects or
helping trainees to understand the operation of the system. process involved in human computer communication for virtual
purpose. Lots of aesthetics (colors) and psychological analysis
Entertainment: Computer graphics methods are new have been done to create user friendly GUI. The most popular
commonly used in making motion pictures, music videos and TV GUI is windows based GUI. The GUI creators are putting having
shows. Images are drawn in wire-frame form and will be shaded emphasis on 3D GUI creation.
with rendering methods to produce solid surfaces. Music videos
use graphics in several ways. Graphics objects can be combined 2.0 HARDWARE CONCEPT: Input device are used to feed
with the line action. data or information into a computer system. They are usually
Computer graphics are also used to introduce virtual used to provide input to the computer upon which reaction,
characters to movies like character in “Lord of the Rings”. outputs are generated. Data input devices like keyboards are used
to provide additional data to the computers whereas pointing and
Visualization: Some methods generate very large amount of selection devices like mouse , light pens, touch panels are used to
data/information for example a survey of one lakh people’s provide visual and indication-input to the application.
choice for using different toothpaste generates large amount of
data. Analysing the property of the whole amount of data. 2.1 Keyboard, Mouse , Light pen, Touch screen and Tablet
Analysing the property of the whole amount of data is very input hardware:
difficult. If we try to locate each and every data value. Therefore
5
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
Keyboard: Keyboard is a primary serial input device. For each Mechanical mouse contains two rollers. One rollers count
key press, a keyboard senses specific codes(American standard horizontal displacement and another roller counts vertical
code for Information Interchange, ASCII) to the computes. displacement. The motion of the roller in the base of mechanical
Keyboards are also capable of sending/coding combinations of mouse is converted to digital values that are used to determine
key press and special keys like function keys. The coding for the the direction and magnetic of movement.
combination of key pressing is called “chording”. It is useful for
expert users in giving exact commands to the computer. Cursor- Optical mouse uses a special mouse pad with a matrix of Black
controlled keys and function keys are used for doing operations and white grid of lines. The matrix reflects light from the LED
in a single keystroke. on the bottom of the mouse. The intensity/quality of reflected
Other types of cursor-pointer devices are trackball or joystick. light varies as Black and white lines reflects it alternatively. The
A numeric keypad is after included on the keyboard for fast entry alternate reflections are used to calculate the relative position
of numeric data. change.
Several different technologies are used to detect a key
depression including mechanical contact closure, change in Advantages:
capacitance and magnetic coupling. Chording is not possible • None of the part of computer screen is obscure (hidden
with standard “coded keyboard”, which returns only an ASCII from head).
code per keystrokes and returns nothing if two keys are pressed • Movement becomes easier as had rests at a desk for
simultaneously. An unencoded keyboard can identify of all key movement.
press simultaneously allowing chording. • Direct-point- and –click.
• Easy to use and understand.
Mouse (Mechanical and optical): Mouse is a serial input
device used to select object movement in graphics system. It Light Pens: Light pens are pencil shaped devices used to select
converts horizontal movement into vertical movement. Primary screen positions by detecting the light coming from points on the
principle of curser movement is to detect the amount of CRT screen. They are sensitive to the short burst of light emitted
displacement of mouse in horizontal plane. This displacement is from the phosphor coating as the instant electron beam strikes a
mapped into screen. Generally the mapping ratio is 1:8 . particular point. Other light sources , such as background light in
According to their working mechanism tow types of mouse are the room are usually not detected by a light pen.
there. They are: An activated light pen pointed at a spot on the screen as the
• Mechanical mouse and electron beam light. Some of that spot generates an electrical
• Optical Mouse. pulse that causes the co-ordinate position of the electron beam to
be recorded.
6
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
Disadvantages: are interrupted and reflected back from their mid wave. The
• When used for long time, leads to an arm pain. sensors on the X-axis and Y-axis sides measured the time,
• Some part of the screen will be obscure by hand. the sound waves took to get reflected back and estimate the
• Cannot read black pixel position. touch position.
• Reading might be errorous if background light has very - An optical touch panel uses Infra red (IR) emitters and
high intensity. sensor on X and Y-axis sides, emitter are placed and on the
apposite sides sensors are placed when a user touches the
screen, the point will interrupt two IR beam from X and y-
Date:2065/4/16 axis. This is detected by IR sensors and the touch position
is calculated.
Touch-Panel: Touch panels are a sensitive surface that is used Advantages:
to point directly. The panel can be touched by finger or any other • Touch panel can be mounted an display screen leaving
object like stylus Transparent touch panels are integrated with more space on desktop but mouse, joystick etc. take some
computer monitor for the manipulation of information display. space.
A basic touch panel senses voltage drop when a user
touches the panel. It knows where the voltage has dropped and Tablets (Electronic, Sonic and Resistive ): A common device
accordingly calculates the touch position. for drawing, painting or interactively selecting co-ordinate
- Resistant based touch panel uses two substances of glass position on an object is a digitizer. Typically a digitizer is used to
or plastic separates by insulators. When a user touches the scan over a drawing on object and to input a set of discrete co-
panel these two substances are connected and the resistance ordinate position which can be joined with straight line segments
at that point will drop down. The resistance drop is sensed to approximate the curve surface shape.
and the touch position is calculated. One type of digitizer is Graphics tablets (data tablets),
- In capacitance based touch panel, some charge is spread which is used to input two dimensional (2D) co-ordinate by
on the screen. When user touches the panel the charge is activity a hand curser or stylus as selected position, flat
drawn by finger form each side proportionally. The sensor surface. A had curser contains cross hairs for sighting position,
calculates the charge in frequency of charge/voltage and while a stylus is a pencil shaped device that is pointed to the
find out the touch position. position of the tablet. Many graphics tablets are constructed with
- In Acoustic(Sound) based touch panel uses very high a rectangular grid of wires embedded on the tablet surface.
frequency (5 Mhz). The sound waves are generated from Electromagnetic pulses are generated in sequence along the
X-axis and Y-axis sides are reflected from opposite side of wires and an electric signal is induced in a wire coil. In an
either axis. When user touches the panel, the sound waves activated stylus or hand curser to record tablet position.
7
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
Acoustic (Sonic) tablets use sound waves to detect a stylus
System Display
position. Either strip microphones or point microphones are used CPU Memory Processor
to detect the sound emitted by an electrical spark from a stylus (Graphic
controller)
tip. The position of the stylus is calculated by calculating the
arrival time of generated sound at different microphone position.
Application:
- Digitizing a drawing in a book. System bus
Date: 2065/4/19
Mouse
Keyboard
8
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
- It sends digital and points co-ordinates to a vector
generator that converts digital co-ordinates values to
analog voltages for beam deflection circuits that display an
electron beam writing on CRT phosphor coating.
- The main principal of the vector system is that the beam is
deflected form end point to end point as detected by
arbitrary order of the display commands term as random
scan.
- Since the light out put of phosphor decays in tens or
hundreds of microseconds, the display processor must
cycle through the display list to refresh the phosphor at
least 30 times per seconds (Hz) to have flicker hence the
buffer holding display list is usually called a refresh
buffer. (Note: jump instruction in the figure above in
Fig. Random scan system drawing through the component refresh buffer is to provide cyclic refresh.
lines of an object in any order specified. - A CRT beam in this system is adjusted in such a way that
electron beam only hits the spot where the graphics is to
- Graphics commands in the application program are be drawn.
translated by the graphic package in to a display file stored - Thus the refresh rate in this system depends upon the
in the system memory. number of lines to be displayed.
- This display file is then accessed by the display processor - Random scan display are design to draw all the component
to refresh the screen. lines of pictures 30 to 60 times per seconds.
- Sometimes the display processor in a random scan is - Vector display system are mostly used for line drawing
referred to as a display processing unit or a graphics applications and can not display realistic shaded scenes.
controller. - It produces smooth line drawing because the CRT beam
- The buffer stores the computer produce display list or directly follows the line path definitions that are stored in
display program which contains points and line plotting the form of line drawing commands.
commands with (x,y) and end point co-ordinates as well as Disadvantages:
character plotting commands. - When the number of command in the buffer goes high the
- The commands for plotting points lines and characters are system take long time to process and draw pictures.
interpreted by the display processor. - Cannot apply shading features.
9
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
- Stored intensity values are retrieved form the refresh
Date: 2065/4/20 buffer and painted on the screen on scan line (one row at a
Raster Display: time).
- It is suited for realistic scenes containing shading and
color pattern.
- In monochrome monitor frame buffer consists of one bit
per each pixel and for color monitor frame buffer consists
of 24 bits for each pixel.
- The refresh rate for this system is at the rate of 60 to 80
frame per second. i.e refresh rate are described in units of
cycle per second.
10
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
- Scan line are labeled from Ymax at the top of screen to zero
system Frame Video
CPU
memroy Buffer Controller at the bottom.
- Scan line are labeled from 0 to Xmax .
Date: 2065/4/21
Video Controller:
System bus Raster-scan
Generatro
I/O Device x y
Registor Registor
Fig. Architecture of a raster system with a fixed positon of
the system memory requred for the frame buffer
13
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
random scan system, whose vector generators must be highly 5. Another drawback of raster system arises from the nature of
accurate to provide linearity and repeatability of beam’s raster itself. A vector system can draw continuous, smooth line
deflection. (curves) from any point on the CRT face to other, the raster
system displays these lines (curves) mathematically using
3. One major advantages of raster graphics over vector graphics various algorithms causing problems of “jaggering” or
includes the ability to display areas filled with solid colors or “staircasing”.
patterns. Moreover, the refresh process is independent of
complexity (i.e. no. of lines) of image and each pixel in buffer
can be read out on each refresh cycles, allowing flicker free
display.
Date:2065/4/23
Electron gun
Shadow mask grid Date:2065/5/2
Chapter : 3
Magnified phosphorous
dot trigger
(x2,y2)
y2
Figure: Operation of delta shadow mask method
(x1,y1)
y1
Xk+1 = xk-1
Yk+1 = yk +m 18
For m >1, △y = -1 16
14
(11 ,17)
12
Yk+1 =y=k +1 ……………………(ix) 11 (10 ,15)
Xk+1= xk +1/m…………….(x) 10
8
6
Therefore , in general, 4
2
Yk+1 = y ± m x
xk+1 = xk ± 1 for m < 0 0
2 4 6 8 10 11 12 14 16 18 202224 26
yk+1= yk ± 1 S.N x y
xk+1 = xk ± 1/m for m >0 1 10 15
2 10 16
Eg. Example: Digitize a line with end points (10,15) and (15, 3 11 17
30). 4 11 18
Solution:
The slope of line is Comments:
y 2 − y1 30 − 15 15 1. It is faster to calculate pixel position.
m= = = =3 2. Due to propagation of round off errors due to successive
x 2 − x1 15 − 10 3
m >1
addition the calculated pixel may shift among from the
true line path.
So we sample at y interval. The formula is given by xk+1 = Algorithm:
xk+1/m. 1. Declare the variables, x1,y1 and x2 , y2 dx, dy ,del x, del y
as real and k as integer.
2. Perform
dx = x2-x1
dy = y2 – y1
3. Test if /dy/</dx/ then
Steps = /dx/
17
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
Else steps = /dy/
We have pk ≥ 0,
So, p1 = p0 + 2 △y – 2 △x 20
=1+2x3–2x5 19
= -3 18
17
P2 = p1+ 2 △y 16
11 12 13 14 15
= - 3+2 x 3
=3 # Digitize a line with end points ( 15, 15 ) and (10, 18 ) use BLE
and DDA.
P3 = p2 + 2△y – 2 △x Solution:
= 3+ 2 x 3 – 2 x 5
= 9 – 10 △y = /15-18/ = 3
= -1 △y = / 10-15/ = 5
m = 3/ 5 = 0.6
K Pk xk+1 , yk+1 m < 1, we sample at x direction,
0 1 11, 16 First pixel , ( 10, 15) Note:
1 -3 12, 16
P0 = 2 △y– △x For, Pk ≥ 0 ,
2 3 13, 17
=2×3–5 Pk+1 = pk+ 2△y – 2△x
3 -1 14, 17
=1 yk+1 = yk-1 ( when the slope is –ve )
4 5 15, 18
We know that, Pk < 0
If pk ≥ 0
Pk+1 = pk + 2△y
P1 = po + 2 △y – 2 △x Yk+1 = yk
=1+2x3–2x5
= -3
Pk < 0
P2 = pk + 2 △y.
= -3 + 2 x 3
20 =3
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
P3 = p2 + 2 △y – 2 △x 2. Load (x0, y0) into the frame buffer; that is plot the first
= 3 + 2×3 – 2× 5 point.
= -1
Pk < 0 3. Calculate constants △x, △y , 2 △y and 2 △y – 2 △x and
obtained the starting value for the decision parameter as ;
P4 = p3 + 2 △y
= -1+ 2×3 po = 2 △y – △x
=5
4. At each xk along the line, starting at k= 0 , perform the
following test:
K pk xk+1 yk+1
0 1 11 17
1 -3 12 17 If pk <0 the next point to plot is ( xk+1, yk) and pk+1 = pk +2 △y.
2 3 13 16 Otherwise , the next point to plot is ( xk+1, yk+1) and pk+1= pk+ 2
3 -1 14 16
4 5 15 15 △y – 2 △x
17
16
15
Case:II m > 1
10 11 12 13 14 15 16
Date: 2065/5/4 d1 d2
Bresenham’s line algorithm: yk+1
1. Input the tow line end points and store the end point in (x0,
y0)
xk x xk+1
21
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
= △y ( x- xk+1+x)
= △y ( 2x – xk+1 + x)
= △y ( 2x – 2xk + 1) [ since, xk+1 = xk+1]
⎛ y k +1 − b ⎞
yk+3
= △y{2 ⎜ ⎟ − 2xk − 1 }
y k+2 ⎝ m ⎠
y k+1
= △y/m{2(yk+1-b) – 2xkm – m}
yk
xk xk+ 1 xk+ 2 = △x { 2 ( yk+1 –b) – 2 xk (△y/△x) – △y/ △x}
= 2 △x( yk+1-b)- 2 △y . xk – △y
Let (xk, yk) be the pixel position determined then the next pixel = 2 △x yk – 2 △y xk + 2(1-b) △x – △y
to the plotted is either ( xk+1, yk+1) or ( xk, yk+1) Px = 2 △x yk – 2△y xk + c …………………..(ii)
Let d1 and d2 be the separation of the pixel positons ( xk, yk+1) Let C = 2 ( 1-b) △x – △y
and ( xk+1, yk+1) for the actual line path. Now for next step,
Y = mx +b
The actual value of x is given by Pk+1 = 2 △x yk+1 – 2 △y xk+1 + c………………….(iii)
x = (y-b)/m From equation (i) and (ii)
Sampling position at yk+1 Pk+1 – pk = 2 △x ( yk+1- yk) – 2 △y ( xk+1- xk)
Pk+1 = pk + 2 △x ( yk+1- yk) – 2 △y ( xk+1 – xk)
Form figure,
d1 = x - xk Where, , xk+1- xk = ‘0’ or ‘1’
d2 = xk+1 – x If pk ≥ 0
Let us define a decision parameter pk and Pk is defined by,
Pk+1 = pk + 2 △x – 2 △y
Pk = △y ( d1- d2) We plot , xk+1 = xk+1, yk+1 = yk+1
△y > 0 P< 0
Pk < 0 if d1 < d2 Pk+1 = Pk+ 2 △x
Pk ≥ 0, if d1 ≥ d2 Xk+1 = xk
xk xk+ 1 xk+ 2
(-x,y) (x,y)
Fig. Midpoint between candidate pixels at sampling position
(r,0) xk+1 along a circular path.
(-x,-y)
(x,-y) Here assume that we have just plotted the pixel (xk,yk ). We next
need to determine whether the pixel at position (xk+1,yk+1) on
(-y,-x) (y,-x) one at the position (xk+1,yk-1) is closer to the circle.
(-4,-3) (-2,0) -2
(4,-3) (6,0) -3
(3,4) (5,7) -4
(3,-4) (5,-1) -5
(-3,-4) (-1,-1) -6
(-3,4) (-1,7) -7
-8
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
Algorithm:
1. Get the input centre (xc, yc) and radius of the circle.
2. Set x = 0, and y = r.
3. Plot the first point and its symmetry at appropriate
positions by x = x+xc , y = y + yc
4. Compute the initial decision parameter. P = 1- r
5. Repeat the following till x < y.
i. Set x = x+1.
ii. Check if P< 0 then.
27
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
P = P+2x + 1 Let us define an ellipse function centered at origin by
Else, f(x, y)= b2x2 + a2y2 – a2b2 .
y = y-1 If f(x,y) < 0 , the point lies inside the ellipse.
p = p+2x – 2y +1 = 0, the point lies on the ellipse.
iii. Shift the point (x, y) and its symmetry points by x = > 0, the point lies outside the ellipse.
x+xc , y = y+yc and plot. Starting at ( 0,b) we take unit steps in x-direction until we
iv. sdf reach the boundary between region 1 region 2 ( R1 , R2 ) . Then
Ellipse: Ellipse is an elongated circle. Therefore elliptical we switch to unit steps in y-direction over the remainder of curve
curves can be generated by modifying circle –drawing in first quadrant. At each step, we need to test the value of the
procedures to take into account the different dimensions of an slope of the curve .The ellipse slope is calculated from equation :
ellipse along the major and minor axes. x2/a2 +y2/b2 = 1
The equation of ellipse in standard form is given by Differentiating both sides w.r to x
, 2x/a2 + 2y/b2. dy/dx = 0
x2/a2 + y2/b2 = 1 Dy/dx = -2b2x/2a2y
Therefore, y = +- b √(1-x2/a2) At the boundary region 1 and region 2 , dy/dx = -1 and
y 2b2x= 2a2y..
Therefore , we move out of region 1 (R1) when 2b2x ≥ 2a2y. For
R1
(0,b) region R1.
(-x,y)
(x,y) R2 b2x2+a2y2-a 2b2 = 0
2b
x
2a (a,0) yk
yk-1
(-x,-y) (x,-y)
(mid point)
tx
Transformation: Changing co-ordinate description of an object
is called transformation.
Types:
- Rigid body transformation ( transformation without
# Translate the given points (2,5) by the translating value (3,3)
defomation in shape. )
Solution:
- Non rigid body transformation (transformation with
(x,y) = (2,5)
change in shape)
Tx = 3
Ty = 3
Basic Transformations: Other Transformation
X’ = x+ tx
1. Translation 1.reflection
Y’= y+ty
2.Reflection 2.Shearing
⎡ x'⎤ ⎡2⎤ ⎡3⎤ ⎡5⎤
3.Scaling ⎢ y '⎥ = ⎢5⎥ + ⎢3⎥ = ⎢8⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
Two dimensional transformation:
1. Translation: Changing the co-ordinate position along a st.
line is called translation. P’(x’,y’)
If P(x,y) is taranslated to a position p’(x’,y’) by tx units parallel
to x-axis and ty units parallel to y axis then, p (x,y)
X’ = x+ tx
Y’ = y+ ty
In matrix form: Scaling: The co-ordinate position of an object by multiplying a
⎡ x ' ⎤ ⎡ x ⎤ ⎡t x ⎤ constant factor ( scaling factor) is called scaling.
⎢ y '⎥ = ⎢ y ⎥ + ⎢t ⎥
⎣ ⎦ ⎣ ⎦ ⎣ y⎦ Scaling Techniques:
i.e p’ = p+T where T is transformation matrix. a. About origin
b. About fixed point
32
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
About origin: If p(x,y) be scaled to a point p’(x’,y’) by sx times y
P’(x’,y’)
About origin: If p(x,y) is rotated to a new position p’(x’,y’) in
anti-clockwise direction by an angle θ , then (x’,y’) can be p (x,y)
calculated as following.
Let the angle made by line OP with x-axis is α and the radius of θ
circulation path is r then, α
x = r cosα (xr , yr)
y = r sinα x
Also, o x- xr
x’ = r cos(θ +α )
y’ = r sin( θ + α ) Do yourself .
x’ = r(cosθ. Cosα – sinθ. Sinα ) # Rotate the triangle having co-ordinates (1,2) , (2,3) (4,5) by 60
x’ = xcosθ – y sinθ
˚ about origin.
y’ = r( sin θ. Cosα + cos θ .sinα)
= xsinθ + y cosθ
In matrix form: Date: 2065/5/18
Matrix Representation and Homogeneous Co-ordinates:
⎡ x'⎤ ⎡cos θ − sin θ ⎤ ⎡ x ⎤
To treat all the transformation in the same manner, homogeneous
⎢ y '⎥ = ⎢ Sinθ cos θ ⎥ ⎢ y ⎥ co-ordinate are used for reapresentation. Each points (x,y) is
⎣ ⎦ ⎣ ⎦⎣ ⎦ represented by triple (x,y,h).
(x,y,h) and (x’,y’,h’) represent same point if on one is multiple
Note: θ +ve ( anticlock wise) of other.
θ –ve ( clock wise ) Ie x’/x = y’/y = h’/h
b. About any point: if (x,y) is rotated to a new position So, (x,y,h) and (x/h, y/h,1) also represent same point, for
p’(x’,y’) by an angle θ, then (x’, y’) can be calculated as simplicity we use h = 1.
following. Therefore, (x,y) in Cartesian system is represented as (x,y,1) in
Now x –xr = r cosα homogeneous co-ordinate system.
Y – yr = r sin ( θ +α ) Now (2×2) matrix is changed into 3× 3 matrix,
34 For translation:
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
⎡ x ' ⎤ ⎡1 0 t x ⎤ ⎡ x ⎤ Let p be the point translated by T(tx1,ty1) to point p’ then,
⎢ y '⎥ = ⎢0 1 t ⎥ ⎢ y ⎥ P’ = T (tx1,ty1). P
⎢ ⎥ ⎢ y ⎥⎢ ⎥
⎢⎣ z ' ⎥⎦ ⎢⎣0 0 1 ⎥⎦ ⎢⎣ z ⎥⎦ Let p’ be the point translated by T(tx2,ty2) to point p’’ then,
P’’ = T (tx2, ty2). P’
Therefore, p’ = T(tx,ty ).p
= T (tx2,ty2).T (tx1,ty1).p
For Rotation (about origin)
Net transformation = T(tx2,ty2). T (tx1,ty1)
⎡ x'⎤ ⎡cos θ − Sinθ 0⎤ ⎡ x ⎤
⎢ y '⎥ = ⎢ Sinθ ⎡1 0 t x1 ⎤ ⎡1 0 t x1 ⎤
cos θ 0⎥⎥ ⎢⎢ y ⎥⎥
⎢ ⎥ ⎢ = ⎢⎢0 1 t y1 ⎥⎥ ⎢⎢0 1 t y1 ⎥⎥
⎢⎣ z ' ⎥⎦ ⎢⎣ 0 0 1⎥⎦ ⎢⎣ z ⎥⎦
⎢⎣0 0 1 ⎥⎦ ⎢⎣0 0 1 ⎥⎦
P’ = R(θ ). P
⎡1 0 fx1 + fx 2 ⎤
For Scaling : (about origin) = ⎢⎢0 1 fy1 + fy 2 ⎥⎥
⎡ x'⎤ ⎡ s x 0 0⎤ ⎡ x ⎤ ⎢⎣0 0 1 ⎥⎦
⎢ y '⎥ = ⎢ 0 sy 0⎥⎥ ⎢⎢ y ⎥⎥ = T(tx1+ tx2, ty1+ty2)
⎢ ⎥ ⎢
⎢⎣ z ' ⎥⎦ ⎢⎣ 0 0 1⎥⎦ ⎢⎣ z ⎥⎦ ∴ T(tx1,ty2). T(tx1,ty1) = T(tx1+ tx2, ty1+ty2)
Which demonstrates that two successive translations are
Inverse Transformation: additive.
For inverse translation:
T-1 (tx,ty )= T ( -tx , -ty )
# Prove that two successive rotations are additative. i.e R(θ2) .
For inverse Rotation: R(θ1) = R(θ1 +θ2)
R-1 (θ = R( -θ ) Solution:
Let p be the point rotated by R(θ1) to point p’ then p’ = R(θ1 )
For inverse scaling: .p
s-1(sx,sy) = S(1/sx, 1/sy) Let p’ the point rotated by R(θ2) to point p’’ then
P’’ = R(θ2). P’
# Prove that two successive translations are additive. Net transformation = R(θ2). R(θ1)
i.e T(tx, ty). T(tx2,ty2) = T(tx1 +tx2, ty1 +ty2). P’ = R(θ1+ θ2 ) p
B(5,8)
C (10,10) ⎡ 2/ 2 2/ 2 0⎤ ⎡10⎤ ⎡ 20 / 2 + 20 / 2 + 0 ⎤ ⎡40 / 2 ⎤
⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎢− 3 / 2 3/ 2 0⎥ ⎢⎢10⎥⎥ = ⎢− 30 / 2 + 30 / 2 + 0⎥ = ⎢ 0 ⎥
⎢ 0 0 1⎥⎦ ⎢⎣ 1 ⎥⎦ ⎢ 0 + 0 + 0 +1 ⎥ ⎢ 1 ⎥
Step 1: Rotation by 45˚ (clock wise) ⎣ ⎣ ⎦ ⎣ ⎦
Step-II: Scaling by (2,3) ¾
S(2,3) Note from miss:
Net transformation: = S(2,3). R(-45)
⎡2 0 0⎤ ⎡ cos 45 − Sin 45 0⎤ General pivot point rotation: We can rotate any selected point
= ⎢⎢0 3 0⎥⎥ ⎢⎢− Sin45 cos 45 0⎥⎥ (xr,yr) by following the sequence of translate – rotate –translate
⎢⎣0 0 1⎥⎦ ⎢⎣ 0 0 1⎥⎦ operations.
36
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
Step 1: Translate the object such that fixed pont moves to origin Net Transformation (T) = T(xr,yr). R(θ). T(-xr,-yr)
i.e T(-xr,-yr) . ⎡1 0 x r ⎤ ⎡cos θ − sin θ 0 ⎤ ⎡1 0 − x r ⎤
Step 2: Rotate the object coordinate origin i.e R(θ) . = ⎢⎢0 1 y r ⎥⎥ ⎢⎢ sin θ cos θ 0⎥⎥ ⎢⎢0 1 − y r ⎥⎥
⎢⎣0 0 1 ⎥⎦ ⎢⎣ 0 0 1⎥⎦ ⎢⎣0 0 1 ⎥⎦
Step 3: Translate back the object so that the pivot point is
returned to its original position T(xr,yr).
General Fixed point Scaling:
This transformation sequence is illustrated in fig below.
A transformation sequence to produce scaling with respect
to a selected fixed position (xf, yf) using a scaling function is
illustrated below:
(xr,yr) 1. Translate the object so that the fixed point coincides with the
co-ordinate origin.
2. Scale the object with respect to the co-ordinate origin.
3. Use the inverse translation of step 1 to return the object to its
original position.
(a) Original position of object (b) Translation of object so
And pivot point that povit point (xr,yr) The transformation sequence is illustrated in fig below:
is at origin.
(xr,yr)
(xr,yr)
(c) Rotation about origin (d) Translation of object so (a) Original position of object (b) Translate object
That the pivot point is And fixed point so that fixed point
Returned to position (xr, yr) is at origin.
(xr, yr)
37
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
y
A(7,15)
x y
( r, r)
C(10,10)
B(5,8)
x
Other transformation:
38
1. Reflection
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
2. Shearing. P’ = Rfy.P
Reflection: Providing a mirror image about an axis of an object Rfy = Reflection matrix about y-axis
is called reflection. y
In matrix from, 3’ 3
⎡ x ' ⎤ ⎡1 0 0 ⎤ ⎡ x ⎤ x
⎢ y '⎥ = ⎢0 − 1 0⎥ ⎢ y ⎥
⎢ ⎥ ⎢ ⎥⎢ ⎥
⎢⎣ 1 ⎥⎦ ⎢⎣0 0 1⎥⎦ ⎢⎣ 1 ⎥⎦
P’ = Rfx.P
Rfx = Reflection matrix about x-axis
y
1 Date: 2065/6/6
Alternative way for reflection:
Original position
Step:1
2 3 Rotate the object so that y axis concise x-axis. i.e R(-90)
x Step: 2
2’ 3’ Reflection about x-axis. Rfx
Step: 3
Reflected object
Rotate back the object so that y-axis move to original position .
1’
R(-90)
Net transformation:
(ii) about y-axis (x=0) i.e Rfy = R(90) . Rfx. R(-90)
x’ = x ⎡cos 90 − sin 90 0⎤ ⎡1 00⎤ ⎡ cos 90 sin 90 0⎤
y’ = y = ⎢⎢ sin 90 cos 90 0⎥⎥ ⎢⎢0 − 1 0⎥⎥ ⎢− sin 90 cos 90 0⎥
⎢ ⎥
In matrix from, ⎢⎣ 0 0 1⎥⎦ ⎢⎣0 0 1⎥⎦ ⎢⎣ 0 0 1⎥⎦
⎡ x '⎤ ⎡ − 1 0 0⎤ ⎡ x ⎤ ⎡0 − 1 0⎤ ⎡1 0 0⎤ ⎡ 1 1 0⎤
⎢ y '⎥ = ⎢ 0 1 0⎥ ⎢ y ⎥
⎢ ⎥ ⎢ ⎥⎢ ⎥ = ⎢⎢1 0 0⎥⎥ ⎢⎢0 − 1 0⎥⎥ ⎢⎢− 1 0 0⎥⎥
⎢⎣ 1 ⎥⎦ ⎢⎣ 0 0 1⎥⎦ ⎢⎣ 1 ⎥⎦ ⎢⎣0 0 1⎥⎦ ⎢⎣0 0 1⎥⎦ ⎢⎣ 0 0 1⎥⎦
39
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
⎡0 − 1 0⎤ ⎡0 1 0 ⎤ y’ = x
= ⎢⎢1 0 0⎥⎥ ⎢1 0 0 ⎥
⎢ ⎥
y
⎢⎣ 0 0 1⎥⎦
p(x,y) p’(x’,y’)
45
x
⎢ ⎥
⎢⎣ ⎥⎦ 45
x
⎡1 − m 2 2m − 2bm ⎤ (-b,0)
⎢ ⎥
⎢1 + m 1+ m 1 + m2 ⎥
2 2
2m m −12
2b ⎥
=⎢
⎢1 + m 2
1+ m 2
1 + m2 ⎥
⎢ 0 0 1 ⎥
Shearing: Transformation that causes deformation in the
⎢ ⎥ original object by supposing as if the object is composed of
⎢⎣ ⎥⎦
internal layers and these layers are caused to slide over is
y
shearing.
(0,b)
θ
x
(-b,0)
42
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
y y’
A B x1
The procedure that identifies these portions of the picture that are
x
x’ either inside or outside of the specified region of span is
About x-axis clipping .
y’ = y
x’= x+x1 where, Line clipping:
x1 α y p2
A
p3
x1 = Shx.y p2’ A’
where, Shx is shearing constant.
y’ = y
x’= x+shx.y p1’
In matrix form, clip
p1
⎡ x'⎤ ⎡1 sh x 0⎤ ⎡ x ⎤
⎢ y '⎥ = ⎢0 1 0⎥⎥ ⎢⎢ y ⎥⎥
B’
⎢ ⎥ ⎢ B
⎢⎣ 1 ⎥⎦ ⎢⎣0 0 1⎥⎦ ⎢⎣ 1 ⎥⎦
Similarly about y-axis Cohen Sutherland line clipping:
x’ = x In this method, every line endpoint is assigned a four digit
y’=y+shy.x binary code(region code) that identifies the location of the point
⎡ x'⎤ ⎡ 1 0 0⎤ ⎡ x ⎤ relative to the boundary.
⎢ y '⎥ = ⎢ sh 1 0⎥⎥ ⎢⎢ y ⎥⎥
⎢ ⎥ ⎢ y For,
⎢⎣ 1 ⎥⎦ ⎢⎣ 0 0 1⎥⎦ ⎢⎣ 1 ⎥⎦ b1 : left
P’ = SHy.p b2 : right
b3 : below
2D window clipping: b4 : above
43
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
1000 The lines which con not be identified as completely inside or
outside a window by these tests are checked for intersection with
1001 0000 1010 the window boundary. Such lines may or may not cross into the
window interior.
0101 0100 In the fig. aside , region code of
0110
P1 = 0001
P2 = 1000
p3
p2 P1 AND P2 = 0
(xwmin, ywmax) (xwmax, ywmax)
So we need future calculation.
p2’ p3’
p4 Starting form p1,
Intersection of P1 with left boundary is calculated.
p1 Region code of P1’ = 0000
(xwmin, ywmin) (xwmax, ywmin) P1’ AND P2 = 0 .
Intersecting of P2 with above boundary is calculated region code
of p2’ = 0000
Since both end points have region codes (0000) .So P1’, P2’
portion of the line is saved.
Similarly,
The value 1 indicates its relative position. If a point is within For P3 , P4.
clipping rectangle then region code is 0000. So , P3 = 1000
If x – xwmin < 0 , b1 = 1 P4 = 0010
If xwmax – x < 0 , b2 = 1 P3 AND P4 = 0
If y – ywmin < 0 , b3 = 1 So we need further calculations; starting form P3 region code of
If ywmin – y < 0 , b4 = 1 P3 is 1000, i.e b4 is high, so intersection of P3 with upper
If the region codes of both end points are 0000 then we accept boundary which yields P3’ having region code 0010.
the line. Again p3’ AND P4 ≠ 0
Any line that have one in the same bit position is rejected i.e So P3P4 is totally clipped.
if RA AND RB ≠ 0 The intersection point with vertical boundary can be obtained by
Line is completely outside . y = y1 + m(x-x1)
44
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
Where (x1,y1) and (x2,y2) are end points of line and y is the co- view areas are selected, these areas can be placed in separate
ordinate value of intersection point where x value is either xwmin display locations or some areas could be inserted into other,
or xwmax and m = y2 –y1 / x2 – x1 . larger display area. Transformations from world to device co-
Similarly , intersection point with horizontal boundary ordinates involve translation rotation and scaling operations, as
x = x1 + (y-y1)/m well as procedures for deleting those parts of the picture that are
Where , y = ywmin or ywmax outside the limits of a selected display area.
A world co-ordinate area selected for display is called a
# Use cohen Sutherland algorithm to clip the line for the window. An area on the display device to which a window is
following dimensions. Line endpoints (15, 45) and (25,15) mapped is called a view port. The window defines what is to be
Window: viewed. The viewport defines where it is to be displayed.
Lower left: ( 10, 20) Often, windows and viewports are rectangles in standard
Upper right : ( 30, 40) positions, if the rectangle edges are parallel to the co-ordinate
axis.
“ The mapping of a port of a world co-ordinate scene to a
Date: 2065/6/7 device co-ordinates is referred to as viewing transformation.”
Sometimes , the 2D viewing transformation is simply referred to
Two dimensional object to screen viewing Transformation: as the window – to – viewport transformation or the windowing
transformation.
Mechanism for displaying view of a picture on an output Fig. given below illustrates the mapping of a picture
device: selections that falls within a rectangular window onto a
designated rectangular viewpoint.
A graphical package allows a user to specify which part of the
defined picture is to be displayed and where that part is to be
placed on the display device. Any convenient Cartesian co- y wmax y vmax
ordinate system; referred to as the world co ordinate reference
frame can be used to define the picture.
For a 2-D picture, a view is selected by specifying a subarea of y wmin y vmin
the total picture area. A user can select single area for displaying
or several areas could be selected for simultaneous display. The
picture parts within the selected areas are then mapped onto x wmin x wmax x vmin x vmax
specified areas of the device co-ordinates. When the multiple World Co-ordinate Device co-ordinate
45
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
Fig. A viewing transformation using standard rectangles for the yworld
- Map the normalized viewing co-ordinate to device co- World co-ordinate Normalized device co-ordinate
ordinate system.
These steps can be illustrated through a pipeline.
By changing the position of the viewport we can view objects at
different positions on the display area of an output device. Also
Construct world
co-ordinate Convert world
Map viewing
co-ordinates to Map normalized
DC
by varying size of the viewport we can change the size and
VC Normalized viewing NVC viewpoint to
scene using
modeling co-ordinate
WC Co-ordinates
to viewing co-ordinates device
co-ordinate
proportions of displayed objects.
co-ordinate using window
transformation viewpoint
Specification
Window to viewport transformation:
Fig. The two dimensional viewing transformation pipeline
y wmin y vmin
46
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
It is the mechanism for displaying view of a picture on an output The value of sx and sy is found by calculating the position of
device. The world co-ordinate selected for display is called (x,y) in the window to the corresponding position of point (u,v)
window. The area on the display device to which window is in the viewpoint.
mapped is called viewport. So, window defines what is to be To maintain the same relative position, so
viewport defines where it is to be displayed. The mapping of part x − x w min u − x v min
=
of world co-ordinate scence to device co-ordinate is called x w max − x w min x v max − x v min
viewing transformation or window-to-viewport transformation. y − y w min u − y v min
Or, =
y w max − y w min y v max − y v min
x − x w min
S x = v max
x w max − x w min
(xwmax,ywmax) (xvmax, yvmax)
y − y w min
S y = v max
(x,y) (u,v) y w max − y w min
∴ Twv =
(xwmin,ywmin) (xvmin,yvmin) − x w min
⎡ x v max ⎤
⎢x 0 0⎥
⎡1 0 x v min ⎤ − x w min ⎡1 0 − x w min ⎤
⎢ w max ⎥
⎢0 1 y v max − y w min
⎢ y v min ⎥⎥ ⎢ 0 0⎥ ⎢0 1 − y
⎢
⎥
w min ⎥
⎢ y w max − y w min ⎥
Window – to – viewport transformation can be explained as: ⎢⎣0 0 1 ⎥⎦ ⎢ ⎢⎣0 0 1 ⎥⎦
- Choose the world co-ordinate in a rectangle. 0 0 1⎥
⎢ ⎥
- Transform it to origin. ⎣⎢ ⎥⎦
- Scale it with appropriate value. Is the required window- to – viewpoint transformation.
- Transform it to the relative position in viewport.
# Determine window to view port transformation for the
Step 1: T (-xwmin, -ywmin) following dimensions of windows and viewpoint.
Step:2: S (sx, sy) Window viewpoint
Step:3: T(xvmin, yvmin) Lower left corner (5,10) (8,12)
Upper right corner (15,20) (12,18)
∴ Net transformation,
Different types of Graphical package are:
Twv = T (xvmin, yvmin). S(sx, sy).T(-xwmin, -ywmin)
1. GKS (Graphical kernel system)
47
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
2. PHIGS(programmers Hierarchical interactive graphics - Update – Update information associated at some location
standard) in the stack.
3. GL(Graphics Library) The most recently pushed element can be checked prior to
4. Open GL. performing a pop operation.
A stack is based on the last in first out algorithm (LIFO) in
which insertion and deletion operations are performed at one end
Data Structural Concept: of the stack. The most accessible information in a stack is at the
top of the stack and least accessible information is at the bottom
Introduction: of the stack.
Data may be organized in different ways; the logical or If someone wants to delete on item from an empty stack, it
mathematical model of a particular organization of data is called causes underflow and if someone wants to add an element to the
data structure. In other words, data structure is a collection of stack (which is already full) then it is the case of overflow.
data elements whose organization is characterized by accessing
operations that are used to store and retrieve individual data
A Top of the stack
elements.
B
Data structure is of two types:
1. Linear data structure. E.g Array, stack, Queue etc. C
(c) (d)
Step 2: [ Increment rear poi
nter] Circular queue:
Rear = rear+1 Suppose we have an array Q that contains n element in
Step 3: [Insert an item ]
50 which Q1 comes after Qn in the array. When this technique is
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
used to construct a queue then the queue is called the circular (viii) 77 66 55 (x) 44 33 77 66 55
queue. In other words we can say that a queue is called circular
when the last room comes just before the first room. Fig given Delete 88
Insert 33
F R
below show the circular queue . R F
Q[2]
Linked List :
Q[1]
node
Each node has two port.
(i) (iv) 99 88 77
• information
• Pointer to the next node.
Front Rear F R
(ii) 99 (v) 99 88 77 66 Information part may consist of one or more than one fields. In
other words a linked list consist of a series of a structure contains
Insert 99 Insert 66 one or more then one contiguous information fields and a pointer
FR F R to a structure containing its successor. The last node of the list
contains NULL (‘\0’).
(iii) 99 88 (vi) 88 77 66
The pointer contains the address of the location where
Insert 88 the next information is stored. A linked list also contains a list
F
Delete 99
pointer variable called start, which contains the address of the
F R
first node is the list. Hence , there is an arrow drawn from start
(ix) 44
(vii) 88 77 66 55 77 66 55
to the node in the linked list. If there is no node in the list, the is
Insert 44
called NULL list or EMPTY list.
Insert 55
F R F The different operations performed on the linked list are:
(1) Insertion:
a. Inset a node at the beginning of the list.
51 b. Inset a node at the end of the list.
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
c. Inset a node between the nodes. in the figure above. Now it is possible to define a doubly linked
(2) Deletion as a collection of nodes, each nodes having three fields.
a. Delete a node at the beginning of the list. - pointer to previous node ( pointer to predecessor)
b. Delete a node at the end of the list. - Information field
c. Delete a node between the nodes. - Pointer to next node (pointer to successor)
(3) Traversing . : Traveling from one node to another node. Different operations performed on doubly linked list are:
1. Insertion 2. Deletion 3. Traversing.
Doubly linked list:
A singly linked list is so named because each list element Non linear data structure:
contain a pointer to the next element . In that list traveling is (1) Trees
possible only in one direction. Some times it is required to
transverse the list in either direction forward or backward. This N1
T1
involves the performance and efficiency of algorithms. So T3
T2
traversing of linked list in both the directions requires nodes N2 N13
N4
having the links as given in figure below: N3
N12
information
N5 N6 N8 N11
right link N9
N10
right link N18
N14 N7
left link
left link
N15
N16
N17
node
N
Fig. Tree T having 18 nodes
N =NULL = ‘\0’
A tree T is defined as a set of finite set of one or more nodes
such that.
Doubly linked list
- There is a special node called the root R.
- The remaining nodes are divided into n ≥ 0
The links are used to denote the predecessor and successor of a Disjoint sets T1,T2,T3,………Tn , where each of these set is a
node. The link denoting the predecessor of a node is called the tree . T1, T2, T3,……Tn is called the subtree of the root.
left link and that denoting its successor is right link. A list with The root node N1 has three subtrees T1,T2,T3 and the roots of
this type of arrangement is called Doubly Linked List as shown 52 these subtrees are N2,N3,N4 respectively . The roots of these
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
subtrees of a node is called its degree, root N1, has degree 3. left successor of R. If T2 is not empty then the root of T2 is
Similarly node N5 has degree 5 and node N14 has degree 0. A known as right successor of R.
node with degree 0 is called leaf.
N6,N7,N8,N9,N10,N11,N12,……N18 are called leaf nodes. The R R
leaf nodes are also called Terminal nodes and rest of nodes in a ROOT 1
Binary tree T1 T2
tree is called non-terminal.
A B 2 3
Forest:
Left child Right child 4 5 7
6
N1
N2
Expression :
N5 N3
E = v + u/x* y-z
N6 N7 _
Z
N18 N8
N9
N14
N15 +
N16 V
N17
*
A forest is a set of n ≥ 0 disjoint trees, where n represents no of
y
nodes in the tree. The meaning of forest is very close to a tree .
because if we remove the root of a tree, we get a forest. For e.g
in the fig. above we remove N1, we get the forest of three trees. u
x
It is shown in the figure above.
8 9 10 11 12 13 14 15 v2
Level 3 e1
e4
Level 4 e2
e3
Level 5 v3
v1
Fig.(f)
54
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
v1 e1 y
v2
e5 e8
e6 e2
v4
e4 e7
xy-plane
v5 v3
e3 x
E = {(v1,v2), (v2,v3), (v3,v4),(v4,v5),(v5,v1)} xz-plane
If we consider the element of E, we find that E is a set of five
tuples, i.e for edge. z
e1 = (v1,v2)
e2 = (v2,v3) The 3D viewing process is inherently more complex then is the
e3 = (v3,v4) 2D viewing process. In 2D we simply specify specify the
e4 = (v4,v5) window on 2D world and a viewpoint on the 2D-view surface.
e5 = (v5,v1) Conceptually objects in the world are clipped against the window
From e1 and e2 we find that v2 is common in both. In the e1 , v2 and are then transformed into the viewpoint for display. The
is the terminal vertex and it is initial vertex of e2. Similarly in e2 extra complexicity 3D-viewing is caused in the part by the added
and e3 , v3 is corner and so on. Thus we can say that there is dimensions and in part by the fact that display device are only
cycle and there exist a circular path that is shown by the dark line 2D
in the above fig. The solution is mismatch between 3D object and 2D displays
is accomplished by introducing projections which transforms 3D
Date: 2065/7/24 objects onto a 2D-projection plane.
Three dimensional Graphics: In 3D-viewing , we specify a new volume in world a
6.1 Three Dimensional object to screen perspective viewing projection onto a projection plane and a viewport on the view
Transfomation: surface. Conceptually objects in the 3D-new volume and are then
projected. The content of the projection of the new volume onto
the projection plane, called the window, are then displayed
(transformed into the view port for display). Figure below shows
the conceptual model of the 3D-viewing process.
o/p Clipped world Projector Transformation into 2D-device
Co-ordination view port in 2D Co-ordinate
primitive co-ordinate Projection to
Clip against Projection plane device co-ordinate
new volume For device
55
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
projection we extend parallel lines from each vertex plane of the
Fig. Conceptual model of 3D-viewing process. screen.
Equation of line in 2D is
Projections: Projections transform points in a co-ordinate (y-y1)/(x-x1) = (y2-y1)/(x2-x1)
system of dimension ‘n’ into points in a co-ordinate system of In parametric form,
dimension less than ‘n’ projection of 3D-object is defied by x = x1+(x2-x1)u
straight projection rays (Called projectors) emanding from a y = y1+(y2-y1)u u ε [0,1]
centre of projection, passing through each point of the object and
intersecting a projection plane to form the projected object. If the Similarly in 3D,
projection is onto a plane (rather than some curved surface) and x = x1+(x2-x1)u
uses straight objectors (rather then curved) then we call it planar- y = y1+(y2-y1)u
geometric projection. y = z1+(z2-z1)u
Let direction of projection is given by vector [xp,yp,zp] and the
Types of Geometric Projection: image is to be projected on the xy-plane. If we have a point on
1. Parallel projection the object at (x1,y1,z1) and the projected point be (x2,y2) then the
2. Perpesctive projection. equation of the line is ,
x = x1+xpu
Parallel projection: y = y1+ypu
z = z1+zpu
projectors
A’ A But on the xy plane
projectors AA’ and
0 = z1+zpu
∴ u = -z1/zp
Centre of BB’ are parallel
projection at
infinity
B’ B
x2 = x1-z1(xp/zp)
projection plane
(plane of projection POP) y2 = y1-z1(yp/zp)
Fig. line AB and its parallel projection A’B’
59
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
y y
Rz = ⎢ z
⎢ 0 0 1 0⎥ About y-axis:
⎢ ⎥
⎣ 0 0 0 1⎦ Y’ = y
z = zcosθ – xsinθ
x = zsinθ+ x cosθ
60
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
y
y
Date: 2065/7/27
Rotation about any co-axis:
Rotation axis
x
x
z (b) Translate rotation axis into x-axis
z (a) original position of object
61
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
r r
△ = p 2 − p1 = (x2,y2,z2) – (x1,y1,z1)
y
y
P’1
θ P’1 (ii) For step II rotation can not be performed directly since the
rotation is not about any of the co-ordinate axis hence. It is
x
x P’’2 done in two steps.
z
z
(c) Rotate p2’ onto the z-axis
(d) Rotate the object around z-axis (a) Rotation by angle α about x axis.
y y (b) Rotate by angle β about y axis.
y y
P2 u’
(a,b,c)
P’2
(a,b,c)
P1 Rx(α)
P’1 α α x
Ryβ)
x x β
uz(0,0,1)
z u u’’
(e) Rotate the axis to original z (f) Rotate the rotation axis to its z z
orientation original position.
Step (a)
Let p1, p2 be the two end points of axis of rotation then the axis Angle for rotation of u around x-axis into xz plane is equal to
vector is given by:
62 angle between u’ (projection of u on yz plane and z-axis ).
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
r r
u '.u z
Cosα = r r =
(0, b, c )(. 0,0,1) = c Step: 3
u'.uz b2 + c2 d ⎡cos θ − sin θ 0 0⎤
⎢ sin θ cos θ 0 0⎥⎥
r r Rz(θ) = ⎢
u '×u z (0, b, c )(
. 0,0,1) b ⎢ 0 0 1 0⎥
Sinα = r r = = Where, d = b 2 + c 2 ⎢ ⎥
u'.uz b + c2
2 d ⎣ 0 0 0 1⎦
Step: 4
⎡1 0 0 0⎤ ⎡1 0 0 0⎤ (a) R-1y(β)
⎢0 cos α − sin α 0⎥⎥ ⎢0 c / d −b/d 0⎥⎥ (b) R-1x(α )
∴ Rx (α) = ⎢ = ⎢
⎢0 sin α cos α 0⎥ ⎢0 b / d c/d 0⎥
⎢ ⎥ ⎢ ⎥ Step: 5
⎣0 0 0 1⎦ ⎣0 0 0 1⎦
Steps (b) T(x1, y1,z1)
U moves to the position u’’ after being rotated by α about x-axis ∴ Net transformation,
r
so the position of u ' ' is given by = T(x1,y1,z1). R-1x(α ) R-1y(β) R2(θ). Ry(β).Rx(α )T(-x,-y,-z)
u’’ = Rx(α ).u
⎡1 0 0 0⎤ ⎡ a ⎤ ⎡ a ⎤ Date:2065/7/28
⎢0 c / d − b / d 0⎥⎥ ⎢⎢b ⎥⎥ ⎢⎢ 0 ⎥⎥
=⎢ = Reflection:
⎢0 b / d c / d 0⎥ ⎢ c ⎥ ⎢ d ⎥
⎢ ⎥⎢ ⎥ ⎢ ⎥
⎣0 0 0 1⎦ ⎣1 ⎦ ⎣ 1 ⎦ (i) About Axis: Reflection about axis is equivalent to 180˚
r r rotation about the axis.
β = angle between u ' ' and u z
r r
u ' '×u z (a,0, d )(. 0,0,1) About z-axis:
cosβ = r r = =d ⎡cos 180 − sin 180 0 0⎤
u' '.uz a2 + d 2 ⎢ sin 180
r r cos 180 0 0⎥⎥
u ' '×u z (a,0, d ) × (0,0,1) Rfz – Rz(180˚) = ⎢
Sinα = r r = = −a ⎢ 0 0 1 0⎥
u' '.uz a2 + d 2 ⎢ ⎥
⎣ 0 0 0 1⎦
⎡ cos β 0 sin β 0⎤ ⎡ d 0 −a 0⎤ ⎡− 1 0 0 0⎤
⎢ 0 ⎢ 0 −1 0 0⎥⎥
1 0 0⎥⎥ ⎢⎢ 0 1 0 0⎥⎥ =⎢
Ry(β ) = ⎢ = ⎢0 0 1 0⎥
⎢− sin β 0 cos β 0⎥ ⎢ a 0 d 0⎥
⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎣ 0 0 0 1⎦ ⎣ 0 0 0 1⎦ ⎣0 0 0 1⎦
About x-axis:
63
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
Rfx = Rx(180) ⎡1 0 0 0⎤
⎡1 0 0 0⎤ ⎢0 − 1 0 0⎥⎥
⎢0 cos 180 − sin 180 Rfxz = ⎢
0⎥⎥ ⎢0 0 1 0⎥
=⎢ ⎢ ⎥
⎢0 sin 180 cos 180 0⎥ ⎣0 0 0 1⎦
⎢ ⎥
⎣0 0 0 1⎦ (c ) about yz-plane (x-axis):
About y-axis: ⎡− 1 0 0 0⎤
Rfy = Ry(180) ⎢0 1 0 0⎥⎥
⎡ cos 180 0 sin 180 0⎤ Rfyz = ⎢
⎢0 0 1 0⎥
⎢ 0 1 0 0⎥⎥ ⎢ ⎥
=⎢ ⎣0 0 0 1⎦
⎢− sin 180 0 cos 180 0⎥ About any plane:
⎢ ⎥
⎣ 0 0 0 1⎦ Step:1: Translate the plane such that it passes through origin i.e
normal vector passes through origin.
(ii) About any axis:
Step:2: Rotate the plane such that normal vector lies on one of
Net transformation: the co-ordinate axis.
T (x1,y1,z1) Rx (-α) Ry(-β) . Rfz Ry(β). Rx (α) T(-x1,-y1,-z1) Step:3: Perform reflection about the plane whose normal vector
(iii) About plane: is one of the co-ordinate axis.
X’ = x ,
Y’ = y Step:4: Rotate back the plane such that normal vector takes its
Z’ = z original orientation.
(a) about xy plane (z-axis)
⎡1 0 0 0⎤ Step5: Translate back the plane to its original position.
⎢0 1 0 0⎥⎥
Rfxy = ⎢
⎢0 0 −1 0⎥ Shearing:
⎢ ⎥
⎣0 0 0 1⎦ In 2D, shearing about x-axis means x-values changes by
(c) about xz plane (y-axis): amount proportional to y-values and y-values remains same.
However in 3D, z-axis means x and y value change by
amount proportional to z-value and z-value remains same.
i.e x’= x+ Shx.z
64
Downloaded from www.jayaram.com.np
Downloaded from www.jayaram.com.np
y’ = y + Shy.z
z’ = z
⎡ x ' ⎤ ⎡1 0 S hx 0⎤ ⎡ x ⎤
⎢ y '⎥ ⎢0 1 S hy 0⎥⎥ ⎢⎢ y ⎥⎥
⎢ ⎥=⎢
⎢ z ' ⎥ ⎢0 0 1 0⎥ ⎢ z ⎥
⎢ ⎥ ⎢ ⎥⎢ ⎥
⎣ 1 ⎦ ⎣0 0 0 1⎦ ⎣ 1 ⎦
Similarly,
⎡ 1 0 0 0⎤
⎢S 1 0 0⎥⎥
SHx = ⎢ hx
⎢ S hx 0 1 0⎥
⎢ ⎥
⎣ 0 0 0 1⎦
⎡1 S hx 0 0⎤
⎢0 1 0 0⎥⎥
SHy = ⎢
⎢0 S hx 1 0⎥
⎢ ⎥
⎣0 0 0 0⎦
65
Downloaded from www.jayaram.com.np