SlideShare a Scribd company logo
Computer Graphics
By: Smruti Smaraki Sarangi
Assistant Professor
IMS Unison University,
Dehradun
1
C O N T E N T S
Sl.no Chapter Page
1 Introduction to graphics, and its application 2-6
2 Video display devices: CRT, Flat panel display, Raster Scan system,
Random scan system, Input and Output devices, Graphics software and
Functions, GUI.
7-29
3 Line drawing algorithms, Circle generating and ellipse generating
algorithms, Filled area primitives: flood-fill, boundary-fill and scan-line
polygon fill algorithm and antialiasing.
30-59
4 Line attributes, Curve attributes, Area-fill attributes, Character attributes,
Bundled and Marker Attributes
60-75
5 2D basic transformation, 2D composite transformation, Matrix
representation and homogeneous co-ordinate, Transformation between co-
ordinate system and Affine transformation
76-102
6 Viewing Pipeline, View Co-ordinate reference frame, Window to viewport
Transformation, Clipping and Types of Clipping
103-125
7 Representation of point, 3D Transformation and its types 126-149
8 3D Viewing, Projection and its types, Viewing Pipeline. 3D Clipping and
Viewport Clipping
150-171
9 Visible surface detection algorithms (back-face detection, z-buffer, a-buffer,
scan-line method, depths sorting method) Ray-tracing algorithm and its
surface intersection calculation and ray casting method.
172-197
10 Curved line and surfaces, BSP Trees and Octree, Spline Representation and
specifications, B-Spline curves and surfaces, Bezier curve and surfaces
198-232
11 Basic Illumination Models, Halftoning and Dithering Techniques, Polygon
Rendering Methods, Animation Techniques and Morphing, Hierarchical
modeling structures, Displaying light Intensities and continuous tone image
233-258
2
CHAPTER -1
COMPUTER GRAPHICS:
Computer graphics are graphics created using computers and more generally,
the representation and manipulation of image data by a computer with help from
specialized software and hardware.
The development of computer graphics has made computers easier to interact
with, and better for understanding and interpreting many types of data.
Developments in computer graphics have a profound impact on many types of
media and have revolutionized animation, movies and the video game industry.
APPLICATION OF COMPUTER GRAPHICS:
Computers have become a powerful tool for the rapid and economical
production of pictures. Advances in computer technology have made interactive
computer graphics a practical tool. Today, computer graphics is used in the areas
as science, engineering, medicine, business, industry, government, art,
entertainment, advertising, education and training.
I. COMPUTER AIDED DESIGN (CAD):
A major use of computer graphics is in design purposes, generally
referred to as CAD. Computer Aided Design methods are now routinely
used in the design of buildings, automobiles, aircraft, watercraft,
spacecraft, computers, text-tiles and many other products.
For some design applications, objects are first displayed in wireframe
outline from that shows the overall shapes. Software packages for CAD
3
applications typically provide the designer with the multi-window
environment.
Animations are often used in CAD applications. Realistic displays of
architectural designs permit both architect and their clients to study the
appearance of a single building or a group of buildings. With virtual
reality systems, designers can even go for a simulated “walk” through the
room or around the outsides of buildings to better appreciate to overall
effect of a particular design.
In addition to realistic exterior building displays architecture, CAD
packages also provide facilities for experimenting with 3-dimensional
interior layouts and lighting.
II. PRESENTATION GRAPHICS:
It is used to produce illustrations for reports or to generate 35 mm
slides or transparencies for use with projectors. It is commonly used in
summarize financial, statistical, mathematics, scientific and economic
data for research reports, managerial reports, consumer information,
bulletins and other types of reports. E.g.: Bar Charts, Line Graphs,
Surface Graphs and Pie Charts. Three dimensional graphs are used
simply for effect they can provide a more dramatic or more attractive
presentation of data relationships.
III. COMPUTER ART:
Computer Graphics methods are widely used in both fine art and
commercial art applications.
4
Artists use a variety of computer methods, including special purpose
hardware, artist’s paint brush programs, other paint packages, specially
developed software, symbolic mathematics packages, CAD packages,
desktop publishing software and animation packages that provide
facilities for designing object shapes and specifying object motions.
The basic idea behind a “paint brush” program is that, it allows artists
to paint pictures on the screen of video monitor. The picture is usually
painted electronically on a graphics tablet using a stylus, which can
simulate different brush strokes, brush widths and colors.
The art work of electronic art created with the aid of mathematical
relationships is designed in relation to frequency variations and other
parameters in a musical composition to produce a video that integrates
visual and aural patterns.
IV. ENTERTAINMENT:
Computer Graphics methods are now commonly used in making
motion pictures, music videos and television shows. A graphics scene
generated for the movie “Star-Trek – The wrath of Khan” is one of the
uses, in entertainment field.
Many TV series regularly employ compute graphics method. E.g.:
Deep Space Nine and Stay Tuned. Music videos use graphics and image
processing technique can be used to produce a transformation of one
person or object into another or morphing.
5
V. EDUCATION AND TRAINING:
Computer generated models of physical, financial and economic
systems are often used as educational aids, models of physical systems,
physiological systems and population trends or equipment such as the
color-coded diagram can help trainings, to understand the operation of
the system.
For some training applications, special systems are designed. E.g.:
Simulators for practice sessions for training of ship, contains pilots,
heavy equipment operators and air-traffic control personnel.
VI. VISUALIZATION:
It is an application for computer graphics. Producing graphical
representations for scientific engineering and medical data sets and
processes is generally referred to as scientific visualization and the term
business visualization is used in connection with data sets related to
commerce, industry and other non-scientific areas.
There are many different kinds of data sets and effective visualization
schemes depend on the characteristics of the data. A collection of data
can contain scalar values vectors, higher order tensors or any
combination of these data types.
Color coding is just one way to visualize the data sets. Additional
techniques include contour plots, graphs and charts, surface renderings
and visualization of volume interiors.
6
VII. IMAGE PROCESSING:
Image Processing applies techniques to modify or interact existing
pictures such as photographs and TV scans. Two principal applications of
image processing are: i) improving picture quality and ii) machine
perception of visual information.
To apply image processing methods, we first digitize a photograph or
other picture into an image file. Then digital methods can be applied to
rearrange picture parts to enhance color separations or to improve the
quality of shading.
An example of the application of image processing methods is to
enhance the quality of a picture. Image processing and computer graphics
are typically combined in many applications. The last application is
generally referred to as computer-aided surgery.
VIII. GRAPHICAL USER INTERFACE(GUI):
It is common now for software packages to provide a graphical
interface. A major component of a graphical interface is a window
manager that allows a user to display multiple-window areas. Each
window can contain a different process that can contain graphical and
non-graphical displays.
An “icon” is a graphical symbol that is designed to look like the
processing option it represents. The advantages of icons are that they take
up less screen space than corresponding textual description and they can
be understood more quickly, if well designed.
7
CHAPTER -2
VIDEO DISPLAY DEVICES:
The display devices are known as output devices. The most commonly used
output device in a graphics video monitor. The operations of most video monitors
are based on the standard cathode-ray-tube (CRT) design.
How the Interactive Graphics display works:
The modern graphics display is extremely simple in construction. It consists of
three components:
1) A digital memory or frame buffer, in which the displayed Image is stored
as a matrix of intensity values.
2) A monitor
3) A display controller, which is a simple interface that passes the contents of
the frame buffer to the monitor.
Inside the frame buffer the image is stored as a pattern of binary digital
numbers, which represent a rectangular array of picture elements, or pixel. The
pixel is the smallest addressable screen element.
In the Simplest case where we wish to store only black and white images, we
can represent black pixels by 0's in the frame buffer and white Pixels by 1's. The
display controller simply reads each successive byte of data from the frame buffer
and converts each 0 and 1 to the corresponding video signal. This signal is then fed
to the monitor. If we wish to change the displayed picture all we need to do is to
change of modify the frame buffer contents to represent the new pattern of pixels.
8
CATHODE-RAY-TUBES:
A Cathode-Ray Tube (CRT) is a video display device, whose design depends
on the operation of most video.
BASIC DESIGN OF A MAGNETIC DEFLECTION:
A beam of electronic emitted by an electron gun, passes through focusing and
deflection systems that direct the beam towards specified position on the phosphor-
coated screen. The phosphor then emits a small spot of light at each position
contacted by the electron beam. Because the light emitted by the phosphor fades
very rapidly. Some method is needed for maintaining the screen picture.
One way to keep phosphor glowing is to redraw the picture repeatedly by
quickly directing the electron beam back over the same points. This type of display
is called a “refresh rate”.
Phosphor coated screen
Deflected Electron beam
Electron beam
Connector Pins
Electron Gun (Cathode)
Base
Focusing System
Magnetic Deflection
Coils
Horizontal
Deflection Amplifier
9
OPERATION OF AN ELECTRON GUN WITH AN ACCELERATING
MODE:
The primary components of an electron gun in a CRT are the heated metal
cathode and a central grid. Heat is supplied to the cathode by directing a current
through a coil of wire called the “filament”, inside the cylindrical cathode
structure. This causes electrons to be ‘boiled off”, the hot cathode surface.
In a vacuum, inside the CRT envelope, the free negatively charged electrons are
then accelerated towards the phosphor coating by a high positive voltage. The
accelerating voltage can be generated with a positively charged metal coating on
the inside of the CRT envelope near the phosphor screen or an accelerating anode
can be used.
Intensity of the electron beam is controlled by setting voltage levels on the
control grid, which is a metal cylinder that fits over the cathode. A high negative
voltage applied to the central grid will shut off the beam by repelling electrons and
stopping them from passing through the small hole at the end of the control grid
structure. A smaller negative voltage on the control grid simply decreases the
number of electrons passing through.
The focusing system in CRT is needed to force the electron beam to coverage
into a small spot as it strikes the phosphor. Otherwise, the electrons would repel
each other and the beam would spread out as it approaches the screen.
The electron beam will be focused properly only at the center of the screen. As
the beam moves to the outer edges of the screen, displayed images become blurred.
To compensate for this, the system can adjust the focusing according to the screen
position of the beam, when the picture presentation is more than the refresh rate,
then it is called “blurred/overlapping”.
10
Cathode ray tubes are now commonly constructed with magnetic deflection
coils mounted on the outside of the CRT envelope. Two pairs of coils are used
with the coils in each pair mounted on opposite sides of the neck of the CRT
envelope.
The magnetic field produced by each pair of coils results in a traverse deflection
force that is perpendicular both to the direction of the magnetic field and to the
direction of travel of the electron beam. Horizontal deflection is accomplished with
one pair of coils and vertical deflection is accomplished with another pair of coils.
When electrostatic deflection is used 2 pairs of parallel plates is mounted
horizontally to control the vertical deflection and other is mounted vertically to
control horizontal deflection.
Different kinds of phosphors are available for use in a CRT. Besides color, a
major difference between phosphors in their “persistence”, how long they continue
to emit light after the CRT beam is removed. “Persistence” is defined as the time;
it takes the emitted light from the screen to delay to one-tenth of its original
intensity. i.e.: Persistence α 1/Refreshment
The intensity is greatest at the center of the spot and decreases with a Gaussian
distribution out to the edges of the spot. The distribution corresponds to the cross
sectional electron density distribution of CRT beam.
The maximum number of points that can be displayed without overlap on a
CRT is referred to as “resolution”. “Resolution” is the number of
points/centimeter that can be plotted horizontally and vertically. Resolution of
: Intensity distribution of an illuminated phosphor spot on a CRT screen.
11
CRT is dependent on the type of phosphor, the intensity to be displayed and the
focusing and the deflection system.
“Aspect Ratio” is the property of video monitors. This number gives the ratio
of vertical points to horizontal points necessary to produce equal length lines in
both directions on the screen. An aspect ratio of 3/4 means that a vertical line
plotted with 3 points has the same length as a horizontal line plotted with 4 points.
COLOR CRT MONITORS:
The CRT monitor displays color pictures by using a combination of phosphors
that emit different colored light. By combining the emitted light from the different
phosphor a range of colors can be generated.
The 2 basic techniques for producing color display with a CRT are the beam-
penetration method and the shadow-mask method.
I. BEAM PENETRATION METHOD:
The beam penetration method for displaying color pictures has been
used with random scan monitors. Two layers of phosphor, usually red
and green are coated onto the inside of the CRT screen and the displayed
color depends on how for the electron beam penetrates into the phosphor
layers.
A beam of slow elements excites only the outer red layer. A beam of
very fast electrons penetrates through the red layer and excites the inner
green layer. An intermediate beam speeds, combinations of red and green
lights are emitted to show two additional colors, orange and yellow. The
speed of the electrons and hence the screen color at any point is
controlled by the beam accelerating voltage.
12
II. SHADOW MASK METHOD:
It is commonly used is raster scan systems because they produced a
much wider range of colors than the beam penetration method. One
phosphor dot emits a red light, another emits a green light and the 3rd
emits a blue light. This type of CRT has 3 electron guns, one for each
color dot and a shadow mask grid just behind the phosphor coated screen.
The 3 electron beams are deflected and focused as a group onto the
shadow mask, which contains a series of holes aligned with the
phosphor-dot patterns. When the 3 beams pass through a hole in the
shadow mask they activate a dot triangle, which appears as a smaller
color spot on the screen.
“Composite Monitors” are adaptations of TV sets that allow bypass of
the broadcast cirentry. These display devices still require that the picture
information be combined, but no carrier signal is needed.
Color CRTs in graphics systems are designed RGB monitors. These
monitors use shadow mask methods and take the intensity level for each
electron gun directly from the computer system without any immediate
processing. A RGB color system with 24 bits of storage per pixel is
generally referred to as a full-color system or a true color system.
FLAT PANEL DISPLAY:
This refers to a class of video devices that have reduced volume, weight and
power requirements compared to a CRT. A significant feature of flat panel displays
is that they are thinner than CRTs.
13
Current uses for flat panel displays include small TV monitors and calculators,
pocket video games, laptop computers and as graphics display in applications
requiring rugged portable monitors. Flat panel display is of 2 types i.e.: emissive
display and non-emissive display.
Flat Panel Display commonly use threadlike liquid crystal compounds, which
tend to keep the long-axes of the rod shaped molecules aligned. A Flat Panel
Display can be constructed with a nematic liquid crystal. It has 2 glass plates, each
containing a light polarizes at right angles to the other plate, sandwich the liquid
crystal material.
Horizontal transparent conductors’ rows are built into one glass plate and
vertical conductors’ columns are put into other plate. The intersection of 2
conductors defines a pixel position.
Polarized light passing through the material is twisted, so that it will pass
through the opposite polarizer. The light is then reflected back to the viewer. The
turn off the pixel, we apply a voltage to the 2 intersecting conductors to align the
molecules, so that the light is not twisted. These types of flat panel device are
called as “Passive Matrix LCD”.
Another method for constructing LCDs is to place a transistor at each pixel
location, using thin film transistor at each pixel location, using thin film transistor
technology. The transistors are used to control the voltage at pixel locations and to
prevent charge from gradually leaking out of the liquid-crystal cells. These devices
are called active matrix displays.
14
I. EMMISIVE DISPLAY:
The Emissive Displays (Emitters) are the devices that convert
electrical energy into light. E.g.: Plasma Panels, Thin Film
Electroluminescent Displays and Light Emitting Diodes are example of
emissive displays.
a. PLASMA PANEL:
The plasma panel also called gas-discharge displays are
constructed by filling the region between two glass plates with a
mixture of gases that usually includes Neon.
A series of vertical conducting ribbons is placed on one glass panel
and a set of horizontal ribbons is built into the other glass panel.
Firing voltages applied to a pair of horizontal and vertical conductors
causes the gat at the intersection of the two conductors to breakdown
into glowing plasma of electron and ions.
One disadvantage of plasma panels has been that they were strictly
monochromatic devices, but systems have been developed that are
now capable of displaying color and gray scale.
b. THIN-FILM ELECTROLUMINISCENT DISPLAYS:
Thin-Film Electroluminescent displays are similar in construction
to plasma panel. The difference is that the region between the glass
plates is filled with a phosphor, such as zinc sulphide dopped with
manganese, instead of a gas.
15
When a high voltage is applied to a pair of crossing electrodes, the
phosphor becomes a conductor in the area of the intersection of two
electrodes; the phosphor becomes a conductor in the area of the
intersection of two electrodes. Electrical energy is then absorbed by
manganese, which release the energy as a spot of light similar to the
glowing plasma effect in a plasma panel.
Electroluminescent displays require more power than plasma
panels and good color and gray scale displays are hard to achieve.
c. LIGHT-EMITTING DIODE(LED):
In Light Emitting Diode (LED), a matrix of diodes are arranged to
form the pixel positions in the display and picture definition is stored
in a refresh buffer.
II. NON-EMISSIVE DISPLAY:
The Non-Emissive Displays (Non-Emitters) use optical effects to
convert sunlight or light from some other source into graphics patterns.
E.g.: Liquid Crystal Display.
The Non-Emissive devices produce by passing polarized light from
the surroundings or from an internal light source through a liquid crystal
material that can be aligned to either block or transmit the light. Liquid
crystal refers to the fact that these compounds have a crystalline
arrangement of molecules.
a. LIQUID CRYSTAL DISPLAY (LCD):
Liquid Crystal Displays (LCDs) are commonly used in small
systems such as calculators, laptops and computers.
16
RASTER-SCAN SYSTEM:
Raster-Scan Systems typically employ several processing units. In addition to
the central processing unit or CPU, a special purpose, processor called the “video
controller” or “display controller”, is used to control the operation of the display
device. Here, the frame buffer can be anywhere in the system memory and the
video controller, more sophisticated raster systems employ other processors as co-
processors and accelerators to implement various graphics.
VIDEO CONTROLLER:
A fixed area of the system memory is reserved for the frame buffer and the
video controller is given direct access to the frame buffer memory.
Frame buffer locations and the corresponding screen positions are referenced in
Cartesian coordinate origin is defined at the lower left screen corner. The screen
surface is then represented as the first quadrant of 2D system, with positive ‘x’
values increasing to the right and positive ‘y’ values increasing from bottom to top.
CPU SYSTEM MEMORY VIDEO CONTROLLER
SYSTEM BUS
I/O DEVICES
MONITOR
CPU SYSTEM
MEMORY
VIDEO
CONTROLLER
SYSTEM BUS
I/O DEVICES
MONITORFRAME
BUFFER
17
Here, 2 registers are used to store the co-ordinates of the screen pixels. Initially
the x-register is set too and y-register is set to ‘ymax’. The value stored in the frame
buffer for this pixel position is then retrieved and used to set the intensity of CRT
beam. The x-register is incremented by 1 and the process repeated for the next
pixel on the top scan line.
This procedure is repeated for each pixel along the scan line. After the last pixel
on the top scan line has been processed, the x-register is rest to 0 and y-register
decremented by 1. This procedure is repeated for each successive scan line. After
cycling through all pixels along the bottom scan line y = 0, the video controller
resets the registers to the 1st
pixel position on the top scan line and the refresh
process start over.
When the frame/pixel presentation is less than the refresh rate, then it is called
flickering. Flickering is a problem occurred in raster-scan system and it is solved
by interlacing technique.
RASTER-SCAN DISPLAY:
It is based on TV technology. Here electron beam is swept across the screen, on
row at a time from top to bottom. The picture definition is stored in a memory area
called refresh buffer/frame buffer. Here each screen point is referred as a pixel or
pel (picture element).
The capacity of raster-scan system is to store intensity information for each
screen point for realistic display of scenes containing shading and color patterns. In
black and white system, a bit value of ‘1’ represents the electron beam intensity is
turned on and a value of ‘0’ indicates the beam intensity is to be off.
18
In black and white system, a bit value of ‘1’ indicates the electron beam
intensity is turned on and a value of ‘0’ indicates the beam intensity is to be off. A
system with 24 bits/pixel requires 2 megabytes of storage for the frame buffer. On
black and white system with one bit/pixel, the frame buffer is called bitmap. For
multiple bits/pixel, the frame buffer is called pixmap.
Raster-Scan display is carried out at the rate of 60 to 80 frames/second. It has
units of cycle/sec or hertz. It contains a separate display processor called “graphics
controller” or “display co-processor” to free the CPU. A major task of display
processor is digitizing a picture definition given in an application program into a
set of pixel intensity values for storage in the frame buffer. This is called “Scan
Conversion”.
RANDOM-SCAN DISPLAY:
In this system, an application program is input and stored in the system memory
along with a graphics package. The display file is accessed by the display
processor to refresh the screen. The display processor is called as display-
processing unit or graphics controller.
DISPLAY PROCESSOR
MEMORY
VIDEO
CONTROLLER
I/O DEVICES
MONITOR
FRAME
BUFFER
CPU DISPLAY
PROCESSOR
SYSTEM
MEMORY
[RASTER-SCAN SYSTEM WITH A DISPLAY PROCESSOR]
19
RANDOM-SCAN SYSTEMS:
When a random-scan display unit is operated a CRT has the electron beam
directed only to the parts of the screen, where a picture is to be drawn. Random-
scan monitors draw a picture one line at a time and for this reason is also refreshed
to as vector displays or stroke-writing or calligraphic display.
Refresh rate on a random-scan system depends on the number of lines to be
displayed. Picture definition is now stored as a set of line drawing commands in an
area of memory referred to as the refresh display file or display list or display
program or refresh buffer. Random-scan systems are designed for line drawing
applications and can’t display realistic shaded scenes.
INPUT DEVICES:
The various input devices are: Keyboard, Mouse, Trackball and Space-ball,
Joysticks, Data glove, Digitizers, Image Scanner, Light Pens, Touch Panels and
Voice System.
I. KEYBOARD:
It is used primarily as a device for entering that strings. It is an efficient
device for inputting non-graphics data as picture labels associated with a
graphics display. It provided with features to facilitate entry of screen co-
ordinates, menu selections or graphics functions.
CPU SYSTEM MEMORY DISPLAY PROCESSOR
SYSTEM BUS
I/O DEVICES
MONITOR
20
Cursor-control keys and function keys are common feature on general
purpose keyboards. Function keys allows users to entry frequently used
operations in a single keystroke and a cursor control keys can be used to
select displayed objects or co-ordinate positions by positioning the screen
cursor.
II. MOUSE:
A mouse is a small hand-held box used to position the screen cursor.
Wheels or rollers on the bottom of the mouse can be used to record the
amount of direction of movement.
III. TRACKBALL AND SPACEBALL:
A track-ball is a ball that can be rotated with fingers or palm of the hand
produce screen-cursor movement. It is a 2-dimensional positioning device. A
space-ball provides 6 degrees of freedom. It does not actually move. It is
used for 3-dimensional positioning.
IV. JOYSTICKS:
It consists of a small, vertical layer mounted on a base that is used to
steer the screen cursor around. Most joysticks select screen positions with
actual stick movement, other respond to pressure on the stick. In movable
joystick, the stick is used to activate switches that cause the screen cursor to
move at a constant rate in the direction selected.
V. DATA GLOVE:
A data glove can be used to grasp a ‘virtual object’. It is constructed with
a series of sensors that detect hand and finger motion.
21
VI. DIGITIZERS:
It is a common device used for drawing, painting or interactively
selecting co-ordinate positions on an object. These devices can be used to
input co-ordinate values in either a 2D or 3D space. It is used to scan over a
drawing or object and to input a set of discrete coordinate positions, which
can be joined with straight line segments to approximate the cure or surface
shapes.
One type of digitizers is the “Graphics Tablet”, which is used to input 2D
co-ordinates by activating a hand cursor or stylus at selected positions on a
flat structure. A hand cursor contains cross hairs for sighting positions, while
a stylus is a pencil shaped device that is pointed at positions on the tablet.
VII. IMAGE SCANNER:
Drawings, graphs, color and black and white photos or text can be stored
for computer processing with an image scanner by passing an optical
scanning mechanism over the information to be stored.
VIII. LIGHT PENS:
This is a pencil shaped device are used to select screen position by
detecting the light coming from points on the CRT screen. An activated light
pen, pointed at a spot on the screen as the electron beam lights up that spot
generates an electrical plate that causes the co-ordinates position of the
electron beam to be recorded.
22
IX. TOUCH PANELS:
It allows displayed objects or screen positions to be selected with the
touch of a finger. A typical application of touch panels is for the selection of
processing options that are represented with graphical icons.
Optical touch panels employ a line of infrared light emitting diodes
(LEDs) along one vertical edge and along one horizontal edge contain light-
detectors. These detectors are used to record which beams are interrupted
when the panel is touched.
An electrical touch panel is constructed with 2 transparent plates
separated by a small distance. One plate is coated with conducting material
and other with a resistance material.
X. VOICE SYSTEM:
It can be used to initiate graphics operations or to enter data. These
systems operate by matching an input against a predefined dictionary of
words and phrases.
HARD COPY OUTPUT DEVICES:
Hard-Copy output devices gives images in several format. For presentations or
archiving, we can send files to devices or service bureaus that will produce 35mm
slides or overhead transparencies. The quality of pictures obtained from a device
depends on dot size and the number of dots per inch or lines per inch that can be
displayed.
Printer produces output by either impact or non-impact methods. Impact
printers press format character faces against an inked ribbon onto the paper. A line
23
printer is an example of impact device. Non-impact printers and plotters use laser
techniques methods and electro-thermal methods to get images into paper.
Character impact printers have a dot matrix print head containing a rectangular
array of protruding wire pins with the number of pins depending on the quality of
the printer.
In a laser device, a laser beam creates a charge distribution on a rotating drum
coated with a photoelectric material, such as selenium. Toner is applied to the
drum and then transferred to paper. Ink-jet methods produce output by squirting
ink in horizontal rows across a roll of paper wrapped on a drum. The electrically
charged ink stream is deflected by an electric field to produce dot-matrix patterns.
An electrostatic device places a negative charge on the paper, one complete row
at a time along the length of the paper. Then the paper is exposed to a toner. The
toner is positively charged and so is to the negatively charged areas, where it
adheres to produce the specified output. Electro-thermal methods use heat in a dot-
matrix print head to output patterns on heat-sensitive paper.
GRAPHICS SOFTWARE:
Graphics Software is of 2 types. That is:
i) General Programming Packages
ii) Special Purpose Application Packages.
A general programming package provides an extensive set of graphics
functions that can be used in a high level programming language. Application
graphics packages are designed for non-programmers. So, that user can generate
displays without worrying about how graphics operations.
24
CO-ORDINATE REPRESENTATIONS:
With few exceptions, general graphics packages are designed to be used with
Cartesian co-ordinate specifications. If co-ordinates values for a picture are
specified in some other references frame, they must be converted to Cartesian co-
ordinates before they can be input to the graphics package.
Special purpose packages may allow using of other co-ordinate frames that are
appropriate to the application. We can construct the shape of individual objects, in
a scene within separate co-ordinate reference frames, called “modeling co-
ordinates” or “local co-ordinates” or “master co-ordinates”.
Only individual object shapes have been specified, we can place the objects into
appropriate positions within the scene using a reference frame called world co-
ordinates. The world co-ordinates description of the scene is transferred to one or
more output device reference frames for display. The display co-ordinate systems
are referred to as device co-ordinates/screen co-ordinates in the case of video
monitors.
Generally, a graphics system first converts world co-ordinates to specific device
co-ordinate to specific device co-ordinates. An initial modeling co-ordinate
position (xmc, ymc) is transferred to advice co-ordinate position (xdc, ydc) with the
sequence (xmc, ymc) → (xwc, ywc) → (xnc, ync) → (xdc, ydc). The normalized co-
ordinates satisfy the inequalities 0 ≤ xnc ≤ 1, 0 ≤ ync ≤ 1 and the device co-ordinates
‘xdc’ and ‘ydc’ are integers within the range (0,0) to (xmax, ymax) for particular
device.
25
GRAPHICS FUNCTIONS:
A general purpose graphics package provides users with a variety of functions
for creating and manipulating pictures. The basic building blocks for pictures are
referred to as output primitives. They include character strings and geometric
entities such as points, straight lines, curved lines, filled areas and shapes defined
with arrays of color points.
Attributes are the properties of the output primitives that is an attribute describe
how a particular primitive is to be displayed. We can change the size, position or
orientation of an object within a scene using geometric transformations similar
modeling transformations are used to construct a scene using object description
given in modeling co-ordinates.
Viewing transformations are used to specify the view that is to be presented and
the portion of the output display area that is to be used. Pictures can be subdivided
into component parts called structures/segments/objects, depending on the software
package in use.
Interactive graphics applications use various kinds of input devices, such as a
mouse, a tablet or a joystick. Input functions are used to control and process the
data flow from those interactive devices. A graphics package contains a number of
housekeeping tasks, such as clearing a display screen and initializing parameters.
The functions for carrying out these chores under the heading control operations.
SOFTWARE STANDARDS:
The primary goal of standardized graphics software is probability. When
packages are designed with standard graphics functions, software can be moved
26
easily from one hardware system to another and used in different implementations
and applications.
International and National standards planning organization have co-operated in
an effort to develop a generally accepted standard for computer graphics. After
considerable effort, this work on standards led to the development of the Graphical
Kernel System (GKS). This system was adopted as the first graphics software
standard by International Standard Organization (ISO), and by others.
The 2nd
software standard to be developed and approved by the standards
organizations was Programmer’s Hierarchical Interactive Graphics Standard
(PHIGS), which is an extension of GKS.
Standard Graphics functions are defined as a set of specifications that is
independent of any programming language. A language binding is then defined for
a particular high level programming language. Standardization for device interface
methods is given in Computer Graphics Interface (CGI) system and the Computer
Graphics Metafile (CGM) system specifies standards for archiving and
transporting pictures.
PHIGS WORKSTATION:
The workstation is a computer system with a combination of input and output
device that defined for a single user. In PHIGS and GKS, the term workstation is
used to identify various combinations of graphics hardware and software.
A PHIGS workstation can be a single output device, single input device, a
combination of input and output devices, a file or even a window displayed on a
video monitor. To define and use various “workstations” within an application
program, we need to specify a workstation identifier and the workstation type.
27
COMPONENTS OF GUI:
A GUI uses a combination of technologies and devices to provide a platform
the user can interact with for the tasks of gathering and producing information.
A series of elements confirming a visual language have evolved to represent
information stored in computers. This makes it easier for people with little
computer skill to work with and use computer software.
The most common combination of such elements in GUIs is the WIMP
paradigm, especially in personal computers.
A window manager facilitates the interactions between windows, applications
and the windowing system. The windowing system handles hardware devices, such
as pointing devices and graphics hardware as well as the positioning of the cursor.
In personal computers all these elements are modeled through a desktop
metaphor, to produce a simulation called a desktop environment in which the
display represents a desktop, upon which documents and folders of documents can
be placed.
USER INTERFACE AND INTERACTION DESIGN:
Designing the visual composition and temporal behavior of GUI is an important
part of software application programming. Its goal is to enhance the efficiency and
ease of use for the underlying logical design of a stored program, a design
discipline known as usability. Techniques of user-centered design are used to
ensure that the visual language introduced in the design is well tailored to the tasks
it must perform.
28
The widgets of a well-designed interface are selected to support the actions
necessary to achieve the goals of the user. A model-view controller allows for a
flexible structure in which the interface is independent from and indirectly linked
to application functionality, so the GUI can be easily customized. This allows the
user to select or design a different skin at will and eases the designer’s work to
change the interface as the user needs evolve.
The visible graphical interface features of an application are sometimes referred
to as “chrome”. Larger widgets such as windows usually provide a frame or
container for the main presentation content, such as a web page, email message or
drawing.
A GUI may be designed for the rigorous requirements of a vertical market. This
is known as “Application Specific Graphical User Interface”. Examples of an
application specific GUI are:
i) Touch screen point of sale software used by wait staff in a busy restaurant.
ii) Self-service checkouts used in a retail store.
iii)Automated Teller Machines (ATM)
iv) Information kiosks in a public space, like a train station or a museum.
v) Monitors or control screens in an embedded industrial application which
employ a real-time operating system (RTOS).
COMMAND LINE INTERFACES:
GUIs were introduced in reaction to the steep learning curve of command line
interfaces (CLI), which require commands to be typed on the keyboard. Since the
commands available in command line interfaces can be numerous, complicated
operations can be completed using a short sequence of words and symbols. This
allows for greater efficiency and productivity once many commands are learnt but
29
reaching this level takes some time because the command words are not easily
discoverable and not mnemonic.
Command line interfaces use modes only in limited forms, such as the current
directory and environment variables. Most modern operating systems provide both
a GUI and some level of a CLI, although the GUIs usually receive more attention.
THREE-DIMENSIONAL USER INTERFACES:
Three-dimensional images are projected on them in two dimensions. Since this
technique has been in use for many years, the recent use of the term three-
dimensional must be considered a declaration by equipment marketers that the
speed of three dimensions to two dimension projection is adequate to use in
standard GUIs.
30
CHAPTER – 3
LINE DRAWING ALGORITHMS:
1. SIMPLE LINE DRAWING ALGORITHM:
The Cartesian slope intercept equation for a straight line is:
y = mx + b => b = y – mx,
Where m = slope of line, b = y-intercept form.
If 2 end points of a line segment is specified at position (x1, y1) and (x2,
y2). So the values for the slope ‘m’ and y-intercept form ‘b’ is:
m = ∆y/∆x = (y2 – y)/(x2 – x1)
=> ∆y = m∆x ------- (1) and
∆x = ∆y/m ------ (2)
b = y1 –mx1
Here, ‘∆y’ is the y-interval computed for the given x-interval ∆x along a
line is ∆y = m∆x. Similarly the x-interval ∆x corresponding to a specified
∆y as: ∆x = ∆y/m.
For lines with slope magnitude, |m| < 1, ‘∆x’ increases. So calculate ‘∆y’
as: ∆y = m∆x. For |m| > 1, ‘∆y’ increases. So calculate ‘∆x’ as: ∆x = ∆y/m.
For |m| = 1, ∆x and ∆y both incremented and have the same value for
horizontal and vertical segments.
x1 x2
∆x
y1
y2
∆y
31
Example: Draw a line for points (3, 2) to (7, 8).
Here, (x1, y1) = (3, 2) and (x2, y2) = (7, 8).
So m = y2 –y1/x2 – x1 = 8 – 2/7 – 3 = 6/4 = 3/2 > 1. That is, for m > 1, ∆y
increases and ∆x = ∆y/m.
∆x ∆y x = x1 + ∆x y = y1 + ∆y
2/3 1 11/3 3
4/3 2 13/3 4
2 3 5 5
8/3 4 17/3 6
10/3 5 19/3 7
4 6 7 (x2) 8 (y2)
2. DIGITAL DIFFERENTIAL ANALYSER ALGORITHM (DDA):
This is a scan conversion line algorithm based on calculating either ∆y or
∆x as: ∆y = m∆x and ∆x = ∆y/m. We sample the line at unit intervals in one
co-ordinate and determine corresponding integer values nearest the line path
for the other co-ordinate.
Consider first a line with positive slope. If m ≤ 1, we sample at unit x-
intervals (∆x = 1) and calculate successive ‘y’ values as: yk+1 = yk + m. (∆x
increases by 1 always, so ∆x = 1).
Where, k = subscript and integer values starting from 1,
for 1st
point and increase by 1 until the final end point is
reached. Since ‘m’ can be any real number between 0 and
x1 x2
y1
y2
32
1, the calculated ‘y’ values must be rounded to the
nearest integer.
If m > 1, we sample at unit y-intervals (∆y = 1) and calculate each
succeeding ‘x’ values as: xk+1 = xk + 1/m. (∆y increases by 1 always, so ∆y =
1). Here, the lines are processes from left end point to right end point.
If the lines processed from right end to left end point, then ∆x = -1 and
yk+1 = yk – m (for, m ≤ 1), when ∆y = -1 and m > 1, then xk+1 = xk - 1/m.
Example: Draw a line for points (3, 2) to (7, 8).
Here, xk = 3, yk = 2 and m = y2 –y1/x2 – x1 = 8 – 2/7 – 3 = 6/4 = 3/2 > 1.
So, m > 1, so yk increases by 1 always.
xk+1 = xk + 1/m yk+1 = yk + m
11/3 3
13/3 4
15/3 = 5 5
17/3 6
19/3 7
7 (x2) 8 (y2)
3. BRESENHAM’S LINE DRAWING ALGORITHM:
An accurate and efficient raster line generating algorithm is developed by
Bresenham. In this approach, at slope m < 1, pixel positions along a line
path are then determined by sampling at unit x-intervals. Starting from left
end point (x0, y0) of a given line, we step to each successive column (x –
33
position) and plot the pixel, whose scan-line ‘y’-value is closest to the line
‘p’.
For kth
step, we determine the pixel at (xk, yk)
is to be displayed we need to decide which
pixel to plot in column, xk+1 and the choice of
pixel position are: (xk+1, yk) and (xk+1, yk+1). At
xk+1, we label vertical pixel separations from
the mathematical line path as ‘d1’ and ‘d2’.
So at xk+1, the ‘y’ co-ordinate is:
y = m(xk + 1) + b ------- (1)
d1 = y – yk = m(xk +1) + b – yk
d2 = (yk + 1) – y = yk + 1 – m(xk + 1) – b
The difference between these 2 separations is:
d1 – d2 = m(xk + 1) + b – yk – (yk +1) + m(xk + 1) + b
= 2m(xk + 1) + 2b - yk – (yk +1) = 2m(xk + 1) + 2b - yk – yk – 1
=> d1 – d2 = 2m(xk + 1) + 2b - 2yk – 1 ------- (2)
The decision parameter ‘Pk’ for kth
step in the line algorithm is calculated
with substitution of m = ∆y/∆x.
So, Pk = ∆x(d1 – d2)
= ∆x(2m(xk + 1) + 2b - 2yk – 1)
yk+3
yk+2
yk+1
yk
xk xk+1 xk+2 xk+3
y = mx + b
34
= ∆x(2∆y/∆x (xk + 1) + 2b - 2yk – 1)
= 2∆y(xk + 1) + 2b∆x - 2yk ∆x - ∆x
= 2∆yxk + 2∆y + 2b∆x - 2yk ∆x - ∆x
= 2∆yxk - 2∆xyk + 2∆y + 2b∆x - ∆x
= 2∆yxk - 2∆xyk + 2∆y + ∆x(2b -1)
= 2∆yxk - 2∆xyk + C
=> Pk = 2∆yxk - 2∆xyk + C ------- (3)
The sign of ‘Pk’ is same as the sign of d1 – d2, since ∆x > 0, C = constant
and value of C = 2∆y + ∆x(2b -1), independent of pixel position. If the pixel
at ‘yk’ is closer to the line path than the pixel at yk+1 (i.e. d1 < d2), then the
decision parameter ‘Pk’ is negative.
At step k + 1, the decision parameter is evaluated as:
Pk+1 = 2∆y(xk +1) - 2∆x(yk +1) + C ------- (4)
Now, subtract equation – (3) from equation – (4), we get:
Pk+1 – Pk = 2∆y(xk+1 – xk) - 2∆x(yk+1 – yk), but xk+1 = xk + 1, so that
Pk+1 = Pk + 2∆y(xk+1 – xk) - 2∆x(yk+1 – yk)
=> Pk+1 = Pk + 2∆y - 2∆x(yk+1 – yk) ------- (5)
Where, yk+1 – yk is either 0 or 1, depending on the sign of parameter Pk.
35
The recursive calculation of decision parameters is performed at each
integer x-position, starting at the left co-ordinate end point of the line. The
1st
parameter ‘P0’ is evaluated from equation – (3), at the starting pixel
position (x0, y0) and with ‘m’ evaluated as ∆y/∆x. So, P0 = 2∆y - ∆x --- (6).
ALGORITHM:
STEP 1: Input the two line end points and store the left end point in
(x0, y0)
STEP 2: Load the (x0, y0) or the initial point of the line into the frame
buffer then plot the first point.
STEP 3: Calculate the constant ∆x, ∆y, 2∆y, 2∆y - 2∆x and obtain the
starting value for the decision parameter: P0 = 2∆y - ∆x
STEP 4: At each ‘xk’ along the starting at k = 0, perform the
following point.
If Pk < 0, plot (xk + 1, yk) and Pk+1 = Pk + 2∆y
If Pk > 0, plot (xk + 1, yk + 1) and Pk+1 = Pk + 2∆y - 2∆x.
STEP 5: Repeat STEP – 4, ∆x times.
Example: To illustrate the algorithm, we digitize the line with end points
(20, 10) and 30, 18)
Here the line has a slope:
m = y2 –y1/x2 – x1 = 18 – 10/30 – 20 = 8/10 = 0.8 < 1
36
∆x = 30 – 20 = 10 and ∆y = 18 – 10 = 8.
The initial decision parameter is: P0 = 2∆y - ∆x = 2 x 8 – 10 = 16 – 10 = 6
and the increments for the calculating successive decision parameters are:
∆x = 10, ∆y = 8, 2∆y = 16, 2∆y - 2∆x = 16 – 20 = - 4. At k = 0, we plot the
initial point (xk, yk) = (x0, y0) = (20, 10) and determine successive pixel
positions along the line path from the decision parameter as:
k Pk (xk +1, yk +1) Decision parameter calculation
0 6 (21, 11) P0 = 2∆y - ∆x = 2 x 8 – 10 = 16 – 10 = 6
1 2 (22, 12) Pk+1 = Pk + 2∆y - 2∆x = 6 + 2 x 8 – 2 x 10 = 2
2 -2 (23, 12) Pk+1 = Pk + 2∆y - 2∆x = 2 + 2 x 8 – 2 x 10 = -2
3 14 (24, 13) Pk+1 = Pk + 2∆y = -2 + 2 x 8 = 14
4 10 (25, 14) Pk+1 = Pk + 2∆y - 2∆x = 14 + 2 x 8 – 2 x 10 = 10
5 6 (26, 15) Pk+1 = Pk + 2∆y - 2∆x = 10 + 2 x 8 – 2 x 10 = 6
6 2 (27, 16) Pk+1 = Pk + 2∆y - 2∆x = 6 + 2 x 8 – 2 x 10 = 2
7 -2 (28, 16) Pk+1 = Pk + 2∆y - 2∆x = 2 + 2 x 8 – 2 x 10 = -2
8 14 (29, 17) Pk+1 = Pk + 2∆y = -2 + 2 x 8 = 14
9 10 (30, 18) Pk+1 = Pk + 2∆y - 2∆x = 14 + 2 x 8 – 2 x 10 = 10
It will continue upto 10 times, starting from 0 to 9, because ∆x = 10.
CIRCLE GENERATING ALGORITHMS:
1. PROPERTIES OF THE CIRCLE:
A Circle is defined as the set of points that are all at given distance ‘r’
from a center position (xc, yc). This distance relationship is expressed by the
Cartesian co-ordinates as:
37
(x – xc)2
+ (y – yc)2
= r2
------ (1)
The general equation of a circle is:
x2
+ y2
= r2
------- (2)
To calculate the position of points on a circle circumference by stepping
along the x-axis in unit steps from xc – r to xc + r and calculating the
corresponding ‘y’ – values at each position as:
------ (3)
To calculate the points along the circular boundary, polar co-ordinates ‘r’
and ‘θ’ are used. Expressing the circle equation in parametric polar form
yields the pair of equations is:
x = xc + rcosθ and y = yc +rsinθ
Computation can be reduced by considering the symmetry of circles. The
shape of the circle is similar in each quadrant. We can generate the circle
section in the second quadrant of the xy-plane by noting that the two circle
sections are symmetric with respect to the y-axis and the circle sections in
3rd
and 4th
quadrants can be obtained from sections in the first and second
quadrants by considering symmetry about the x-axis.
Circle sections in adjacent octants within one quadrant are symmetric
with respect to the 45 degree line dividing the two octants. These symmetry
conditions are illustrated in given figure, where a point at position (x, y) on a
one eight circle sector is mapped onto the seven circle points in the other
r
xc
yc
38
octants of the xy-plane. Taking the advantage of the circle symmetry, we can
generate all pixel positions around a circle by calculating only the points
within the sector from x = 0 to x = y.
2. MID-POINT CIRCLE/BRESENHAM’S CIRCLE GENERATING
ALGORITHM:
We set up the algorithm to calculate pixel positions around a circle path
centered at the co-ordinate origin (0, 0). Then each calculated position (x, y)
is moved to its proper screen position by adding ‘xc’ to ‘x’ and ‘yc’ to ‘y’,
where (xc, yc) is the center position of the circle with radius ‘r’.
Along the circle section from x = 0 to x = y in 1st
quadrant, the slope of
the curve varies from 0 to 1. To apply the midpoint method, we define the
circle function with (0, 0) as its center is:
Fcircle(x, y) = x2
+ y2
– r2
--- (1)
It has 3 properties, at any point (x, y). That is:
(x, y)
(y, x)
(-x, y)
(-y, x)
(y, -x)
(x, -y)
(-x, -y)
(-y, -x)
45o
Fcircle(x, y) = < 0, if (x, y) is inside the circle boundary
= 0, if (x, y) is on the circle boundary --- (2)
> 0, if (x, y) is outside the circle boundary
39
We have plotted the pixel at (xk, yk) and next to determine whether the
pixel at position (xk+1, yk) or one at position (x k+1, yk – 1) is closer to the
circle. The decision parameter is the circle function and equation – (1) is
evaluated at the midpoint between these 2 pixels (x k+1, yk) and (x k+1, y k – 1).
So, the decision parameter is:
Pk = Fcircle(xk+1, yk -1/2) = (xk+1)2
+ (yk -1/2)2
– r2
--- (3)
[Since midpoint = (yk + yk-1)/2 = (2yk -1)/2 = yk – 1/2]
If Pk < 0, the midpoint is inside the circle and the pixel on scan line ‘yk’ is
closer to the circle boundary, otherwise the midpoint is outside or on the
circle boundary and we select the pixel on ‘yk - 1’.
The recursive expression for the next decision parameter is obtain by
evaluating the circle function at sampling position xk+1 + 1 = xk + 2, then,
Pk+1 = Fcircle(xk+1 + 1, yk +1 -1/2) = [(xk+1) + 1]2
+ (yk+1 – 1/2)2
– r2
=> Pk+1 – Pk = 2(xk + 1) + (yk+1
2
– yk
2
) – (yk+1 – yk) + 1
=> Pk+1 = Pk + 2(xk + 1) + (yk+1
2
– yk
2
) – (yk+1 – yk) + 1 --- (4),
where yk+1 is either ‘yk’ or ‘yk-1’, depending on the sign of Pk.
Increments for obtaining Pk+1 are either 2xk+1 + 1 (if Pk is negative) or
2xk+1 + 1 – 2yk+1. Evaluation of terms 2xk+1 and 2yk+1 can also be done
incrementally as: 2xk+1 = 2xk + 2, 2yk+1 = 2yk - 2. At the start position (0, r),
the initial decision parameter is obtained by evaluating the circle function at
the start position (x0, y0) = (0, r). So,
40
P0 = Fcircle(1, r – 1/2) = 1 + (r – 1/2)2
– r2
= 1 + r2
+ 1/4 – 2 x r x 1/2 – r2
= 5/4 – r --- (5)
If the radius ‘r’ is specified as an integer, we can simply round the ‘P0’ to
P0 = 1 – r (for ‘r’ is an integer).
ALGORITHM:
STEP 1: Input radius ‘r’ and circle center (xc, yc) and obtain the first point
on the circumference of a circle centered on the origin as: (x0, y0) = (0, r).
STEP 2: Calculate the initial value of decision parameter as P0 = 5/4 – r.
STEP 3: At each ‘xk’ position, starting at k = 0, perform the following test:
i) If Pk < 0, the next point along the circle centered on (0, 0) is
(xk+1, yk) and Pk+1 = Pk + 2xk+1 + 1, otherwise,
ii) The next point along the circle is, (xk+1, yk-1) and
Pk+1 = Pk + 2xk+1 + 1 – 2yk+1, 
Where 2xk+1 = 2xk + 2 and 2yk+1 = 2yk – 2, we will continue this
upto xk ≤ yk
STEP 4: Determine symmetry points in other screen octants.
STEP 5: Move each calculated pixel position (x, y) onto the circular path
centered on (xc, yc) and plot the co-ordinate values x = x + xc and y = y + yc.
STEP 6: Repeat STEP – 3 through S, until x ≥ y.
41
Example: Given a circle radius r = 10, we demonstrate the midpoint circle
algorithm by determining positions along the circle algorithm by
determining positions along circle octant in the first quadrant from x = 0 to x
= y.
The initial value of decision parameter is P0 = 1 –r = - 9. For the circle
centered on the co-ordinates origin, the initial point is (x0, y0) = (0, 10) and
initial increment terms are: 2x0 =0, 2y0 = 20.
Successive decision parameter values and positions along the circle path
are calculated using the midpoint method as:
k Pk (xk+1, yk -1) 2xk+1 2yk+1
0 - 9 (1, 10) 2 20
1 - 6 (2, 10) 4 20
2 - 1 (3, 10) 6 20
3 6 (4, 9) 8 18
4 - 3 (5, 9) 10 18
5 8 (6, 8) 12 18
6 5 (7, 7) 14 16
ELLIPSE GENERATING ALGORITHM:
1. PROPERTIES OF THE ELLIPSE:
An ellipse is the set of points, such that the sum of the distances from two
fixed position is the same for all positions (Foci) is the same for all points.
If the distances to the two foci from any point P = (x, y) on the ellipse
are labeled ‘d1’ and ‘d2’, then the general equation of ellipse stated as:
42
d1 + d2 = Constant --- (1)
Expressing distance ‘d1’ and ‘d2’ in terms of
the focal co-ordinates F1 = (x1, y1) and F2 =
(x2, y2), we have:
By squaring this equation, isolating the remaining radica and then
squaring again, we write the general ellipse equation in the form:
Ax2
+ By2
+ Cxy +Dx + Ey + F = 0 --- (3)
Here the coefficients A, B, C, D, E and F are evaluated in terms of the
focal co-ordinates and dimensions of the major and minor axes of the ellipse.
An ellipse in standard position with major and minor axes oriented
parallel to ‘x’ and ‘y’ axes.
Parameter ‘rx’ is the semi-major axis and
parameter ‘ry’ is the semi-minor axis. The
equation of the ellipse can be written in
terms of the ellipse center co-ordinates and
parameters ‘rx’ and ‘ry’ as:
(x – xc/rx)2
+ (y – yc/ry) 2
= 1 --- (4)
Using polar co-ordinates ‘r’ and ‘θ’, the parametric equations of the
ellipse is:
(x – x1)2
+ (y – y1)2
+ (x – x2)2
+ (y – y2)2
= Constant --- (2)
d1
d2
F1
F2
P = (x, y)
ry
rx
yc
xc
y
x
43
x = xc +rxcosθ and y = yc + rysinθ --- (5)
Symmetric consideration can be used to further reduce computation.
2. MID-POINT ELLIPSE/BRESENHAM’S ELLIPSE GENERATING
ALGORITHM:
This is applied throughout the 1st
quadrant in 2 parts. The division of 1st
quadrant is according to the slope of an ellipse with rx < ry. When we process
this quadrant by taking unit steps in the x-direction, where slope of the curve
has a magnitude less than 1 and taking unit steps in y-direction, when slope
has the magnitude greater than 1.
For a sequential implementation of the
midpoint algorithm, we take the start
position at (0, ry) in clockwise order
throughout the 1st
quadrant. The ellipse
function from equation (4) with (xc, yc) = (0,
0) as:
Fellipse(x, y) = ry
2
x2
+ rx
2
y2
– rx
2
ry
2
--- (6)
-x, y
x, -y
ry
rx
x, y
y
x
-x, -y
Region 2
Region 1
ry
rx
Slope m = -1
y
x
44
It has 3 properties, at any point (x, y). That is:
Thus the ellipse function Fellipse(x, y) serves as the decision parameter in
midpoint algorithm.
Starting at (0, ry), we take unit steps in the x-direction until we reach the
boundary between region 1 and region 2. The slope is calculated from
equation – (6) is:
m = dy/dx = -2ry
2
x/2rx
2
y --- (8)
At the boundary between region 1 and region 2, dy/dx = -1 and 2ry
2
x =
2rx
2
y. So we move to region 1, when 2ry
2
x ≥ 2rx
2
y.
In region 1, the midpoint between the two candidate pixels at sampling
position xk + 1 in the 1st
region. Assuming position (xk, yk) has been selected
at the previous step. We determine the next position along the ellipse path by
evaluating the decision parameter at this midpoint is:
Pk
1
= Fellipse(xk+1, y k -1/2) = ry
2
(xk+1)2
+ rx
2
(yk -1/2)2
– rx
2
ry
2
--- (9)
If Pk
1
< 0, the midpoint is inside the ellipse and the pixel on scan line ‘yk’
is closer to the ellipse boundary, otherwise the midpoint is outside or on the
ellipse boundary and we select the pixel on ‘yk - 1’.
Fellipse(x, y) = < 0, if (x, y) is inside the ellipse boundary
= 0, if (x, y) is on the ellipse boundary --- (7)
> 0, if (x, y) is outside the ellipse boundary
45
At the next sampling position (xk+1 + 1 = xk + 2), the decision parameter
for region 1 is evaluated as:
Pk+1
1
= Fellipse(xk+1 + 1, yk +1 -1/2) = ry
2
[(xk+1) + 1]2
+ rx
2
(yk+1 – 1/2)2
– rx
2
ry
2
=> Pk+1
1
= Pk
1
+ 2ry
2
(xk + 1) + ry
2
+ rx
2
[(yk+1 – 1/2)2
– (yk – 1/2)2
] --- (10),
Where, ‘yk+1’ is either ‘yk’ or ‘yk -1’, depending on the sign of Pkꞌ.
Decision parameters are incremented by following amounts:
At the initial position (0, ry), the two terms evaluated to
2ry
2
x = 0 --- (11)
2rx
2
y = 2rx
2
ry --- (12)
As ‘x’ and ‘y’ are incremented, updated values are obtained by adding
2ry
2
to equation – (11) and subtract 2rx
2
from equation – (12). The updated
values are compared at each step and we move from region 1 to region 2,
when 2ry
2
x ≥ 2rx
2
y is satisfied.
In region 1, the initial value of decision parameter is obtained by
evaluating the ellipse function at start position (x0, y0) = (0, ry).
So, P0
1
= Fellipse(1, ry – 1/2) = ry
2
– rx
2
(ry – 1/2)2
– rx
2
ry
2
=> P0
1
= ry
2
– rx
2
ry – 1/4rx
2
--- (13)
Increment = 2ry
2
xk+1 + ry
2
, if Pkꞌ < 0
2ry
2
xk+1 + ry
2
– 2rx
2
yk + 1, if Pkꞌ ≥ 0
46
Over region 2, we sample at unit steps in negative y-direction and
midpoint in now taken between horizontal pixels at each step. For this region
2, the decision parameter is evaluated as:
Pk
2
= Fellipse(xk+1/2, yk -1) = ry
2
(xk+1/2)2
+ rx
2
(yk -1)2
– rx
2
ry
2
--- (14)
If Pk
2
> 0, the midpoint is outside the ellipse and we select the pixel at
scan line ‘xk’. If Pk
2
≤ 0, the midpoint is inside or on the ellipse boundary
and we select pixel position on ‘xk + 1’.
To determine the relationship between successive decision parameters in
region 2, we evaluate the ellipse function at the next sampling step: yk+1 – 1
= yk – 2.
Pk+1
2
= Fellipse(xk+1 + 1/2, yk +1 -1) = ry
2
(xk+1+ 1/2)2
+ rx
2
[(yk – 1) – 1]2
– rx
2
ry
2
=> Pk+1
2
= Pk
2
- 2rx
2
(yk - 1)2
+ rx
2
+ ry
2
[(xk+1 + 1/2)2
– (xk + 1/2)2
] --- (15),
Here, ‘xk+1’ set either ‘xk’ or ‘xk+1’, depending on the sign of Pk
2
.
When we enter region 2, the initial position (x0, y0) is taken as the last
position selected in region 1 and the initial decision parameter in region 2 is:
P0
2
= Fellipse(x0 + 1/2, y0 – 1) = ry
2
(x0 + 1/2) 2
– rx
2
(y0 – 1)2
– rx
2
ry
2
--- (16)
To simplify the calculation of P0
2
, we could select pixel position in
counter clockwise order starting at (rx, 0) unit steps would then be taken in
the positive y-direction upto the last position selected in region 1.
47
ALGORITHM:
STEP 1: Input rx, ry and ellipse center (xc, yc) and obtain the first point on
an ellipse centered on the origin as: (x0, y0) = (0, ry).
STEP 2: Calculate the initial value of decision parameter in region 1 as:
P0
1
= ry
2
– rx
2
ry – 1/4rx
2
STEP 3: At each ‘xk’ position in region 1, starting at k = 0, perform the
following test:
i) If Pk
1
< 0, the next point along the ellipse centered on (0, 0) is
(xk+1, yk) and Pk+1
1
= Pk
1
+ 2ry
2
xk + 1 + ry
2
, otherwise,
ii) The next point along the circle is, (xk+1, yk-1) and
Pk+1
1
= Pk
1
+ 2ry
2
xk + 1 - 2rx
2
yk+1 + ry
2
With 2ry
2
xk + 1 = 2ry
2
xk + 2ry
2
,
2rx
2
yk+1 = 2rx
2
yk - 2rx
2
and continue until 2ry
2
x ≥ 2rx
2
y.
STEP 4: Calculate the initial value of the decision parameter in region 2,
using the last point (x0, y0). Calculated in region 1 as:
P0
2
= ry
2
(x0 + 1/2) 2
– rx
2
(y0 – 1)2
– rx
2
ry
2
STEP 5: At each ‘yk’ position in region 2, starting at k = 0, perform the
following test:
i) If Pk
2
> 0, the next point along the ellipse centered on (0, 0) is
(xk, yk – 1) and Pk+1
2
= Pk
2
- 2rx
2
yk + 1 + rx
2
, otherwise,
ii) The next point along the circle is, (xk + 1, yk - 1) and
48
Pk+1
2
= Pk
2
+ 2ry
2
xk + 1 - 2rx
2
yk+1 + rx
2
Using the same incremental calculations for ‘x’ and ‘y’ as in
region 1.
STEP 6: Determine symmetry points in the other 3 quadrants.
STEP 7: Move each calculated pixel position (x, y) onto the elliptical path
centered on (xc, yc) and plot the co-ordinate values: x = x + xc, y = y + yc.
STEP 8: Repeat the steps for region 1, until 2ry
2
x ≥ 2rx
2
y.
Example: Given input ellipse parameter rx = 8, ry = 6. We illustrate the steps
in the midpoint ellipse algorithm by determining raster positions along the
ellipse path in the first quadrant. Initial values and increments for the
decision parameter calculations as:
2ry
2
= 0 (with increment 2ry
2
= 72) and
2rx
2
y = 2rx
2
ry (with increment -2rx
2
= -128)
For Region 1:
The initial point for the ellipse centered on the origin is (x0, y0) = (0, 6)
and the initial decision parameter value is: P0
1
= ry
2
– rx
2
ry – 1/4rx
2
= - 332.
Successive decision parameter values and positions along the ellipse path
are calculated using the midpoint method as:
49
k Pk
1
(xk+1, yk +1) 2ry
2
xk + 1 2rx
2
yk+1
0 -332 (1, 6) 72 768
1 -224 (2, 6) 144 768
2 - 44 (3, 6) 216 768
3 208 (4, 5) 288 640
4 - 108 (5, 5) 360 640
5 288 (6, 4) 432 512
6 244 (7, 3) 504 384
We now move out of region 1, since 2ry
2
x > 2rx
2
y.
For Region 2:
The initial point is: (x0, y0) = (7, 3) and the initial decision parameter
value is: P0
2
= Fellipse(7 + 1/2, 2) = -151
The remaining positions along the ellipse path in the 1st
quadrant are then
calculated as:
k Pk
2
(xk+1, yk +1) 2ry
2
xk + 1 2rx
2
yk+1
0 -151 (8, 2) 576 256
1 233 (8, 1) 576 128
2 745 (8, 0) - -
FILLED AREA PRIMITIVES:
A standard output primitives is a solid color or patterned polygon area. Other
kinds of area primitives are sometimes available, but polygons are easier to process
since they have linear boundaries.
50
POLYGON FILLING:
It is the process of coloring in a defined area or regions. The region can be
classified as: Boundary defined region and Interior defined region.
When the region is defined in terms of pixels, if comprised of it is known as
interior defined region. The algorithm used for filled interior-defined regions are
known as Flood-Fill Algorithm.
When the region is defined in terms of bounding pixels, that outline, it is
known as boundary defined region. The algorithm used for filling boundary
defined region is known as: Boundary-Fill Algorithm.
FLOOD-FILL ALGORITHM:
While using this, the user generally provides an initial pixel, which is known as
seed pixel, starting from the seed pixel, the algorithm will inspect each of the
surrounding eight pixels to determine whether the extent has been reached.
In 4-connected region, only 4 pixels are surrounding pixels. i.e.: left, right, top
and bottom. The process is repeated until all pixels inside the region have been
inspected.
INTERIOR-DEFINED REGION
BOUNDARY-DEFINED REGION
51
The flood-fill procedure for a 4-connected region is:
void floodfill4(int x, int y, int fillcolor, int oldcolor)
{
if(getPixel(x, y) == oldcolor)
{
setColor(fillcolor);
setPixel(x, y);
floodfill4(x + 1, y, fillcolor, oldcolor);
floodfill4(x – 1, y, fillcolor, oldcolor);
floodfill4(x, y + 1, fillcolor, oldcolor);
floodfill4(x, y – 1, fillcolor, oldcolor);
}
}
P P P
P S P
P P P
P
P S P
P
8 - CONNECTED 4 - CONNECTED
52
The flood-fill procedure for an 8-connected region is:
void floodfill8(int x, int y, int fillcolor, int oldcolor)
{
if(getPixel(x, y) == oldcolor)
{
setColor(fillcolor);
setPixel(x, y);
floodfill4(x + 1, y, fillcolor, oldcolor);
floodfill4(x – 1, y, fillcolor, oldcolor);
floodfill4(x, y + 1, fillcolor, oldcolor);
floodfill4(x, y – 1, fillcolor, oldcolor);
floodfill4(x + 1, y + 1, fillcolor, oldcolor);
floodfill4(x + 1, y - 1, fillcolor, oldcolor);
floodfill4(x - 1, y + 1, fillcolor, oldcolor);
floodfill4(x - 1, y – 1, fillcolor, oldcolor);
}
}
53
BOUNDARY-FILL ALGORITHM:
A Boundary-Fill Algorithm or procedure accepts as input, the co-ordinates of an
interior point (x, y), a fill color and a boundary color. Starting from (x, y) the
procedure test neighboring positions to determine whether they are of the boundary
color, if not they are painted with fill color and their neighbors are tested.
There are 2 methods are used for area filled i.e.: 4-connected and 8-connected.
In 4-connected form the current positions, four neighboring points are tested.
Those pixel positions are right, left, above and below the current pixel. In 8-
connected, the set of neighboring positions to be tested includes the 4 diagonal
pixels. An 8-connected boundary fill algorithm would correctly fill the interior of
the area.
The procedure or a recursive method for filling a 4-connected area with
intensity specified in parameter fill upto a boundary color specified with parameter
boundary. That is:
void boundaryfill4(int x, int y, int fill, int boundary)
{
int current;
S S
8 - CONNECTED4 - CONNECTED
54
current = getPixel(x, y)
if((current != boundary) && (current != fill))
{
setColor(fill);
setPixel(fill);
boundaryfill4 (x + 1, y, fill, boundary);
boundaryfill4 (x – 1, y, fill, boundary);
boundaryfill4 (x, y + 1, fill, boundary);
boundaryfill4 (x, y – 1, fill, boundary);
}
}
We can extend this procedure to fill an 8-connected region by including 4
additional statements to test diagonal positions, such as (x + 1, y – 1). The
procedure for 8-connected area is:
void boundaryfill8(int x, int y, int fill, int boundary)
{
int current;
current = getPixel(x, y)
55
if((current != boundary) && (current != fill))
{
setColor(fill);
setPixel(fill);
boundaryfill8(x + 1, y, fill, boundary);
boundaryfill8(x – 1, y, fill, boundary);
boundaryfill8(x, y + 1, fill, boundary);
boundaryfill8(x, y – 1, fill, boundary);
boundaryfill8(x + 1, y + 1, fill, boundary);
boundaryfill8(x + 1, y - 1, fill, boundary);
boundaryfill8(x - 1, y + 1, fill, boundary);
boundaryfill8(x - 1, y – 1, fill, boundary);
}
}
SCANLINE POLYGON-FILL ALGORITHM:
For each scan line crossing a polygon, the area-fill algorithm locates the
intersection points of the scan line with the polygon edges. These intersection
56
points are then sorted from left to right and the corresponding frame buffer
positions between each intersection pair are set to specified fill color.
Here, the four pixel intersection positions with the
polygon boundaries define two stretches of interior
pixels from x = 10 to x = 14 and from x = 18 to x =
24.
A scan line passing through a vertex intersects two polygon edges at that
position, adding two points to the list of intersections for the scan line.
Here, 2 scan-lines at position ‘y’ and ‘yꞌ’
that intersect edge endpoints. Scan-line ‘y’
intersects five polygon edges. Scan-line ‘yꞌ’
intersects an even number of edges although
it also passes through a vertex. Intersection
point along scan-line ‘y’ correctly identifies
the interior pixel spans.
But with scan-line ‘y’, we need to do some additional processing to determine
the correct interior points.
The topological difference between scan-line ‘y’ and scan-line ‘yꞌ’ is identified
by noting the position of the intersecting edge relative to the scan-line. For scan-
line ‘y’, the two intersecting edges sharing a vertex are on opposite sides of the
scan-line. But for scan-line ‘yꞌ’, the two intersecting edges are both above the scan-
line.
10 14 18 24
Scan line y’
Scan line y
1 2 1
2 1
1
57
Calculations performed in scan-conversion and other graphics algorithms
typically take advantage of various coherence properties of a scene that is to be
displayed. Coherence is simply that the properties of one part of a scene are related
in some way to other parts of the scene, so that the relationship can be used to
reduce processing.
Here, two successive scan-lines crossing a
left edge of a polygon. The slope of this
polygon boundary line can be expressed in
terms of scan-line intersection co-ordinate
is: m = yk+1 – yk/xk+1 - xk --- (1)
Since the change in ‘y’- coordinates between two scan-lines is:
yk+1 – yk = 1 --- (2).
This x-intersection value xk+1 on the upper scan-line can be determined from the
x-intersection value xk on the proceeding scan-line as: xk+1 = xk + 1/m --- (3).
Along an edge, with slope ‘m’, the intersection ‘xk’ value for scan-line ‘k’ above
the initial scan-line can be calculated as: xk = x0 + k/m --- (4).
In a sequential fill algorithm, the increment of ‘x’ values by the amount 1/m
along an edge can be accomplished with interior operations by recalling that the
slope ‘m’ is the ratio of 2 integers : m = ∆y/∆x.
Here ∆x and ∆y are the differences between the edges, endpoint ‘x’ and ‘y’ co-
ordinate values. So incremental calculations of ‘x’- intercepts along an edge for
successive scan lines can be expressed as:
xk+1 = xk + ∆x/∆y --- (5)
Scan-line yk+1
Scan-line yk
(xk+1, yk+1)
(xk, yk)
58
Using this equation, we can perform the integer evaluation if the x-intercepts by
initializing a counter to 0, then incrementing the counter by the value ‘∆x’ each
time we move upto new scan-line. Whenever the counter value becomes equal to
or greater than ∆y, we increment the current x-intersection value by 1 and decrease
the counter by the value ∆y.
ANTIALIASING:
The distortion of information due to low frequency sampling is called aliasing.
We can improve the appearance of displayed raster lines by applying antialiasing
methods compensate for the under-sampling process.
To avoid losing information from such periodic objects, we need to set the
sampling frequency to at least twice of the highest frequency occurring in the
object referred to as Nyquist Sampling Frequency/Nyquist Sampling Rate i.e.:
fs = 2fmax
Another way to state this is that: the sampling interval should be no longer than
one-half the cycle interval called Nyquist Sampling interval. For x-interval
sampling, the Nyquist Sampling interval ∆xs i.e.:
∆xs = ∆xcycle/2, where, ∆xcycle = 1/fmax
* * * * * : Sampling
Position
It shows the effects of under-
sampling
59
In the above figure, the sampling interval is one and one-half times the cycle
interval, so the sampling interval is at least 3 times too big.
A straight forward antialiasing method is to increase sampling rate by
treating the screen as if it were covered with a finer grid that is actually available.
We can then use multiple sample points across this finer grid to determine an
appropriate intensity level for each screen pixel. This technique of sampling object
characteristics at a high resolution and displaying the results at a lower resolution
is called super-sampling/post-filtering.
An alternative to super-sampling is to determine pixel intensity by calculating
the areas of overlap of each pixel with the objects to be displayed. Antialiasing by
computing overlap areas is referred to as Area Sampling/Pre-filtering. Pixel
overlap areas intersect individual pixel boundaries. Raster objects can also be anti-
aliased by shifting the display location of pixel areas. This technique is called pixel
phasing is applied by “micro-positioning” the electron beam is relation to object
geometry.
60
CHAPTER -4
LINE ATTRIBUTES:
This basic attributes of a straight line segment are its type, its width and its
color. Lines can also be displayed using selected pen or brush options.
i. LINE TYPE:
This attribute includes solid lines, dashed lines and dotted line. The line
drawing algorithm is modifying to generate lines by setting the length and
spacing of displayed solid sections along the line path.
A dashed line could be displayed by generating an inter-dash spacing that
is equal to the length of the solid sections. Both the length of the dashes and
the inter-dash spacing are often specified as user options.
A dotted line can be displayed by generating very short dashes with the
spacing equal to or greater than the dash size.
To set the line type attributes with command is: set linetype (lt); where
parameter ‘lt’ is assigned to a positive integer values of 1, 2, 3 or 4 to
generate lines that are respectively solid, dashed, dotted or dash-dotted. The
line-type parameter ‘lt’ could be used to display variations in dot-dash
patterns.
61
ii. LINE WIDTH:
Implementation of line-width options depends on the capabilities of the
output device. A line-width command is used to set the current line-width
value in the attribute set. The command for this is:
set linewidthscalefactor(lw)
Here line-width parameter ‘lw’ is assigned to a positive number to
indicate the relative width of the line to be displayed.
A value ‘1’ specifies a standard width line. If a user set ‘lw’ to a value
0.5 to plot a line whose width is half of the standard line. Values greater than
‘1’ produce lines thicker than the standard.
Line-caps are used to adjust the shape of the line ends and give better
appearance. One kind of line cap is butt cap, obtained by adjusting the end
positions of the component parallel lines, so that the thick line is displayed
with square ends that are perpendicular to the line path. If the specified line
has slope ‘m’, the square end of the thick line has slope 1/m. Another line-
cap is the round cap, obtained by adding a filled semicircle to each butt cap.
The circular arcs are centered on the line endpoints and have a diameter
equal to the line thickness. A third type of line cap is the projecting square
cap, where we simply extended the line and add butt caps that are positioned
one-half of the line with beyond the specified end points.
[BUTTCAP] [ROUNDCAP] [PROJECTING SQUARE CAP]
62
We can generate thick polylines that are smoothly joined at the cost of
additional processing at the segment endpoints. A meter join is
accomplished by extending the outer boundaries of each of the two lines
until they meet. A round join is produced by capping the connection
between the two segments with a circular boundary whose diameter is equal
to the line width. A bevel join is generated by displaying the line segments
with butt caps and filling in the triangular gap where the segments meet.
iii. LINE WIDTH:
Lines can be displayed with pen and brush selections options in this
category include shape, size and pattern. E.g.: , , , , , , :, etc.
These shapes can be stored in a pixel mask, which identifies the array of
pixel positions that are to be set along the line path. Lines generated with
pen or brush shapes can be displayed in various widths by changing the size
of the mask.
iv. LINE COLOR:
When a system provides color or intensity options, a parameter giving the
current color index is included in the list of system attribute values.
[MITER JOIN] [ROUND JOIN] [BEVEL JOIN]
63
A polyline routine displays a line in the current color by setting this color
value in the frame buffer at pixel locations along the line path using the set
pixel procedure. The number of color choices depends on the number of bits
available per pixel in the frame buffer. The function of line color is:
Set PolylineColorIndex(lc), where lc = line color parameter
A line drawn in background color is invisible and a user can ensure a
previously displayed line by specifying it in the background color.
E.g.: set linetype (2);
set linewidthscalefactor (2);
set PolylineColorIndex (5);
Polyline (n1, wcpoints1);
set PolylineColorIndex (6);
Polyline (n2, wcpoints2);
CURVE ATTRIBUTES:
Parameters of curve attributes are same as line attributes we can display curves
with varying colors, widths, dot-dash patterns and available pen and brush options
methods are also same as line attributes. We can generate the dashes in the various
octants using circle symmetry, but we must shift the pixel positions to maintain the
correct sequence of dashes and spaces as we move from one octant to the next.
Raster curves of various widths can be displayed using the method of horizontal
or vertical pixel spans, where the magnitude of the curve slope is less than 1, we
64
plot vertical spans, where the slope magnitude is greater than 1, and we plot
horizontal spans.
Using circle symmetry, we generate the circle path with vertical spans in the
octant from x = 0 to x = y and then reflect pixel positions about the line y = x to
obtain the remainder of the curve. For displaying the thick curves is to fill area
between two parallel curve paths, whose separation distance is equal to the desired
width.
AREA FILL ATTRIBUTES:
i. FILL STYLES:
Areas are displayed with 3 basic fill styles. i.e.: hollow with a color
border, filled with a solid color or filled with specified pattern or design. The
function for basic fill style is: set Interiorstyle(fs);
Where fs = fill style parameter and the values include hollow, solid and
pattern. Another value for fill style is hatch, which is used to fill an area with
selected hatching patterns i.e.: parallel lines or crossed lines. Fill style
parameter ‘fs’ are normally applied to polygon areas, but they can also be
implemented to fill regions with curved boundaries.
Hollow areas are displayed using only the boundary outline with the
interior color, same as the background color. A solid fill displayed in a
single color upto and including the borders of the region. The color for a
solid interior or for a hollow area outline is chosen with:
set InteriorColorIndex(fc);
65
Where fc = fill color parameter is set to desired color code.
ii. PATTERN FILL:
We select fill patterns with set InteriorStyleIndex(Pi), where
Pi = Pattern index parameter, specifies a table position.
Example: The following set of statements would fill the area defined in
the fill area command with the second pattern type stored in the pattern
table:
set InteriorStyle(Pattern);
set InteriorStyleIndexI2);
fill Area(n, points);
Separate tables are set up for hatch patterns. If we had selected hatch fill
for the interior style in this program segment, then the value assigned to
parameter ‘Pi’ is an index to the stored patterns in the hatch table. For fill
style pattern, table entries can be created on individual output devices with:
set PatternRepresentation (ws, Pi, nx, ny, cp);
Where, parameter ‘Pi’ sets the pattern index number for workstation ws.
cp = two dimensional array of color codes with ‘nx’ columns and ‘ny’ rows.
HOLLOW SOLID PATTERN
N
DIAGONAL HATCH FILL DIAGONAL CROSS
HATCH FILL
66
Example: The 1st
entry in the pattern table for workstation1 is
cp[1, 1] = 4; cp[2, 2] = 4;
cp[1, 2] = 0; cp[2, 1] = 0;
set PatternRepresentation(1, 1, 2, 2, cp);
Index(Pi) Pattern(cp)
1 4 0
0 4
Here, 1st
2 entries for the color table-color
array ‘cp’ specifies a pattern that
produces alternate red and black diagonal
pixel
2
2 1 2
1 2 1
2 1 2
When a color array ‘cp’ is to be applied to fill a region, we specify the
size of the area that is to be converted by each element of the array. We do
this by setting the rectangular co-ordinate extents of the pattern:
set Patternsize(dx, dy);
Here dx and dy is the co-ordinate width and height of the array mapping.
A reference position for starting a pattern fill is assigned with the
statement: set PatternReferencepoint(position);
Here, position = pointer to co-ordinate (xp, yp) that fix the lower left
corner of the rectangular pattern. Form this starting position, the pattern is
then replicated in the ‘x’ and ‘y’ directions until the defined area is covered
by non-overlapping copies of pattern array. The process of filling an area
67
with a rectangular pattern is called tiling and rectangular fill patterns are
sometimes referred to a tiling pattern.
If the row positions in the pattern array are referred in reverse (i.e.: from
bottom to top starting at 1), a pattern value is then assigned to pixel position
(x, y) in screen or window co-ordinate as:
set Pixel(x, y, cp(y mod ny + 1), (x mod nx + 1))
Where, ‘nx’ and ‘ny’ = number of rows and columns in pattern array.
iii. SOFT FILL:
Modified boundary fill and flood fill procedures that are applied to
repaint areas, so that the fill color is combined with background colors are
referred to as Soft-fill/Tint-fill algorithm.
A linear soft fill algorithm repaints an area that was originally painted by
merging a foreground color ‘F’ with a single background color ‘B’. Assume,
we know the values for ‘F’ and ‘B’, we can determine how these colors were
originally combined by checking the current color contents of the frame
buffer. The current RGB color ‘P’ of each pixel within the area to be refilled
is some linear combination of ‘F’ and ‘B’.
P = tF + (1 – t)B --- (1)
Where, the transparency factor ꞌtꞌ has a value between 0 and 1 for each
pixel. For value of ꞌtꞌ less than 0.5, the background color contributes more to
the interior color of the region that does the fill color.
68
The vector equation – (1) holds for each,
P = (PR, PG, PB), F = (FR, FG, FB), B = (BR, BG, BB) --- (2).
So, we can calculate the value of parameter ꞌtꞌ using one of the RGB color
component as:
t = PK – BK/FK – BK --- (3),
Where K = R, G or B and FK ≠ BK. The parameter ꞌtꞌ has the same value
for each RGB component but round off to integer codes can result in
different values of 't' for different components.
We can minimize this round off error by selecting the component with
the largest difference between ‘F’ and ‘B’. This value of ꞌtꞌ is then used to
mix the new fill color ‘NF’ with the background color, using either a
modified flood-fill or boundary-fill procedure.
Soft-fill procedures can be applied to an area whose foreground color is
to be merged with multiple background color areas. E.g.: check board
pattern. When two background colors B1 and B2 are mixed with foreground
color ‘F’, the resulting pixel color ‘P’ is:
P = t0F + t1B1 + (1 – t0 – t1)B2 --- (4)
Where the sum of the coefficients ‘t0’, ‘t1’ and (1 – t0 – t1) on the color
terms must equal to 1. These parameters are then used to mix the new fill
color with parameters are then used to mix the new fill color with the two
background colors to obtain the new pixel color.
69
FILLED AREA ATTRIBUTES WITH IRREGULAR BOUNDARY:
i. CHARACTER ATTRIBUTES:
Here, we have to control the character attributes, such as font size, color
and orientation. Attributes can be set both for entire character string (text)
and for individual characters defined as marker symbols.
a. Text Attributes:
It includes the font (type face) which is a set of characters with a
particular design style, such as: Courier, Times Roman etc. This is also
displayed with assorted underlying styles. i.e.: solid, dotted, double and
also the text may be boldface, italics or in outline or shadow style.
A particular font and associated style is selected by setting an interior
code for the text font parameter ‘tf’ in the function: set Textfont(tf);
Color setting for displayed text is done by the function:
set TextColorIndex(tc);
Here ‘tc’ = text color parameter specifies an allowable color code.
Text size can be adjusted without changing the width to height ratio of
characters with: set CharacterHeight(ch);
Here ‘ch’ is assigned a real value greater than 0 to set the coordinate
height of capital letters.
70
The width of text can be set with the function:
set CharacterExpansionFactor(cw);
Here, cw = character-width parameter is set to positive real value that
scales the body width of characters. Text height is unaffected by this
attributed setting.
Spacing between characters is controlled separately with:
set CharacterSpacing(cs);
Here cs = character spacing parameter can be assigned any real value.
The value assigned to ‘cs’ determine the spacing between character bodies
along print lines. Negative values for ‘cs’ overlap character bodies positive
values insert space to spread out the displayed characters.
The orientation for a displayed character string is set according to the
direction of the character up vector: set CharacterUpVector(upvect);
Parameter ‘upvect’ in this function is assigned two values that specify the
‘x’ and ‘y’ vector components. Text is then displayed, so that the orientation
of characters from baseline to cap line in the direction of the up-vector.
A procedure for orienting text rotates characters so that the sides of
character bodies, from baseline to cap line are aligned with the up-vector.
The rotated character shapes are then scan converted into the frame buffer.
An attributes parameter for this option is set with the statement:
set TextPath(tp);
71
Here tp = text path can be assigned with the value right, left, up, down,
horizontal, vertical etc.
For text alignment, the attribute specifies how text is to be positioned
with respect to the start coordinates. Alignment attributes are set with:
set TextAlignment(h, v);
Here ‘h’ and ‘v’ control horizontal and vertical alignment respectively.
Horizontal alignment is set by assigning ‘h’, a value of left, center and right.
Vertical alignment is set by assigning ‘v’, a value of top, cap, half, base or
bottom.
A precision specification for text display is given with:
set TextPrecision(tpr);
Here tpr = text precision parameter is assigned one of the values: string,
char or stroke.
The highest quality ‘text’ is displayed when the precision parameter is set
to the value stroke. For this precision setting, greater detail would be used in
defining the character shapes and the processing of attributes selection and
other string manipulation procedures would be carried out to the highest
possible accuracy. The lowest quality precision setting, string is used for
faster display of character string.
72
b. Marker Attributes:
A marker symbol is a single character that can be displayed in different
colors and in different sizes. Marker attributes are implemented by
procedures that load the choses character into the raster at the defined
positions with the specified color and size. We select a particular character
to be the marker symbol with: set MarkerType(mt);
Here, mt = marker type parameter is set to an integer code. Typical codes
for marker type are integers 1 through 5, specifying respectively, a dot (.), a
vertical cross (+), an asterisk (*), a circle (O) and a diagonal cross (x).
Displayed marker types are centered on the marker coordinates we set the
marker size with: set MarkerSizeScaleFactor(ms);
Here, ms = marker size parameter, assigned a positive number.
It is applied to the normal size for the particular marker symbol chosen,
values greater than 1 produce character enlargement; values less than 1
reduce the marker size.
Marker color is specified with: set PolymarkerColorIndex(mc);
Here, mc = selected color code, stored in current attribute list and used to
display subsequently specified market primitives.
ii. BUNDLED ATTRIBUTES:
When each function references a single attribute, then that specifies
exactly how a primitive is to be displayed with that attribute setting. These
73
specifications called Individual/Unbundled Attributes and they are used
with an output device that is capable of displaying primitives in the way
specified.
A particular set of attribute values for a primitive on each output device is
then chosen by specifying the appropriate table index. Attributes specified in
this manner are called Bundled Attributes. The table for each primitive that
defined groups of attributes values to be used when displaying that primitive
on particular output device is called a Bundle table.
Attributes that may be bundled into the workstation table entries are those
that don’t involve co-ordinate specifications, such as color and line type. The
choice between a bundled and an unbundled specification is made by setting
a switch called the aspect source flag for each of these attributes:
set IndividualASF(attribute ptr, flag ptr);
Where ‘attribute ptr’ parameter points to a list of attributes and
parameter ‘flag ptr’ points to the corresponding list of aspect source flags.
Each aspect source flag can be assigned a value of individual or bundled.
a. Bundled Line Attributes:
Entries in the bundle table for line attributes on a specified workstation
are set with function: set PolylineRepresentation(ws, li, lt, lw, lc);
Here, ws = workstation identifier, li = line index parameter, defined the
bundle table position. Parameter lt, lw and lc are then bundled and assigned
values to set the line type, line width and line color specifications
respectively for the designated table index.
74
E.g.: set PolylineRepresentation(1, 3, 2, 0, 5, 1);
set PolylineRepresentation(4, 3, 1, 1, 7);
Here, a polyline that is assigned a table index value of 3 would then be
displayed using dashed lines at half thickness in a blue color on workstation
‘1’ while on workstation 4, this same index generates solid standard sized
white lines. Once the bundle tables have been set up a group of bundled line
attributes is chosen for each workstation by specifying the table index value.
set PolylineIndex(li);
b. Bundled Area Fill Attributes:
Table entries for bundled area-fill attributes are set with:
set InteriorRepresentation(ws, fi, fs, Pi, fc);
This defines the attribute list corresponding to fill index ‘fi’ on
workstation ws. Parameter ‘fs’, ‘Pi’, and ‘fc’ are assigned values for the fill
style, pattern index and fill color respectively on the designated workstation.
Similar bundle tables can also be set up for edge attributes of polygon fill
areas. A particular attribute bundle is then selected from the table with the
function: set InteriorIndex(fi);
Subsequently defined fill areas are then displayed on each active
workstation according to the table entry specified by the fill index parameter
‘fi’.
75
c. Bundles Text Attributes:
The function is: set TextRepresentation(ws, ti, tf, tp, te, ts, tc);
Which bundles value for text font, precision, expansion factor, size, and
color in a table position for workstation ‘ws’ that is specified by the value
assigned to text index parameter ‘ti’. Other text attributes, including
character up vector, text, path, character height and text alignment are set
individually. A particular text index value is then chosen with the function:
set TextIndex(ti);
Each text function that is then invoked is displayed on each workstation
with the set of attributes referenced by this table position.
d. Bundled Marker Attributes:
Table entries for bundled marker attributes are set up with:
set PolymarkerRepresentation(ws, mi, mt, ms, mc);
This defined the marker type, marker scale factor and marker color for
index ‘mi’ on workstation ws.
Bundle table sections are then made with the function:
set PolymarkerIndex(mi);
76
CHAPTER -5
2D TRANSFORMATION:
A fundamental objective of 2D transformation is to simulate the movement and
manipulation of objects in the plane. There are 2 points of view are used for
describing the object movement. That is:
i. The object itself is moved relative to a stationary co-ordinate system or
background. The mathematical statement of this viewpoint is described by
geometric transfer motions applied to each point of the object.
ii. The second view holds that the object is held stationary, while the co-
ordinate system is moved relative to the object. This effect is attained
through the application of co-ordinate transformations.
The transformations are used directly by application programs and within many
graphic sub-routines.
BASIC TRANSFORMATION IN 2D:
In 2D Transformation, the basic transformation includes 3 parameters to
reposition and resize the 2D objects. i.e.: Translation, Rotation and Scaling.
i. TRANSLATION:
A translation is applied to an object by repositioning it along a straight
line path from one-coordinate location to another. We translate a 2D point
by adding translation distance ‘tx’ and ‘ty’ to the original co-ordinate position
(x, y) to move the point to a new position (xꞌ, yꞌ). So,
77
xꞌ = x + tx, yꞌ = y + ty --- (1)
The translation distance pair (tx, ty) is called a translation vector or shift
vector. The equation can be express as a single matrix equation by using the
column vector to represent co-ordinate positions and the translation vector
are:
ii. ROTATION:
A 2D Rotation is applied to an object by repositioned it along a circular
path in xy-plane. To generate a rotation angle θ, and the position (xr, yr) of
the rotation or pivot point, about which the object is to be rotated.
Positive values for the rotation angle define counter clockwise rotations
about the pivot point and negative values rotate objects in clockwise
direction. This transformation can also be described as a rotation about a
rotation axis, which is perpendicular to xy-plane and passes through pivot
point.
The transformation equations for rotation of point position ‘P’, when the
pivot point is at the co-ordinate origin.
r = constant distance of the point from origin.
θ = rotation angle
Φ = original angular position of the point from horizontal.
X1
X2
P =
Xꞌ1
Xꞌ2
Pꞌ =
tx
ty
T = --- (2)
78
So, transformed co-ordinates in terms of angle θ and Φ are:
The original co-ordinates of the point in polar co-ordinates are:
Substitute equation – (2), in equation – (1), we get the transformation
equation, for rotating a point of position (x, y) through an angle ‘θ’ about the
origin.
We can write the rotation equation in matrix from is: Pꞌ = R.P --- (4),
where rotation matrix is:
When co-ordinate positions are represented as row vectors instead of
column vectors, the matrix product in rotation equation – (4) is transposed,
so that the transformed row co-ordinate vector [xꞌ, yꞌ] is calculated as:
xꞌ = rcos(θ + Φ) = rcosΦcosθ – rsinΦsinθ
yꞌ = rsin(θ + Φ) = rcosΦsinθ + rsinΦcosθ
--- (1)
x = rcosΦ
y = rsinΦ
--- (2)
xꞌ = xcosθ – ysinθ
yꞌ = xsinθ + ycosθ
--- (3)
cosθ - sinθ
sinθ
sinθ cosθ
R
=
---
(5)
(Clockwise direction)
cosθ sinθ
- sinθ cosθ
R
=
---
(6)
(Anti-Clockwise
direction)
79
PꞌT
= (R.P)T
= PT
.RT
--- (7)
Where PT
= [x y]
RT
= Transpose of ‘R’ obtain by interchanging the rows and
columns.
The transformation equation for rotation of a point about any specified
rotation position (xr, yr) is:
Example 1: Consider an object ‘ABC’ with co-ordinates A(1, 1), B(10, 1),
C(5, 5). Rotate the object by 90 degree in anticlockwise direction and give
the co-ordinates of the transformed object.
Example 2: Perform a 45 degree rotation of the object A(2, 1), B(5, 1) and
C(5, 6) in clockwise direction and give the co-ordinates of the transformed
objects.
xꞌ = xr + (x –xr)cosθ – (y – yr)sinθ
yꞌ = yr + (x –xr)sinθ + (y – yr)cosθ
--- (8)
A
B
C
1
10
5
1
1
5
X =
cosθ sinθ
- sinθ cosθ
R =
cos90 sin90
- sin90 cos90=
0 1
-1 0
=
1
10
5
1
1
5
Xꞌ = [X].[R] =
0 1
-1 0
-1
-1
-5
1
10
5
=
A
B
C
80
iii. SCALING:
A scaling transformation alters the size of the object. This operation can
be carried out for polygons by multiplying the co-ordinate values (x, y) of
each vertex by scaling factors ‘Sx’ and ‘Sy’ to produce the transformed co-
ordinates (xꞌ, yꞌ) as:
xꞌ = x . Sx and yꞌ = y . Sy --- (1)
Scaling factors ‘Sx’ scales objects in the x-direction, while ‘Sy’ scales in
the y-direction. The transformation equation in matrix form is:
Or, Pꞌ = S. P --- (3)
The scaling factors ‘Sx’ and ‘Sy’ is less than 1, reduce the size of objects,
values greater than 1 produce an enlargement. Specifying a value of 1for
both ‘Sx’ and ‘Sy’ leaves the size of objects unchanged. When ‘Sx’ and ‘Sy’
A
B
C
2
5
5
1
1
6
X =
cosθ - sinθ
sinθ cosθ
R =
cos45 - sin45
sin45 cos45
=
1/√2 -1/√2
1/√2 1/√2
=
Xꞌ = [X].[R] =
2
5
5
1
1
6
1/√2 -1/√2
1/√2 1/√2
3/√2
6/√2
11/√2
-1/√2
-4/√2
1/√2
= B
C
A
xꞌ
yꞌ
=
Sx 0
0 Sy
x
y
--- (2)
81
are assigned the same value, a uniform scaling is produced that maintains
relative object proportions.
We can control the location of a scaled object by choosing a position,
called the fixed point that is to remain unchanged after the scaling
transformation. Co-ordinates for the fixed point (xf, yf) can be chosen as one
of the vertices, the object centroid or any other position.
For a vertex, with co-ordinates (x, y), the scaled co-ordinates (xꞌ, yꞌ) are
calculated as:
xꞌ = xf + (x – xf)Sx and yꞌ = yf + (y – yf)Sy --- (4)
The scaling transformations to separate the multiplicative and additive
items:
xꞌ = x . Sx + xf(1 – Sx) and yꞌ = y . Sy + yf(1 – Sy) --- (5)
Where, the additive terms xf(1 – Sx) and yf(1 – Sy) are constant for all
points in the object.
Example 1: Scale the object with co-ordinates A(2, 1), B(2, 3), C(4, 2) and
D(4, 4) with a scale factor Sx = Sy = 2.
Sx 0
0 Sy
S =
2 0
0 2
= X =
2
4
4
1
3
2
2
4
82
Example 2: What will be the effect of scaling factor Sx = 1/2 and Sy = 1/3
on a given triangle ABC whose co-ordinates are: A[4, 1], B[5, 2], C[4, 3]?
OTHER TRANSFORMATION:
i. REFLECTION:
A reflection is a transformation that produces a mirror image of an
object. The mirror image for a 2D reflection is generated relative to an axis
of reflection by the object 180 degree about the reflection axis.
Reflection about x-axis, the line y = 0, the x-axis is accomplished with
the transforming matrix is given below. This transformation keeps ‘x’ values
the same, but flips the y-value of co-ordinate positions.
Xꞌ = [X].[S] =
4
4
5
1
2
3
1/2 0
0 1/3
=
2
2
1/3
2/3
1
5/2
X =
4
4
1
2
3
5
Sx 0
0 Sy
S =
1/2 0
0 1/3
=
Xꞌ = [X].[S] =
2
4
2
4
1
3
2
4
2 0
0 2
=
4
8
8
2
6
4
4
8
83
The reflection about y-axis flips ‘x’ co-ordinates while keeps ‘y’ co-
ordinates the same. The matrix for this transformation is:
We flip both ‘x’ and ‘y’ co-ordinates of a point by reflecting relative to
an axis that is perpendicular to xy-plane and that passes through the co-
ordinate origin. The transformation referred to as a reflection relative to the
co-ordinate origin has the matrix representation is:
1
2 3
2ꞌ 3ꞌ
1ꞌ
x
y
Original
Position
Reflected
Position
or ---- (1)
1
0
0
-1
0
1
0
0 0
1
0
0
-1
1
2
3
2ꞌ
3ꞌ
1ꞌ
y
x
Original
Position
Reflected
Position
or ---- (2)
-1
0
0
1
0
1
0
0 0
-1
0
0
1
12
3
2ꞌ
3ꞌ
1ꞌ
y
x
Original
Position
Reflected
Position
or ---- (3)
-1
0
0
-1
0
1
0
0 0
-1
0
0
-1
84
If we choose the reflection axis as the diagonal line y = x, the reflection
matrix is:
To obtain a transformation matrix for reflection about the diagonal y = -x,
we could concatenate matrices for transformation sequence.
i. Clockwise rotation by 45 degree
ii. Reflection about y-axis.
iii. Counter clockwise rotation by 45 degree.
The resulting transformation matrix is:
or ---- (4)
0
1
1
0
0
1
0
0 0
0
1
1
0
12
3
2ꞌ
3ꞌ
1ꞌ
y
x
Original
Position
Reflected
Position
or
0
1
1
0
0
1
0
0 0
0
1
1
0
12
3
2ꞌ
3ꞌ
1ꞌ
y
x
Original
Position
Reflected
Position
y = x
450
y
x
450
85
Example: Consider a triangle ABC whose co-ordinate are: A= [4 1], B = [5, 2],
and C = [4, 3]. a) Reflect the given triangle about x-axis; b) reflect the given
triangle about y-axis, c) reflect the given triangle about y = x and d) reflect the
given triangle about y = -x.
a) The transformation matrix for reflection about x-axis is:
b) The transformation matrix for reflection about y-axis:
c) The transformation matrix for reflection about y = x is:
d) The transformation matrix for reflection about y = -x is:
ii. SHEARING:
A transformation that distorts the shape of an object such that
transformed shape appears as if the object were composed of internal layers
that had been called to slide over each other is called a ‘Shear’. Two
X =
4
5
1
2
[T] = => Xꞌ = [X][T] =
4 3
1
0
0
-1
4
5
-1
-2
4 -3
X =
4
5
1
2
[T] = => Xꞌ = [X][T] =
4 3
-1
0
0
1
- 4
- 5
1
2
- 4 3
X =
4
5
1
2
[T] = => Xꞌ = [X][T] =
4 3
0
1
1
0
1
2
4
5
3 4
X =
4
5
1
2
[T] = => Xꞌ = [X][T] =
4 3
0
-1
-1
0
-1
-2
-4
-5
-3 -4
86
common shearing transformations are those shift co-ordinate x-values and
those that shift y-values.
An x-direction shear relative to x-axis is produced with transformation
matrix is:
This transforms co-ordinate position as:
xꞌ = x + shx . y and yꞌ = y --- (2)
A y-direction shear relative to y-axis is produced with transformation
matrix is:
This transforms co-ordinate position as:
xꞌ = x and yꞌ = shy . x + y --- (4)
Any real number can be assigned to the shear parameter ‘Shx’. A co-
ordinate position (x, y) is then shifted horizontally by an amount
proportional to its distance (y-value) from x-axis (y = 0). We can generate x-
direction shears relative to other reference lines with:
--- (1)
1
0
shx
1
0
1
0
0 0
--- (3)
1
shy
0
1
0
1
0
0 0
87
With co-ordinate positions transformed as:
xꞌ = x + shx(y – yref) and yꞌ = y --- (6)
A y-direction shear relative to the line x = xref is generated with
transformation matrix is:
This generates transformed co-ordinate position:
xꞌ = x and yꞌ = shy(x – xref) + y --- (8)
Example: Consider a unit square, find the co-ordinate of transformed object
when the transformed matrix of shearing for x-axis, shx = 2.
--- (5)
1
0
shx
1
-shx . yref
1
0
0 0
--- (7)
1
shy
0
1
0
1
-shy . xref
0 0
Xꞌ = [X].[T] =X =
0
1
0
0
0
1
1
1
1 2
0 1
T = =
0
1
1
0
2
3
1
1
1 2
0 1
0
1
0
0
0
1
1
1
88
MATRIX REPRESENTATION AND HOMOGENEOUS CO-ORDINATES:
The basic transformations can be expressed in the general matrix form:
Pꞌ = M1.P +M2 --- (1)
With co-ordinate positions ‘P’ and ‘Pꞌ’ represented as column vectors. Matrix
‘M’ is a 2 by 2 array containing translational terms.
For translation, M1 = identity matrix. For rotation or scaling, M2 contains the
translational terms associated with the pivot point or scaling fixed point.
To express any 2D transformation as a matrix multiplication, we represent each
Cartesian co-ordinate position (x, y) with the homogeneous co-ordinate triple (xh,
yh, h) where:
x = xh/h, y = yh/h --- (2)
A general homogeneous co-ordinate representation can also be written as (h.x,
h.y, h). For 2D geometric transformations, the homogeneous parameter ‘h’ must be
any non-zero value. Thus there are an infinite number of equivalent homogeneous
representations for each co-ordinate point (x, y).
A
D C
B
1
1
(1, 1)
(0, 0)
A*
D*
C*
B*
1
1(0, 0) 2 3
89
A convenient choice is simply to set h = 1. Each 2D position is then represented
with homogeneous co-ordinates (x, y, 1). Other values for parameter ‘h’ are
needed.
The homogeneous co-ordinates are used in mathematics to refer to the effect of
this representation on Cartesian equations. When a Cartesian point (x, y) is
converted to a homogeneous representation (xh, yh, h) equations containing ‘x’ and
‘y’ such as f(x, y) = 0, become homogeneous equations in the three parameters xh,
yh and h. If each of the three parameters replaced by any value ‘v’ times that
parameter, the value ‘v’ can be factored out of the equations.
Expressing positions in homogeneous co-ordinates allows us to represent all
geometric transformation equation as matrix multiplications. Co-ordinates are
represented with three element column vectors and transformation operations are
written as 3 by 3 matrices. For translation, we have:
This can be written in abbreviated form:
Pꞌ = T(tx, ty).P --- (4)
Here T(tx, ty) as the 3 by 3 translation matrix.
The inverse of the translation matrix is obtained by replacing the translation
parameter ‘tx’ and ‘ty’ with their negatives ‘- tx’ and ‘- ty’. Rotation transformation
equations about the co-ordinate origin are now written as:
xꞌ
yꞌ
1
1
0
0
0
1
0
tx
ty
1
x
y
1
= --- (3)
90
Or as, Pꞌ = R(θ).P --- (6)
The rotation transformation operation R(θ) is the 3 by 3 matrix with rotation
parameter ‘θ’. We get the inverse rotation matrix when ‘θ’. We get the inverse
rotation matrix when ‘θ’ is replaced with ‘- θ’.
Finally a scaling transformation relative to the co-ordinate origin is now
expressed as the matrix multiplication.
Or as, Pꞌ = S(Sx, Sy).P --- (8)
Here S(Sx, Sy) is the 3 by 3 matrix with parameter ‘Sx’ and ‘Sy’. Replacing these
parameters1/Sx and 1/Sy, with their multiplicative inverse yields inverse scaling
matrix.
TRANSFORMATION BETWEEN CO-ORDINATE SYSTEMS:
Here, the two Cartesian system with the co-ordinate origins at (0, 0) and (x0, y0)
and with an orientation angle ‘θ’ between ‘x’ and xꞌ-axis. To transform object
description from ‘xy’ co-ordinate to ‘xꞌyꞌ’ co-ordinates, we need to set up a
transformation that super imposes the xꞌyꞌ-axes into xy-axes. This is done in two
steps:
xꞌ
yꞌ
1
cosθ
sinθ
0
- sinθ
cosθ
0
0
0
1
x
y
1
= --- (5)
xꞌ
yꞌ
1
Sx
0
0
0
Sy
0
0
0
1
x
y
1
= --- (7)
91
i. Translate so that the origin (x0, y0) of xꞌyꞌ
system is moved to the origin of the xy
system.
ii. Rotate the xꞌ-axis onto the x-axis.
iii. Translation of the co-ordinate origin is
expressed with the matrix operation.
The orientation of the two systems after the translation operation would appear.
To get the axes of the two systems into coincidence, we then perform the
clockwise rotation.
Concatenating these 2 transformations matrices gives us the complete
composite matrix for transforming object descriptions from the xy-system to the
xꞌyꞌ-system:
Mxy, xꞌyꞌ = R(-θ).T(-x0, - y0) --- (3)
x-axis
y-axis yꞌ-axis xꞌ-axis
θ
yv
T(-x0, - y0) =
1
0
0
0
1
0
-x0
-y0
1
--- (1)
R(-θ)
cosθ
- sinθ
0
sinθ
cosθ
0
0
0
1
= --- (2)
θ
x-axis
y-axis
yꞌ-axis
xꞌ-axis
yꞌ xꞌ
Py
92
An alternative method for giving the orientation of the second co-ordinate
system is to specify a vector ‘V’ that indicates the direction for the position of yꞌ-
axes.
Vector ‘V’ is specified as a point in the xy-reference frame relative to the origin
of the xy-system. A unit vector in the yꞌ-direction can then obtained as:
V = V/|V| = (Vx, Vy) --- (4)
The unit vector ‘u’ along xꞌ-axis by rotating ‘V’ as -90 degree clockwise as:
u = (Vy, -Vx) = (ux, uy) --- (5)
The elements of any rotation matrix could be expressed as elements of a set of
orthogonal unit vectors. So the matrix to rotate xꞌyꞌ-system into coincidence with
the xy-system can be written as:
Suppose we choose the orientation for the yꞌ-axis as v = (-1, 0), then the xꞌ-axis
is in the positive y-direction and the rotation transformed matrix is:
x-axis
y-axis yꞌ-axis xꞌ-axis
V y0
x0
R
ux
vx
0
uy
vy
0
0
0
1
= --- (6)
0
-1
0
1
0
0
0
0
1
--- (7)
93
Equivalently, we can obtain this rotation matrix by setting the orientation angle
as θ = 90o
. In an interactive application, it may be more convenient to choose the
direction for ‘V’ relative to position ‘P0’ than it is to specify it relative to the xy-co-
ordinate origin. Unit vectors ‘u’ and ‘v’ would then be oriented.
COMPOSITE TRANSFORMATION:
i. TRANSLATION:
If 2 successive translation vectors (tx1, ty1) and (tx2, ty2) are applied to a
co-ordinate position ‘P’, the final transformed location ‘Pꞌ’ is calculated as:
Pꞌ = T(tx2, ty2). {T(tx1, ty1).P} = {T(tx2, ty2).T(tx1, ty1). P} --- (1)
Where, ‘P’ and ‘Pꞌ” are represented as homogeneous co-ordinate column
vectors.
The composite transformation matrix for this sequence of translation is:
Or, T(tx2, ty2).T(tx1, ty1) = T(tx1 + tx2, ty1 + ty2) --- (3)
1
0
0
0
1
0
tx2
ty2
1
= --- (2)0
0
0
1
0
tx1 + tx2
ty1 + ty2
1
11
0
0
0
1
0
tx1
ty1
1
x-axis
y-axis yꞌ-axis xꞌ-axis
V = P1 – P0
y0
x0
The components of ‘v’ are now calculated
as: V = P1 – P0/|P1 – P0| --- (8), and ‘u’ is
obtained as the perpendicular ‘v’ that forms
a right-handed Cartesian system.
94
This demonstrates that 2 successive translations are additive.
ii. ROTATION:
Two successive rotations applied to point ‘P’ produce the transformed
position: Pꞌ = R(θ2).{R(θ1).P} = {R(θ2).R(θ1)}.P --- (1)
By multiplying the 2 rotation matrices, we can verify that 2 successive
rotations are additive. That is: R(θ2).R(θ1) = R(θ1 + θ2) --- (2)
So, that the final rotated co-ordinates can be calculated with the
composite rotation matrix as: Pꞌ = R(θ1 + θ2).P --- (3)
iii. SCALING:
Concatenating transformation matrix for 2 successive scaling operations
produces the following composite scaling matrix:
Or, S(Sx2, Sy2).S(Sx1, Sy1) = S(Sx1 + Sx2, Sy1 + Sy2) ---- (2)
iv. GENERAL PIVOT POINT ROTATION:
We can generate rotations about any selected pivot point (xr, yr) by
performing the following sequence, translate-rotate-translate operations.
Sx2
0
0
0
Sy2
0
0
0
1
Sx1
0
0
0
Sy1
0
0
0
1
=
Sx1.Sx2
0
0
0
Sy1.Sy2
0
0
0
1
--- (1)
95
i. Translate the object, so that the pivot point position is moved to the
co-ordinate origin.
ii. Rotate the object about the co-ordinate origin.
iii. Translate the object, so that the pivot-point is reformed to its original
position.
That is: T = [Tr][Rθ][Tr]-1
= T(xr, yr).R(θ).T(-xr, -yr)
Example: Consider a triangle ABC having co-ordinate a = [4, 1], B = [5, 2] and
C = [4, 3]. Rotate it by an angle 90 degree about point ꞌAꞌ in anticlockwise
direction. Give the co-ordinates of rotated triangle.
=
1
0
0
0
1
0
xr
yr
1
1
0
0
0
1
0
-xr
-yr
1
cosθ
sinθ
0
- sinθ
cosθ
0
0
0
1
=
1
0
m
0
1
n
0
0
1
1
0
4
0
1
1
0
0
1
[Tr] =
cos90
- sin90
0
sin90
cos90
0
0
0
1
[Rθ] =
0
-1
0
1
0
0
0
0
1
=
[Tr]-1
=
1
0
-4
0
1
-1
0
0
1
Xꞌ = [X].[T], [T] = [Tr] [Rθ] [Tr]-1
=
1
0
00
1 0
xr yr 1
1
0 0
0
1
0
-xr -yr 1
cosθ
sinθ
0
- sinθ
cosθ
0
0
0
1
96
v. GENERAL FIXED POINT SCALING:
A transformation sequence to produce scaling with respect to a selected
fixed point position (xf, yf) using a scaling function that can only scale
relative to the co-ordinate origin.
i. Translate object, so that the fixed point coincides with the co-ordinate
origin.
ii. Scale the object with respect to the co-ordinate origin.
iii. Use the inverse translation of step-1 to return the object to its original
position.
That is: T = [Tr][S][Tr]-1
=> T(xf, yf).S(Sx, Sy).T(-xf, -yf) = S(xf, yf, Sx, Sy) --- (2)
1 0 xf
0 1 yf
0 0 1
Sx 0 0
0 Sy 0
0 0 1
1 0 -xf
0 1 -yf
0 0 1
=
=
Sx 0 xf(1-Sx)
0 Sy yf(1-Sy)
0 0 1
--- (1)=
=
=> [T] =
1
0
4
0
1
1
0
0
1
0
-1
0
1
0
0
0
0
1
1
0
-4
0
1
-1
0
0
1
0
-1
5
5
1
0
-3
0
0
1
=
=> Xꞌ =
4
5
4
1
2
3
1
1
1
4
3
2
1
2
1
1
1
1
0
-1
5
5
1
0
-3
0
0
1
=
97
Example: Consider an object ABCD with given co-ordinates A(10, 10), B(60,
10), C(60, 60) and D(10, 60). It is desired to double the size of the object,
keeping in mind that point ‘A’ remains the same.
T = [Tr][S][Tr]-1
and Xꞌ = [X].[T]
vi. GENERAL SCALING DIRECTIONS:
Parameters ‘Sx’ and ‘Sy’ scale objects along the ‘x’ and ‘y’ directions. We
can scale an object in other directions by rotating the object to align the
desired scaling directions with the co-ordinate axes before applying the
scaling transformations.
Suppose we want to apply scaling factors with values by parameters ‘S1’
and ‘S2’ in the directions. To accomplish the scaling without changing the
orientation of the object, we first perform a rotation, so that the directions for
‘S1’ and ‘S2’ coincide with ‘x’ and ‘y’-axes respectively. Then, the scaling is
applied, followed by an opposite rotation to return points to their original
orientations.
1 0 0
0 1 0
10 10 1
2 0 0
0 2 0
0 0 1
1 0 -xf
0 1 -yf
-10 -10 1
T =
2 0 0
0 2 0
-10 -10 1
=
=
Xꞌ =
2 0 0
0 2 0
-10 -10 1
=
=
10 10 1
60 10 1
60 60 1
10 60 1
10 10 1
110 10 1
110 110 1
10 110 1
98
The composite matrix resulting from the product of these three
transformations is:
R-1
(θ).S(S1, S2).R(θ)
vii. CONCATENATION PROPERTIES:
Matrix multiplication is associative. For any 3 matrices A, B and C, the
matrix product A.B.C can be performed by first multiplying ‘A’ and ‘B’ or
by first multiplying ‘B’ and ‘C’: A.B.C = (A.B).C = A.(B.C). So, we can
evaluate matrix products using either a left-to-right or right-to-left
associative grouping.
On other hand, transformation products may not be cumulative. The
matrix product A.B is not equal to B.A, in general. This means that if we
want to translate and rotate an object.
viii. GENERAL COMPOSITE TRANSFORMAITON AND
COMPUTATIONAL EFFICIENCY:
A general 2D transformation, representing a combination of translations,
rotations and scaling can be expressed as:
S1cos2
θ + S2sin2
θ (S2 – S1)cosθsinθ
S1sin2
θ + S2cos2
θ(S2 – S1)cosθsinθ
00
0
0
1
=
xꞌ
yꞌ
1
rSxx
rSyx
0
rSxy
rSyy
0
trSx
trSy
1
x
y
1
= --- (1)
99
The 4 elements ‘rSij’ are the multiplicative rotation scaling terms
containing in the transformation that involve only rotation angles and scaling
factors. Elements trSx and trSy are the translational terms containing
combinations of translation distances pivot point and fixed point co-
ordinates and rotation angle and scaling parameters. If an object is to be
scaled and rotated about its centroid co-ordinates (xc, yc) and then translated,
the values for the elements of the composite transformation matrix are:
T(tx, ty).R(xc, yc, θ).S(xc, yc, Sx, Sy)
To explicit calculations for the transformed co-ordinates are:
xꞌ = x.rSxx + y.rSyy + trSx and yꞌ = x.rSyx + y.rSyy + trSy --- (3)
A general rigid body transformation matrix, involving only translations
and rotations can be expressed in the form:
Where the four elements ‘rij’ are the multiplicative rotation terms and
elements ‘trx’ and ‘try’ are the translational terms. A rigid body change in
coordinate position is also sometimes referred to as a rigid-motion
transformation. All angles and distances between co-ordinate positions are
unchanged by the transformation. The matrix 3 has the property that its
Sxcosθ – Sysinθ
SycosθSxsinθ
00
xc(1 - Sxcosθ) + ycSysinθ + tx
yc(1 – Sycosθ) - xcSxsinθ + ty
1
= --- (2)
rxx rxy
ryyryx
00
trx
try
1
--- (4)
100
upper left 2 by 2 sub-matrix is an orthogonal matrix. This means that if we
consider each row of the sub-matrix as a vector, then the 2 vectors (rxx, rxy)
and (ryx, ryy) from an orthogonal set of unit vectors.
Each vector has unit length: rxx
2
+ rxy
2
= ryx
2
+ ryy
2
= 1 --- (5) and the
vectors are perpendicular i.e.: rxxrxy + ryxryy = 0 --- (6) (their dot product is
0).
Therefore, if these unit vectors are transferred by the rotation sub-matrix
(rxx, rxy) is converted to a unit vector along the x-axis and (ryx, ryy) is
transformed into a unit vector along the y-axis of the co-ordinate system.
The rigid body transformation first rotates an object through an angle ‘θ’
about a pivot point (xr, yr).
The orthogonal unit vectors in the upper left 2 by 2 sub-matrix are (cosθ,
-sinθ) and (sinθ, cosθ) and unit vector (sinθ, cosθ) is converted by the
transformation matrix into the unit vector (0, 1) in the y-direction.
rxx
rxy
1
=
rxx rxy
ryyryx
00
0
0
1
1
0
1
--- (7)
ryx
ryy
1
=
rxx rxy
ryyryx
00
0
0
1
1
0
1
--- (8)
cosθ – sinθ
cosθsinθ
00
xr(1 - cosθ) + yrsinθ + tx
yr(1 – cosθ) – xrsinθ + ty
1
T(tx, ty).R(xr, yr, θ) = --- (9)
101
When the rotation angle is small the trigonometric functions can be
replaced with approximation values based on the first few terms of their
power series expansions. For small enough angles, ‘cosθ’ is approximately 1
and ‘sinθ’ has value close to the value of ‘θ’ in radians.
If we are rotating in small angular steps about the origin for instance, we
can set cosθ to 1 and reduce transformation calculations at each step to two
multiplications and two additions for each set of co-ordinates to be rotated.
xꞌ = x – ysinθ and yꞌ = xsinθ – y --- (11)
Where ‘sinθ’ is evaluated once for all steps, assuming the rotation angle
does not change.
AFFINE TRANSFORMATION:
A co-ordinate transformation of the form:
xꞌ = axxx + axyy + bx and yꞌ = ayxx + ayyy + by --- (1)
This is called a 2-dimensional affine transformation. Each of the transformed
co-ordinates ‘xꞌ’ and ‘yꞌ’ is a linear function of the original co-ordinates ‘x’ and ‘y’
and parameters ‘aij’ and ‘bk’ are constants determined by the transformation type.
Affine transformations have the general properties that parallel lines are
transformed into parallel lines and finites points map to finite points.
cosθ
sinθ
0
- sinθ
cosθ
0
0
0
1
cosθ
- sinθ
1
= --- (10)
1
0
1
102
Translation, Rotation, Scaling, Reflection and Shear are examples of two-
dimensional affine transformation. Any general two-dimensional affine
transformation can always be expressed as a composition of these 5
transformations.
Another affine transformation is the conversion of co-ordinates descriptions
from one reference system to another which can be described as a combination of
translation and rotation.
An affine transformation involving any rotation, translation and reflection
preserves angles and lengths as well as parallel lines. For these 3 transformations
the lengths and angle between two transformations, the lengths and angle between
two lines remains the same after the transformation.
103
CHAPTER -6
VIEWING PIPELINE:
A world co-ordinate area selected for display is called a window, which defines
what is to be viewed? An area on a display device to which a window is mapped is
called a viewport, which defines where it is to be display.
Windows and Viewports are rectangle in standard position, with the rectangle
parallel to the co-ordinate axes. In general, the mapping of a part of a world co-
ordinate scene to device co-ordinate is referred to a viewing transformation.
Sometimes, 2D viewing transformation is simply referred to as the window to
viewport transformation or windowing transformation.
In computer graphics, the term window originally referred to an area of picture.
i.e.: selected for viewing. Some graphics packages that provides window and
viewport operation, allow only standard rectangles, but a more general approach to
allow the rectangular window to have any orientation.
To obtain a particular orientation for the window, we can set up a 2D viewing
co-ordinate system in the world co-ordinate plane and define a window in the
viewing co-ordinate system.
The viewing co-ordinate reference frame is used to provide a method for setting
of arbitrary orientation for rectangular windows. Once the viewing reference frame
is established, we can transform descriptions in world co-ordinate to viewing co-
ordinate.
We then define a viewport in normalized co-ordinates (range from 0 to 1) and
map the viewing co-ordinate descriptions of the scene to normalize co-ordinates.
104
At the final step, all parts of the picture that lie outside the viewport are clipped
and the contains of the viewport are transformed to device co-ordinate.
Viewports are typically defined within the unit square (normalized co-
ordinates). This provides a means for separating the viewing and other
transformations from specific output device requirements. Different output devices
can be used by providing the appropriate device drivers.
When all co-ordinate transformations are completed, viewport clipping can be
performed in normalized co-ordinates. This allows us to reduce computations by
concatenating the various transformation matrices.
VIEW CO-ORDINATE REFERENCE FRAME:
The co-ordinate system provides the reference frame for specifying the world
co-ordinates window. First a viewing co-ordinate origin is selected at some world
position. i.e.: P0 = (x0, y0), then we need to establish the orientation, rotation of this
reference frame.
One way to do this is to specify a world vector ‘V’ that defines the viewing
‘yv’ direction. Vector ‘V’ is called the View-up vector. Given ‘V’, we can
calculate the components unit vector V = (Vx, Vy) and U = (ux, uy) for the viewing
Window
XWmaxXWmin
YWmax
YWmin
[WORLD CO-ORDINATE]
Viewport
XVmaxXVmin
YVmax
YVmin
[VIEWPORT CO-ORDINATE]
105
‘yv’ and ‘xv’ axes respectively. These unit vectors are used to form the 1st
and 2nd
rows of the rotation matrix ‘R’, that alive the viewing xvyv axes with the world.
In fig-1, translate the viewing origin to the world origin. The fig-2 rotate to a
line, the axes of the 2 systems we obtain the matrix for converting world co-
ordinate position to viewing co-ordinate as a two- step composite transformation.
i. 1st
, we rotate to align the 2 co-ordinate reference plane.
ii. Then we rotate to align the 2 co-ordinate reference plane.
The composite 2D transformation to convert world co-ordinates to viewing co-
ordinates is: Mwc, vc = R.T,
Where T= translation matrix, that takes the viewing origin point ‘P0’ to the
world origin and R = rotation matrix.
WINDOW TO VIEWPORT TRANSFORMATION:
Once the object description has been transferred to the viewing reference frame,
we choose the window extends in viewing co-ordinates and select the view code
limits is normalized co-ordinates. Object descriptions are transfer to normalized
device co-ordinates.
Yview
Xview
Xworld
Yworld Y X
X0
Y0 Yview
Xview
Xworld
Yworld
R
Fig - 1 Fig - 2
106
If a co-ordinate position is at the center of viewing window, it will display at the
center of the viewpoint. A point position (xw, yw) in window maps into position (xv,
yv) in associated viewport.
To maintain the same relative placement in the viewport as in the window, we
require that:
Solving these expression for the viewpoint position (xv, yv), we have
Where, ‘Sx’ and ‘Sy’ are scaling factors.
Window
XWmaxXWmin
YWmax
YWmin
[WORLD CO-ORDINATE]
Viewport
XVmaxXVmin
YVmax
YVmin
[VIEWPORT CO-ORDINATE]
(xw, yw)
XV – XVmin
XVmax – XVmin
XW – XWmin
XWmax – XWmin
=
YV – YVmin
YVmax – YVmin
YW – YWmin
YWmax – YWmin
=
--- (1)
XV = XVmin + (XW – XWmin)Sx
YV = YVmin + (YW – YWmin)Sy
--- (2)
107
CLIPPING:
It is described as the procedure that identifies the portion of a picture lie inside
the region and therefore it should be drawn or outside the specified and hence not
to be drawn.
The algorithms that perform the job of clipping are called clipping algorithms.
The different types of clipping are:
i. Point clipping
ii. Curve clipping
iii. Text clipping
iv. Exterior clipping
v. Line clipping
vi. Polygon clipping
In clipping it form an arbitrary view point in the world co-ordinate system. It is
a common experience that an object may be seen partially. The following 3 cases
may arise. That is:
Sx
XVmax – XVmin
XWmax – XWmin
=
Sy
YVmax – YVmin
YWmax – YWmin
=
--- (3)
108
Case-1: The object is completely outside the viewing area, describe by the
viewport or camera. This means that the object is not going to contribute in the
final image in the screen co-ordinate.
Case-2: The object may be seen partially that is some part of it may lie outside
the viewing area.
Case-3: The object may be completely seen within the viewing area.
The process of clipping eliminates the portion of the object, which does not
contribute to the final image. For the above cases, it can be clearly seen that, Case-
1, and Case-2 demand clipping while in Case-3, no clipping is necessary.
L1, L2: No Clipping: Case 3.
L3: Apply Clipping by Case 2.
L4: Apply Clipping by Case 1.
I. POINT CLIPPING:
Assume that the clip window is a rectangle in standard position, we
save a point P = (x, y) for display if the following inequalities are
satisfied. That is:
XWmin ≤ X ≤ XWmax and YWmin ≤ Y ≤ YWmax
Where the edges of the clip window (XWmin, XWmax, YWmin, YWmax)
can be either the world co-ordinates window boundaries or viewport
boundaries. If any one of these four inequalities is not satisfied, then the
point is clipped (not saved for display).
L1 L2
L3
L4
109
Point clipping is applied less often than line or polygon clipping;
some applications may require a point clipping.
II. CURVE CLIPPING:
This procedure will involve non-linear equations, however and this
requires more processing than for objects with linear boundaries. The
boundary rectangle for a circle or other curve object can be used first to
test for overlap with a rectangular clip window. If the bounding rectangle
for the object is completely inside the window, we save the object. If the
rectangle is determined to be completely outside the window, we discard
the object. In either case, there is no further computation necessary.
III. TEXT CLIPPING:
There are several techniques that can be used to provide text clipping
in a graphics package. The simplest method for processing character
strings relative to a window boundary is to use the all-or-none string
clipping strategy.
If all of the string is inside a clip window, we keep it, otherwise the
string is discarded. This procedure is implemented by considering a
bounding rectangle around the text pattern. The boundary positions of the
rectangle are then compared to the window boundaries and the string is
BEFORE
CLIPPING
AFTER
CLIPPING
110
rejected if there is any overlap. This method produces the fastest text
clipping.
An alternative to rejecting an entire character string that overlaps a
window boundary is to use the all-or-none-character clipping strategy.
Here we discard only those characters that are not completely inside the
window.
Here the boundary limits of individual characters are compared to the
window. Any character that either overlaps or is outside a window
boundary is clipped.
A final method for handling text clipping is to clip the components of
individual characters. If an individual character overlaps a clip window
boundary, we clip off the parts of the character that are outside the
window.
STRING2
STRING1
BEFORE CLIPPING
STRING2
AFTER CLIPPING
STRING3
STRING1
BEFORE CLIPPING
STRING4
STRING2
TRING3
RING1
AFTER CLIPPING
STRING4
STR
111
IV. EXTERIOR CLIPPING:
We have considered only procedures for clipping a picture to the
interior of a region by eliminating everything outside the clipping region.
What is saved by these procedures is inside the region. In some cases, we
want to do the reverse that is; we want to clip a picture to the exterior of a
specified region. The picture parts to be saved are those that are outside
the region. This is referred to as exterior clipping.
It is used in multiple window systems and also in other applications
that require overlapping pictures. The technique can also be used for
combining graphs, maps or schematics. For this we can use exterior
clipping to provide a space for an insert into a larger picture. Procedure
for clipping objects to the interior of concave polygon windows can also
make use of external clipping.
V. LINE CLIPPING:
Line is a series of infinite number of points where no two points have
space in between them. A variety of lines clipping algorithms are
available in computer graphics are:
a) Cohen-Sutherland Line Clipping Algorithm
b) Liang-Barsky Line Clipping Algorithm
c) Nicholl-Lee-Nicholl Line Clipping Algorithm
All line segments fall into one of the following clipping. That is:
i. Visible: Both endpoints of the line segments lie within the
window.
112
ii. Non-Visible: The line segment definitely lies outside the
window. This will occur, if the line segment from (x1, y1) to (x2,
y2) satisfies any one of the following 4 inequalities. i.e.:
a) x1, x2 > Xmax
b) x1, x2 < Xmin
c) y1, y2 > Ymax
d) y1, y2 < Ymin
iii. Partially Visible/Clipping Co-ordinate: A line is partially
visible when a part of it lies within the window.
a) COHEN-SUTHERLAND LINE CLIPPING ALGORITHM:
It provides an efficient procedure for determining the category of line
segments. It proceeds in 3 steps. That is:
Step 1: Assign a 4 bit code to each end point of the line segment and code is
determined by the same. The end point is one of the following 9 regions of
the plane.
The 4 bit code is assigned to UDRL Rule.
(UP DOWN RIGHT LEFT). Starting from
the left most bit, each bit of the code is said
to be true i.e.: 1 or false i.e.: 0, according to
the following scheme. That is:
i. Bit 1 is said to 1, if point ‘P’ lies above the window.
ii. Bit 2 is said to 1, if point ‘P’ lies below the window.
iii. Bit 3 is said to 1, if point ‘P’ lies right to the window.
iv. Bit 4 is said to 1, if point ‘P’ lies left to the window.
1001 1000 1010
0001 0000
(w)
0010
0101 0100 0110
UDRL RULE
113
v. Point 0000 code is lies inside the window.
Step 2: The line segment is visible if both endpoints codes are 0000 not
visible if the logical AND of the codes is not 0000 and a candidate for
clipping if the logical AND of the endpoint codes is 0000.
Step 3: If the line is a candidate for clipping, consider its 2 endpoints to be
‘P1’ and ‘P2’. If ‘P1’ is outside the window, then replace ‘P1’ with the
intersection of ‘P1P2’ and window edge.
LINE INTERSECTION AND CLIPPING:
Here, we determine the intersections points of the line in clipping
candidate with the boundaries of the window. Their intersection points then
subdivided the line segments into several smaller line segments which can
belong only to visible category or not visible category.
The segment in visible category will be the clipped line segment. The
intersection points are found by solving the equations representing the line
segments and the boundary line.
i. For left window edge, intersection point will be (xL, y) and y-value
can be calculated as: y = m(xL –x1) + y1, m ≠ ∞.
ii. For right window edge, intersection point will be (xR, y) and y-
value can be calculated as: y = m(xR –x1) + y1, m ≠ ∞.
iii.For top window edge, intersection point will be (x, yT) and x-value
can be calculated as: x = x1 + 1/m(yT –y1), m ≠ 0.
iv. For bottom window edge, intersection point will be (x, yB) and x-
value can be calculated as: x = x1 + 1/m(yB –y1), m ≠ 0.
114
Here, ‘xL’ is ‘x’-value of left edge of clipping window.
‘xR’ is ‘x’-value of right edge of clipping window.
‘yT’ is ‘y’-value of top edge of clipping window.
‘yB’ is ‘y’-value of bottom edge of clipping window.
Acceptable values of ‘x’ and ‘y’ are: xL ≤ x ≤ xR and yB ≤ y ≤ yT
Example: Given a clipping window A(20, 20), B(60, 20), C(60, 40) and
D(20, 40) using Cohen-Sutherland line clipping algorithm, find the visible
portion of line segment joining the points P(40, 80) and Q(120, 30).
Here, xR = 60, xL = 20, yT = 40, yB = 20.
(x1, y1) = (40, 80) and (x2, y2) = (120, 30)
m = y2 – y1/x2 – x1 = 30 – 80/120 – 40 = -50/80 = - 5/8
Intersection with window edges,
Left xL = 20,
Ymax
Ymin
Xmin XmaxP1
P2
P4
P3
P2 P3
ꞌ
P2
P2
ꞌ
P2
P1
ꞌ
P2
A B
D C
L2
L1
115
y = m(xL – x1) + y1
= -5/8(20 – 40) + 80 = 92
x = x1 + 1/m(yT - y1)
= 40 + (-8/5)(40 – 80) = 104
Since, ‘y’ is greater than yT. So, it is
rejected.
Left xR = 60,
y = m(xR – x1) + y1 = -5/8(60 – 40) + 80 = 67.5. Since, ‘y’ is greater than yT.
So, it is rejected.
Top yT = 40, x = 104. Since ‘x’ is greater than ‘yT’. So it is rejected.
Bottom yB = 20, x = 136. Since ‘x’ is greater than ‘yB’. So, it is rejected.
The given line has no intersection with clipping window; hence the line is
totally invisible.
b) LIANG-BARSKY LINE CLIPPING ALGORITHM:
Faster line clippers have been developed that are based on analysis of the
parametric equation of a line segment, which can write in the form:
x = x1 + u∆x and y = y1 + u∆y, where 0 ≤ u ≤ 1 --- (1)
Here, ∆x = x2 – x1 and ∆y = y2 – y1.
(20, 40) (60, 40)
(20, 20) (60, 20)
Q(120, 30)
P(40, 80)
(x, yT)
A B
D C
(xR, y)
116
Using this parametric equation, Cyrus and Beck developed an algorithm
which is generally more efficient that the Cohen-Sutherland algorithm. Later
Liang and Barsky independently devised an even faster parametric line
clipping algorithm.
Following the Liang-Barsky approach, we first write the point clipping
conditions in the parametric form is:
XWmin ≤ x1 + u∆x ≤ XWmax and YWmin ≤ y1 + u∆y ≤ YWmax --- (2)
Each of these four inequalities can be expressed as:
upk ≤ qk, where k = 1, 2, 3, 4 --- (3)
Where parameters ‘p’ and ‘q’ are defined as:
Any line that is parallel to one of the clipping boundaries has pk = 0
for the value of ‘k’ corresponding to that boundary (k = 1, 2, 3 and 4
correspond to the left, right, bottom and top boundaries respectively). If, for
that value of ‘k’, we also find qk < 0, then the line is completely outside the
boundary and can be eliminated from further consideration. If qk ≥ 0, then
line is inside the parallel clipping boundary.
When pk < 0, the infinite extension of the line proceeds from outside
to the inside of the infinite extension of this particular clipping boundary. If
p1 = - ∆x, q1 = x1 - XWmin
p2 = - ∆x, q2 = XWmax - x1
p3 = - ∆y, q3 = y1 - YWmin
p4 = - ∆y, q4 = YWmax - y1
--- (4)
117
pk > 0, the line proceeds from the inside to the outside. For a non-zero
value of ‘pk’, we can calculate the value of ‘u’ that corresponds to the point
where the infinitely extended line intersects the extension of boundary ‘k’
as:
u = qk/pk --- (5)
For each line, we can calculate values for parameters u1, u2 that define
that part of the line that lies within the rectangle. The value of ‘u1’ is
determined looking at the rectangle edges for which the line proceeds from
the outside to the inside (p < 0). For these edges, we calculate as:
rk = qk/pk --- (6)
The value of ‘u1’ is taken as the largest of the set consisting of ‘0’ and the
various values of ‘r’. The value of ‘u2’ is determined by examining the
boundaries for which the line proceeds from inside to outside (p > 0).
A value of ‘rk’ is calculated for each of these boundaries and the value of
‘u2’ is the minimum of the set consisting of ‘1’ and the calculated ‘r’ values.
If u1 > u2, the line is completely outside the clip window and it can be
rejected, otherwise the endpoints of the clipped line are calculated from the
two values of parameter ‘u’.
Line intersection parameters are initialized to the value u1 = 0 and u2 = 1.
For each clipping boundary, the appropriate values for ‘p’ and ‘q’ are
calculated and used by the function ‘clipTest’ to determine whether the line
can be rejected or whether the intersection parameters are to be adjusted.
118
When p < 0 the parameter ‘r’ is used to update ‘u1’ and when p > 0 the
parameter ‘r’ is used to update ‘u2’. If updating ‘u1’ or ‘u2’ results in u1 > u2,
we reject the line, otherwise we update the appropriate ‘u’ parameter only if
the new value results in a shortening of the line. When p = 0 and q < 0, we
can discard the line, since it is parallel to and outside of this boundary. If the
line has not been rejected after all four values of ‘p’ and ‘q’ has been tested,
the endpoints of the clipped line are determined from values of ‘u1’ and ‘u2’.
c) NICHOLL-LEE-NICHOLL LINE CLIPPING ALGORITHM:
This algorithm avoids multiple clipping of an individual line segment.
The extra intersection calculations are eliminated in NLN algorithm by
carrying out more regions testing before intersection positions are
calculated.
This algorithm performs fewer comparisons and divisions. The tradeoff is
that the NLN algorithm can only be applied to the two-dimensional clipping,
whereas, both the Liang-Barsky and Cohen-Sutherland methods are easily
extended to 3-dimensional scenes.
For a line with endpoints ‘p1’ and ‘p2’, we first determine the position of
point ‘p1’ for the nine possible regions relative to the clipping rectangle.
Only the 3 regions are shown, need to be considered. That is:
(a) p1 in a window
p1p1
p1
(b) p1 in edge region (c) p1 in corner region
119
If ‘p1’ lies in any one of the other six regions, we can move it to one of
the 3 regions, using a symmetric transformation. E.g.: The region directly
above the clip window can be transformed to the region left to the clip
window using a reflection about the line y = -x or we could use a 90 degree
counter clockwise rotation.
We determine the position of ‘p2’, relative to ‘p1’. To do this, we create
some regions in the plane, depending on the location of ‘p1’. Boundaries of
the new regions are half-infinite line segments that start at the position of
‘p1’ and pass through the window corners. If ‘p1’ is inside the clip window
and ‘p2’ is outside, we set up the four regions.
The intersection with the appropriate window
boundary is then carried out; depending on which
one of the four regions (L, T, R or B) contain ‘p2’.
Of course, if either ‘p1’ or ‘p2’ are inside the
clipping rectangle, we simply save the entire line.
If ‘p1’ is in the region to the left of the window, we set up the four
regions L, LT, LR and LB as shown as:
These 4 regions determine a unique boundary for
the line segment. For instance, if ‘p2’ is in region 1,
we clip the line at the left boundary and save the
line segment from this intersection point to ‘p2’.
But if ‘p2’ is in region ‘LT’, we save the line segment from the left
window boundary to the top boundary. If ‘p2’ is not in any of the four
regions L, LT, LR or LB, the entire line is clipped.
T
RL
B
P1
LT
LRL
LB
P1
L
L
120
We save the line segment from the left window boundary to the top
boundary. If ‘p2’ is not in any of the four regions L, LT, LR or LB, the entire
line is clipped.
For 3rd
case, when ‘p1’ is to the left and above the clip window, we use
the clipping regions shown as:
Here, we have the 2 possibilities shown, depending on the position of ‘p1’
relative to the top left corner of the window. If ‘p2’ is in one of the regions T,
L, TR, TB, LR or LB, this determines a unique clip window edge for the
intersection calculations; otherwise the entire line is rejected.
To determine the region in which ‘p2’ is located, we compare the slope of
the line to the slopes of the boundaries of the clip regions.
E.g.: if ‘p1’ is at left of the clipping rectangle, then ‘p2’ is in region LT, if
Or, yT – y1/xR – x1 < y2 – y1/x2 – x1 < yT – y1/xL – x1 --- (2)
And we clip the entire line if,
(yT – y1)(x2 – x1) < (xL – x1)(y2 – y1) --- (3)
TB
TRT
LB
P
T
L
Or
LR
TR
L
LB
P
T
L
slope p1pTR < slope p1p2 < slope p1pTL --- (1)
121
The co-ordinate difference and product calculations used in the slope
tests are saved and also used in the intersection calculations from the
parametric equations:
x = x1 + (x2 – x1)u and y = y1 + (y2 – y1)u --- (4)
An x-intersection position on the left window boundary is: x = xL, with:
u = (xL – x1)/(x2 – x1),
So that the y-intersection position is:
y = y1 + y2 – y1/x2 – x1(xL – x1) --- (5)
And an intersection position on the top boundary has y = yT and
u = (yT – y1)/(y2 – y1), with
x = x1 + x2 – x1/y2 – y1(yT – y1) --- (6)
VI. POLYGON CLIPPING:
Polygon is a surface enclosed by several lines. So, by considering the
polygon as a set of line we can divide the problem to line clipping and
hence the problem of polygon clipping is simplified, but it is to be noted
that each edge separately by using a line clipping algorithm, will
certainly not produce a truncated polygon as unconnected line segments.
Sutherland-Hodgeman algorithm is one of the standard methods used
for clipping arbitrary polygons with a rectangular clipping window, it
uses divide and conquer technique for clipping the polygon.
122
i. SUTHERLAND-HODGEMAN POLYGON CLIPPING:
Any polygon of any arbitrary shape can be described with the help of
some set of vertices associated with it.
When we try to clip the polygon, under consideration with any
rectangular window, then we observe that the co-ordinates of the polygon
vertices satisfies one of the 4 cases and further it is to be noted that this
procedure of clipping can be simplified by clipping the polygon edge-wise
and not the polygon as a whole. This decomposes the bigger problem into a
set of sub-problem which can be handling separately as per the cases.
The 4 possible cases are mentioned below. That is:
CASE 1: If both input vertices are inside the window boundary then only
2nd
vertex is added to output vertex list.
CASE 2: If first vertex is inside the window boundary and 2nd
vertex is
outside then only the intersection edge with boundary is added to the
output vertex.
CASE 3: If both input vertices are outside the window boundary then
nothing is added to the output list.
CASE 4: If the first vertex is outside the window and the 2nd
vertex is
inside the window then both the intersection point of the polygon edge
with window boundary, the 2nd
vertex is added to the output vertex list.
So, we can use the above rules to clip a polygon correctly. The polygon
must be tested against each edge of the clip rectangle, new edges must be
123
added and existing edges must be discarded, retained or derived. Actually,
this algorithm decompose the problem of polygon clipping against a clip
window into identical sub-problems, where a sub-problems is to clip all
polygon edges (pair of vertices) in succession against a single infinite clip
edge.
This output is a set of clip edges or pair of vertices that fall in the visible
site with respect to clip edge. These set of clip edges or considered as input
for the next sub-problems of clipping against the 2nd
window page.
This considering the output of the previous sub-problem as the input,
each of sub-problems are solved subsequently and finally yielding the
vertices that fall in or within the window boundary. These vertices
connected in order forms, the shape of the clip polygon.
Example: Clip the polygon p1, p2, p3, … , p8 in the given figure against
the rectangular clipping window using the Sutherland-Hodgeman Algorithm.
P2P1
P4
P3
P6
P5
P8 P7
P4
ꞌ
P5
ꞌ
P2
ꞌ
P7
ꞌ
P3
P6
After Clipping
P4
ꞌ
P5
ꞌ
P2
ꞌ
P7
ꞌ
124
After clipping, For P1P2, clipping not required as per CASE 3. For P2P3,
clipping becomes P2ꞌP3, which is added to output list as per CASE 4. For
P3P4, clipping becomes P3P4ꞌ, which is added to output list as per CASE 2.
For P5P6, clipping becomes P5ꞌP6, which is added to output list as per CASE
4. For P6P7, clipping becomes P6P7ꞌ, which is added to output list as per
CASE 2. For P7P8 and P8P1 clipping not required as per CASE 3.
ii. WEILER-ATHERTON POLYGON CLIPPING:
Here, the vertex processing procedures for window boundaries are
modified, so those concave polygons are displayed correctly. This clipping
procedure was developed as a method for identifying visible surfaces and so,
it can be applied with arbitrary – polygon clipping regions.
The basic idea in this algorithm is that instead of always proceeding
around the polygon edges as vertices are processed, we sometimes want to
follow the window boundaries, which path we follow depend on the polygon
processing direction (clockwise or counter clockwise) and whether the pair
of polygon vertices being processed represents an outside-to-inside pair or
an inside-to-outside.
For clockwise processing of polygon vertices, we use the following rules.
That is:
i. For an outside-to-inside pair of vertices, follow the polygon boundary.
ii. For an inside-to-outside pair of vertices, follow the window boundary
in a clockwise direction.
125
This considering the output of the previous sub-problem as the input,
each of sub-problems are solved subsequently and finally yielding the
vertices that fall in or within the window boundary. These vertices
connected in order forms, the shape of the clip polygon.
Here, the processing direction in the Weiler-Atherton algorithm and the
resulting clipped polygon is shown for rectangular clipping window.
An improvement on this algorithm is the Weiler algorithm, which applies
constructive solid geometry ideas to clip an arbitrary polygon against any
polygon clipping region.
V2
V6
V4
V3
V5
V1
V4
ꞌ
V1
ꞌ
V3
ꞌ
After Clipping
126
CHAPTER -7
REPRESENTATION OF POINT IN 3D:
A point in 3D is represented by 3 co-ordinates [x, y, z] by introducing the
homogeneous concept. A point in 3D i.e.: [x, y, z] is represented by 4D position
vector: [xꞌ yꞌ zꞌ h] = [x y z 1][T], where [T] is some transformation matrix.
Again the transformation from homogeneous co-ordinate to ordinates is given
by: [x* y* z* 1] = [xꞌ/h yꞌ/h zꞌ/h 1]. The generalized 4 x 4 transformation matrix
for 3D homogeneous co-ordinate is:
The 4 x 4 transformation matrix in equation – (1) can be partitioned into 4
separate sections as:
The upper-left 3 x 3 sub-matrix produces a linear transformation in the form of
scaling, shearing, reflection and rotation. The 1 x 3 lower-left sub-matrix produces
translation and upper-right 3 x 1 sub-matrix produces perspective transformation
and the final lower-right hand side 1 x 1 sub-matrix produces overall scaling.
g i j r
a b c p
d e f q
l m n s
--- (1)
4 x 4
[T] =
3 x 3 3 x 1
1 x 3 1 x 1
127
This transformation matrix [T] will be applied on homogeneous or co-ordinate
position vector and will yield shearing, local scaling, rotation, reflection,
translation, perspective and overall scaling.
3D TRANSFORMATION:
The different types of 3D transformations are:
i. 3D translation
ii. 3D rotation
iii. Rotation about an axis parallel to co-ordinate axis
iv. Rotation about an arbitrary axis in space
v. 3D scaling
vi. 3D reflection
vii. 3D shearing
i. 3D TRANSLATION:
In general 4 x 4 transformation matrix is:
The elements of the 4th
row of order 1 x 3 i.e.: l, m, n at the
translations in the x, y, and z direction. The matrix for translation is:
g i j r
a b c p
d e f q
l m n s
4 x 4
[T] =
128
The translation of homogeneous co-ordinates is obtained by writing:
The transformed physical co-ordinates are: x* = x + l, y* = y + m and
z* = z + n.
Example: Consider the effect of a translation in the xyz - direction by -2,
-4 and -6 respectively on the homogeneous co-ordinates position vectors
[1, 6, 4].
0 0 1 0
1 0 0 0
0 1 0 0
l m n 1
4 x 4
[T] =
0 0 1 0
1 0 0 0
0 1 0 0
l m n 1
= [(x + l) (y + m) (z + n) 1][xꞌ yꞌ zꞌ h] = [x y z 1]
0 0 1 0
1 0 0 0
0 1 0 0
l m n 1
=[T] =
0 0 1 0
1 0 0 0
0 1 0 0
-2 -4 -6 1
[X][T] = 1 60 4 1
0 0 1 0
1 0 0 0
0 1 0 0
-2 -4 -6 1
= 1 + (- 2) 6 – 4 4 – 6 1 -1 20 -2 1=0
129
ii. 3D ROTATION:
This rotation is examined about each of the co-ordinate axis. For
rotation about the x-axis, the x co-ordinate of the position vector doesn’t
change.
In effect, the rotation occurs in places perpendicular to x-axis.
Similarly the rotation about the y-axis and z-axis occurs in planes
perpendicular to the y-and z-axis respectively.
The transformation of the position vector in each of these planes it’s
governed by the general 2D rotation matrix. That is:
By considering the above matrix and again noting that, for rotation
about the x-axis, the x co-ordinate of the transformed position vector
doesn’t change. The 4 x 4 homogeneous co-ordinate transformation
vectors by angle ‘θ’ can be written as:
Rotation is assumed ‘+ ve’ in right hand side. i.e.: clockwise as one
looks outwards from the origin in the ‘+ ve’ direction along the rotation
cosθ sinθ
- sinθ cosθ
[T]
= (in 2D)
0 0
0
0
1
cosθ sinθ
- sinθ cosθ
[T]
=
--- (1)
0 0
0
0
1
0 0
0
0
0
01
130
axis. In similar manners, the transformation matrix for rotation of an
angle ‘Φ’ about y-axis is:
Again for rotation by an angle ‘Ψ’ about the z-axis is:
NOTE: The equation (1), (2) and (3) show that the determinant of
each transformation matrix as ‘+ 1’ as required for purse rotation. i.e.:
Determinant of pure rotation matrix is always +1.
Since 3D rotations are obtained using matrix multiplication they are
non-communicative. i.e.: the order of multiplication, affects the final
result. In order to show this, consider a rotation about x-axis followed by
an equal rotation about y-axis by using the equation (1) and (2) with θ =
Φ. Now, we have:
1
- sinΦ
sinΦ
sinΦ cosΦ
[T] = --- (2)
0 0
0
cosθ
0
1
0
00
0
0
0cosΦ
1
- sinΨ
sinΨ
sinΨ
cosΨ
[T] = --- (3)
0 0
0
cosθ
0
1
0
0
0 0
0
0cosΨ
131
On the other hand, the reverse operation i.e.: rotation about y-axis
followed, by equal rotation about the x-axis with θ = Φ yields.
Example: A rectangular parallelepiped is given having length on x-axis, y-
axis and z-axis as 3, 2, 1 respectively. Perform a rotation by an angle θ = -90
degree about x-axis and perform a rotation by and angle Φ = 90 degree about
y-axis.
cosθ sinθ
- sinθ cosθ
[T]
=
0 0
0
0
1
0 0
0
0
0
01
1
-
sinθ
sinθ cosθ
0 0
0
0
1
0
00
0
0
0cosθ
cosθsin2
θ
- sinθ
cosθsinθ
=> [T] = --- (4)
-
sinθ
cosθsinθ cos2
θ
0 0
0
0
1
0
0
0cosθ
cosθ sinθ
- sinθ cosθ
0 0
0
0
1
0 0
0
0
0
01
1
-
sinθ
sinθ cosθ
0 0
0
0
1
0
00
0
0
0cosθ
[T] =
cosθ
sin2
θ
sinθ
- cosθsinθ
=> [T] = --- (5)
sinθ
- cosθsinθ cos2
θ
0 0
0
0
1
0
0
0cosθ
132
The position vector matrix of rectangular parallelepiped is:
The rotation matrix about x-axis by an angle θ = -90o
:
A B
CD
E F
GH
1
2
3 X
Y
Z
0 0 1 1
3 0 1 1
3 2 1 1
0 2 1 1
0 0 0 1
3 0 0 1
3 2 0 1
0 2 0 1
[X] =
cos(-90) sin(-90)
90)
- sin(-90) cos(-90)
[T] =
0 0
0
0
1
0 0
0
0
0
01
0 -1
1 0
=
0 0
0
0
1
0 0
0
0
0
01
[X*] = [X] [T] =
0 0 1 1
3 0 1 1
3 2 1 1
0 2 1 1
0 0 0 1
3 0 0 1
3 2 0 1
0 2 0 1
0 -1
1 0
=
0 0
0
0
1
0 0
0
0
0
01
0 1 0 1
3 1 0 1
3 1 -2 1
0 1 -2 1
0 0 0 1
3 0 0 1
3 0 -2 1
0 0 -2 1
133
The rotation matrix about y-axis by an angle Φ = 90o
:
iii. ROTATION ABOUT AN AXIS PARALLEL TO CO-ORDINATE
AXIS:
The transformation matrices given by the equation 1, 2, 3 are the
rotation transformation matrices about x, y and z co-ordinate axes
respectively. Our aim is to rotate the object about axes other than these
standard axes. Here, the special case of an axis that is parallel to one of
the x, y or z co-ordinate axis is considered.
Here, the body with local axis system xꞌyꞌzꞌ parallel to the fixed global
axis system xyz.
1
-
sin90
sin90 cos90
0 0
0
0
1
0
00
0
0
0cos90
[T] = =
1
-1
0 0
0 0
0
0
1
0
00
1
0
00
[X*] = [X] [T] =
0 0 1 1
3 0 1 1
3 2 1 1
0 2 1 1
0 0 0 1
3 0 0 1
3 2 0 1
0 2 0 1
0
-1
1
0
=
0 0
0
0
1
0
0
0
0
0
0
1
01 0 1
-31 0 1
-31 2 1
01 2 1
00 0 1
-30 0 1
-30 2 1
00 2 1
134
Rotation of the body about any of the individual xꞌ, yꞌ or zꞌ local axis
is accomplished using the following 3 steps. That is:
i. Translate the body until the local axis is coincident with the co-
ordinate axis in the same direction.
ii. Rotate about the specified axis is given
iii. Translate the body back to its original position.
Mathematically, it can be shown as:
[X*] = [X] [T], where [T] = [Tr] [Rx] [Tr]-1
Here, [T] = compound transformation matrix, [Tr] = Translation
matrix
[Rx] = Rotation matrix about x-axis, [Tr]-1
= Inverse translation matrix
[X] = Untransformed/Original co-ordinate matrix
[X*] = It represents the transformed co-ordinate of the body.
Z
Y
H
G
F
D
C
B
A
Xꞌ
XZꞌ
Yꞌ
Z
Y
H G
D
C
BA
Xꞌ
X
F
135
Example: Perform the rotation of block about x+
- axis by an angle θ =
30o
), which is local to the block. The co-ordinate of the blocks is given
relative to the global xyz-axis system.
The position vector of the cube relative to the x, y, z axis system is given,
i.e.:
Let the local xꞌ-axis pass through centroid of the block. The co-ordinate
of the centroid of the block is: [xc yc zc 1].
So, [xc yc zc 1] = [3/2 3/2 3/2 1].
Rotation about local axis is accomplished by: [x*] = [x] [Tr] [Rx] [Tr]-1
Where,
Z
Y
H G
F
D
C
B
A
Xꞌ
X
Zꞌ
Yꞌ1 1 2 1
2 1 2 1
2 2 2 1
1 2 2 1
1 1 1 1
2 1 1 1
2 2 1 1
1 2 1 1
[X] =
1 0 0 0
0 1 0 0
0 -yc -zc 1
0 0 1 0
1 0 0 0
0 1 0 0
0 -3/2 -3/2 1
0 0 1 0
[Tr] = =
136
The value of composite transformation matrix [T= [Tr] [Rx] [Tr]-1
After putting the values of yc, zc and θ = 30o
, we get
1 0
.866
1
0
0
0
0
0
-.5 .866
.5
-.549.951
0
0
1 0
cosθ
1
0
0
0
0
0
0
0
-sinθ cosθ
sinθ
00
0
0
[Rx] = =
1 0
.866
1
0
0
0
0
0
-.5 .866
.5
00
0
0
1 0
cosθ
1
0
0
0
0
0
- sinθ cosθ
sinθ
zc(1 – cosθ) -
ycsinθ
yc(1 – cosθ)
+ zcsinθ
0
0
=
1 1 2 1
2 1 2 1
2 2 2 1
1 2 2 1
1 1 1 1
2 1 1 1
2 2 1 1
1 2 1 1
[X*
] = [X][T] =
1 0
.866
1
0
0
0
0
0
-.5 .866
.5
-.549.951
0
0
137
iv. ROTATION ABOUT AN ARBITRARY AXIS IN SPACE:
The rotation about an arbitrary axis in space occurs in robotics
animation simulating. This is accomplished using the procedure of
translations and simple rotation about a co-ordinate axis. The procedure
idea is to make the arbitrary rotation axis coincident with one of the co-
ordinate axes.
Let’s assume that an arbitrary axis is space passing through the point
(x0, y0, z0) with direction cosine (Cx, Cy, Cz). Rotation about this axis by
some angle ꞌdꞌ is accomplished using the following procedure.
i. Translate the body so that the point (x0, y0, z0) is reached at the
origin of co-ordinate system.
ii. Do approximate rotations to make the axis of rotation
coincident with the z-axis (the selection of z-axis is arbitrary,
we can choose any axis).
iii. Rotate the body by the angle ꞌdꞌ about z-axis.
1 .817 1.683 1
2 .817 1.683 1
2 1.683 2.183 1
1 1.683 2.183 1
1 1.317 .817 1
2 1.317 .817 1
2 2.183 1.317 1
1 2.813 1.317 1
=
138
iv. Do the inverse of the combined rotation transformation.
v. Now, perform the inverse of the translation.
vi. Our aim is to make the arbitrary rotation axis coincident with
the z-axis. For this first rotate about the x-axis and then about
the y-axis. To find the value of rotation angle ꞌαꞌ about x-axis
used to place the arbitrary axis in xz-plane, now first project the
unit vector along the axis onto the yz-plane.
The projected components of the ‘y’ and ‘z’ values are ‘Cy’ and ‘Cz’
and the direction cosine of the unit vector along the arbitrary axis. From
the above figure, we note that:
Cosα = Cz/d and Sinα = Cy/d --- (2)
After completion of rotation about the x-axis into the xz-plane, the z-
component of the unit vector ꞌdꞌ and the x-component is ‘Cx’ and the
direction cosine in the x-direction is shown in fig-2.
[Rotation about x-axis]
α
d
x
z
yCx
Cz
Cy
[Rotation about y-axis]
d
x
z
y
Cx
β
d
P(Cx, 0, d)
0
d = Cy
2
+ Cz
2
--- (1)
139
We know, the length of a unit vector is 1. The rotation angle ‘β’ about
the y-axis required to make the arbitrary axis coincident with z-axis is:
Cosβ = d and Sinβ = Cx --- (3)
Now, the total transformation or composite transformation is:
[T] = [Tr] [Rx] [Ry] [Rδ] [Ry] -1
[Rx] -1
[Tr]-1
--- (4)
[Tr] = Translation matrix
[Rx] = Rotation matrix about x-axis
[Ry] = Rotation matrix about y-axis
1 0
cosθ
1
0
0
0
0
0
0
0
-sinθ cosθ
sinθ
00
0
0
[Rx] = --- (6)
1 0
Cx/d
1
0
0
0
0
0
-Cy/d Cz/d
Cy/d
00
0
0
1 0 0 0
0 1 0 0
-x0 -y0 -z0 1
0 0 1 0
[Tr] = --- (5)
1
- sin(-
β)
sin(-β) cos(-β)
0 0
0
0
1
0
00
0
0
0cos(-β)
[Ry] =
--- (7)1
Cx
0 d
0 0
0
0
1
0
00
-Cx
0
0d
140
[Rδ] = Rotation about the arbitrary axis given by z-axis is:
Now, we take a 2nd
point on the axis i.e.: (x1, y1, z1) to find the
direction cosine is:
Example: Derive the transformation matrix for rotating any object about
an axis passing through the origin and point (10, 0, 10).
Steps to be followed to perform the above task are:
i. Translate, so that local axis is coincident with the co-ordinate axis
ii. Rotate about specified axis i.e.: by 30 degree anticlockwise.
iii. Translate the transformed body back to its original position.
In general, making an arbitrary axis pass through origin, coincident with
one of the axis, required two successive rotations about other two co-
ordinate axis. According to the example, axis passes through the origin
and a point P[10, 0, 10]. Hence, the direction cosines of rotation axis will
be:
1
- sinδ
sinδ
sinδ
cosδ
[Rδ] = --- (8)
0 0
0
cosθ
0
1
0
0
0 0
0
0cosδ
[Cx Cy Cz] =
[(x1 – x0)2
+ (y1 – y0)2
+ (z1 – z0)2
]1/2
[(x1 – x0)(y1 – y0)(z1 – z0)]
--- (9)
[Cx Cy Cz] =
[(x1 – x0)2
+ (y1 – y0)2
+ (z1 – z0)2
]1/2
[(x1 – x0)(y1 – y0)(z1 – z0)]
141
x0 = y0 = z0 = 0, x1 = 10, y1 = 0, z1 = 10, then,
[Cx Cy Cz] = [(10) (0) (10)] / [(10)2
+ (10)2
+ (10)2
]1/2
= [(10) (0) (10)] / √200
= [10/√200 0/√200 10/√200]
= [10/14.142 0 10/14.142]
Hence, [Cx Cy Cz] = [0.707 0 0.707]
We rotate the arbitrary axis by angle ‘α’ about x-axis and about y-axis by
angle ‘β’ in order to make it coincident with the z-axis.
cosα = Cz/d = 0.707/0.706 = 1.001, sinα = Cy/d = 0
cosβ = d = 0.706, sinβ = Cx = 0.707
To compute transformation is:
[T] = [Rx] [Ry] [Rθ] [Ry] -1
[Rx] -1
Where [T] = Transformation matrix
[Rx] = Rotation matrix about x-axis by angle ‘α’
[Ry] = Rotation matrix about y-axis by angle ‘β’
[Rθ] = Rotation about z-axis by angle ‘30o
’
[Ry] -1
= Inverse matrix of [Ry]
[Rx] -1
= Inverse matrix of [Rx]
d = Cy
2
+ Cz
2
= 0 + .499 = 0.706
142
Hence, the required transformation matrix is:
v. 3D SCALING:
The diagonal terms of the general 4 x 4 transformation matrix produce
local and overall scaling. To understand this, consider the transformation
matrix given below:
0.930
- 0.353
0.93
- 0.068 0.353
00
[T] =
- 0.353 0.871
0.431
0
0
0
1
00.355
1
-
sin30
sin30
cos30cos30
0 0
0
0
1
0
0
0 0
0
0cos30
1 0
cosα
1
0
0
0
0
0
0
0
-sinα cosα
sinα
00
0
0
[T] =
1
- sinβ
sinβ cosβ
0 0
0
0
1
0
00
0
0
0cosβ
1
0
0
c
o
s
3
0
.866
0 0
0
0
1
0
0
0 0
0
0.866
1 0
1.001
1
0
0
0
0
0
0
0
0 1.001
0
00
0
0
=
1
- 0.707
0.707 0.706
0 0
0
0
1
0
00
0
0
00.706
0.930
- 0.353
0.93
- 0.068 0.353
00
=
- 0.353 0.871
0.431
0
0
0
1
00.355
143
[x* y* z* 1] = [X][T] = [x y z 1][T]
=> [x* y* z* 1] = [ax ey jz 1] or
[Sxx Syy Szz 1]
The overall scaling is obtained by using the 4th
diagonal element. That
is: the element of 1 x 1, in general transformation matrix shown by the
equation:
The ordinary or physical co-ordinates are:
[x* y* z* 1] = [xꞌ/S yꞌ/S zꞌ/S 1].
0 0 j 0
a 0 0 0
0 e 0 0
0 0 0 1
[T] =
0 0 Sz 0
Sx 0 0 0
0 Sy 0 0
0 0 0 1
or
g i j r
a b c p
d e f q
l m n s
4 x 4
[T] =
0 0 0 0
1 0 0 0
0 1 0 0
0 0 0 s
= [xꞌ yꞌ zꞌ s][x* y* z* 1] = [x y z 1]
144
If S<1, a uniform expansion of the position vector occurs and if S>1, a
uniform compression of the position vector occurs.
Example 1: Given a rectangular parallelepiped which is unit distance on
z-axis, 2 distances on x-axis and 3 distances on y-axis. What is the effect
of scaling factor Sx = 1/2, Sy = 1/3 and Sz = 1?
x
y
z
A B
CD
E F
GH
0 0 1 1
3
0 1 1
3
2
1 1
0
2
1 1
0 0 0 1
3
0 0 1
3
2
0 1
0
2
0 1
[X] = [T] =
1/3 0
0 1
0 0
0
0
1
0 0
0
0
0
01/2
0 0 1 1
1
0 1 1
1
1
1 1
0
1
1 1
0 0 0 1
1
0 0 1
1
1
0 1
0
1
0 1
=
1/3 0
0 1
0 0
0
0
1
0 0
0
0
0
01/2
[X*] = [X] [T] =
0 0 1 1
3
0 1 1
3
2
1 1
0
2
1 1
0 0 0 1
3
0 0 1
3
2
0 1
0
2
0 1
145
Example 2: Perform the uniform scaling on the unit cube by a factor of 2
and also draw the figure.
The transformation matrix [T] for the
uniform (overall) scaling is:
Here, the homogeneous co-ordinate factor h = .5, for each of the
transformed position vector, ‘q0’ obtain the ordinary or physical co-
ordinates each position vector must be divided by ‘h’, therefore the result
is:
0 0 1 1
1
0 1 1
1
1
1 1
0
1
1 1
0 0 0 1
1
0 0 1
1
1
0 1
0
1
0 1
[X] = [T] =
1 0
0 1
0 0
0
0
1/2
0 0
0
0
0
01
0 0 1 .5
1
0 1 .5
1
1
1 .5
0
1
1 .5
0 0 0 .5
1
0 0 .5
1
1
0 .5
0
1
0 .5
=
[X*] = [X] [T] =
1 0
0 1
0 0
0
0
1/2
0 0
0
0
0
01
0 0 1 1
1
0 1 1
1
1
1 1
0
1
1 1
0 0 0 1
1
0 0 1
1
1
0 1
0
1
0 1
146
vi. 3D REFLECTION:
Some orientations of a 3D object can’t be obtained using pure
rotation. They require reflections. In 3D, reflections occur through a
plane, but in 2D, reflection occurs through an axis.
In 3D, the value of the determinant for pure reflection matrix is
always equal to -1. In a reflection through the xy-plane, only the z-co-
ordinate values of the object’s position vectors change. i.e.: they are
reversed in sign, so the transformation matrix for reflection through the
xy-plane is:
[X*] =
0 0 2 1
2
0 2 1
2
2
2 1
0
2
2 1
0 0 0 1
2
0 0 1
2
2
0 1
0
2
0 1
A* B*
C*D*
E* F*
G*H*
2
2
2 X
Y
Z
[T]xy =
1 0
0 -1
0 0
0
cosθ
0
1
0 0
0
0
0
01
147
The transformation matrix for reflection through yz-plane is:
The transformation matrix for reflection through xz-plane is:
Example: Perform reflection of unit cube about the xy-plane.
The matrix for position vector of unit cube is:
[T]yz =
1 0
0 1
0 0
0
0
1
0 0
0
0
0
0-1
[X] =
0 0 1 1
1
0 1 1
1
1
1 1
0
1
1 1
0 0 0 1
1
0 0 1
1
1
0 1
0
1
0 1
A B
CD
E F
GH
X
Y
Z
[T]xz =
-1 0
0 1
0 0
0
0
1
0 0
0
0
0
01
148
The transformation matrix for reflection about xy-plane is given by:
The value of transformed vector i.e.: after reflection about xy-plane is:
vii. 3D SHEARING:
The off diagonal terms in the upper-left 3 x 3 sub-matrix of the
general 4 x 4 transformation matrix produce shear in 3D.
[T] =
1 0
0 -1
0 0
0
0
1
0 0
0
0
0
01
0 0 -1 1
1
0 -1 1
1
1
-1 1
0
1
-1 1
0 0 0 1
1
0 0 1
1
1
0 1
0
1
0 1
=
[X*] = [X] [T] =
1 0
0 -1
0 0
0
0
1
0 0
0
0
0
01
0 0 1 1
1
0 1 1
1
1
1 1
0
1
1 1
0 0 0 1
1
0 0 1
1
1
0 1
0
1
0 1
g i 1 0
1 b c 0
d 1 f 0
0 0 0 1
= [x + yd + gz bx + y + iz cx + fy + z 1]
[x* y* z* 1] = [x y z 1]
149
Example: What is the effect of sheared transformation on the unit cube,
where the value of shear transformation matrix is as follows:
The position vector for unit cube and transformed matrix is given as
follows:
Applying the effect of the sheared transformation matrix on [X], it
give X*. i.e.: [X*] = [X][T].
Here, one thing to be noted is that
origin is unaffected by the sheared
transformation.
0 0 1 1
1
0 1 1
1
1
1 1
0
1
1 1
0 0 0 1
1
0 0 1
1
1
0 1
0
1
0 1
[X] = [T] =
1 .7
1 1
0 0
0
0
1
-.85 .25
-.75
.5
0
01
.5 1 1 1
1.15
.15 1.25 1
2
1.5
1.95 1
-.25
.75
1.7 1
0 0 0 1
.15
-.85 .25 1
1
1
.95 1
-.75
.25
.7 1
=
150
CHAPTER - 8
3D VIEWING:
The 3D viewing process is inherently more complex than 2D viewing process.
The extra complexity of 3D viewing is caused in part by the added dimension and
in part by the fact that display devices are only 2D.
In 3D viewing, we specify a view volume in the world, a projection onto a
projection plane and a viewpoint on a view surface. Conceptually, objects in 3D
world are clipped against the 3D view volume and are then projected.
The contains of the projection of the view volume onto the projection plane
called the window, are then transformed into the viewport for display. The
complete viewing process consists of the following sequence of transformation.
i. Object Transformation:
Transformation applied to the object prior to viewing. These
transformations improved instance information, scaling, translations and
rotations.
ii. Image Transformation:
2D Transformations applied to the 2D image in normalized device
space to produce the final view.
iii. Viewing Transformation:
Transformations applied to the desired object produce a 2D view of
the object, describe in normalized device co-ordinate.
151
PROJECTION:
The important terms related to projections are:
i. CENTER OF PROJECTIONS: The point form where projection is taken,
it can either be light source or eye position is called center of projections.
ii. PROJECTION PLANE: The plane on which projection of the object is
formed is called projection plane.
iii. PROJECTORS: Lines emerging from center of projection and heating the
projection plane after passing through a point in the object to be
projected. Mainly these projectors are responsible for obtaining
projection of an object.
GEOMETRIC PROJECTION:
The plane Geometric Projection of the objects is formed by the intersection of
lines called Projectors on a plane called Projection Plane. Projectors are lines
Plane Geometric Projection
Perspective Projection
Two Point
Three Point
Single Point
Parallel Projection
Orthographic
Cavalier
Oblique
CabinetDi-metric
Isometric
Trimetric
Axanometric
152
from an arbitrary point called the Center of Projection through each point in an
object. Plane Geometric Projection is of 2 types. That is: Parallel and Perspective
Projection.
i. PARALLEL PROJECTION:
If the center of projection is at infinity, all the projectors are parallel
and the result is called Parallel Projection. It is of 3 types.
a. ORTHOGRAPHIC PROJECTION:
It is a part of parallel projection in which the center of projection lies at
infinity. In this projection, the projectors are perpendicular to the projection
plane and true size and shape of a single plane face, of an object is obtained.
It is commonly used for engineering drawing. It is the projection on one of
the co-ordinate planes. i.e.: x = 0, y = 0 or z = 0.
The matrices for projection onto x = 0 plane, y = 0 plane and z = 0 plane
are:
To visually and partially reconstruct the shape of an object, a single
orthographic projection does not provide sufficient information. There are
multiple orthographic projections which are necessary. The front, right and
[Px] =
1 0
0 1
0 0
0
0
1
0 0
0
0
0
00
[Py] =
0 0
0 1
0 0
0
0
1
0 0
0
0
0
01
[Pz] =
1 0
0 0
0 0
0
0
1
0 0
0
0
0
01
153
top views are obtained by projection onto the z = 0, x = 0, y = 0 planes from
centers of projection infinity on the +z, +x, +y axis.
The rear, left and bottom view projections are obtained by projection onto
the z = 0, x = 0 and y = 0 planes from center of projection at infinity on the –
z, -x, -y axes.
The front and side view are known as front and side elevation and top
view is known as plane view. All the 6 views can be obtained by
combinations of reflection translation and rotation followed by projection
onto the z = 0 plane from a center of projection at infinity on the +z-axis.
The standard orthographic views don’t show the correct or true shape of
these planes.
It is possible to combine all the 6 views by reflection, rotation and
translation followed by projection onto the z = 0 plane from the center of
projection at infinity on the z-axis.
b. AXANOMETRIC PROJECTION:
It is used to overcome the limitation of single orthographic projection
which is unable to illustrate the general 3D shape of an object. The
construction of an axonometric projection is done by using rotation and
translation to manipulate the object such that at least 3 adjacent faces are
shown.
The result is then projected at infinity onto one of the co-ordinate plane (z
= 0 plane) from the center of projection. An axonometric projection shows
its true shape only when a face is parallel to the plane of projection. The
154
foreshortening factor is the ratio of projected length of a line to its true
length.
Axonometric Projection is of 3 types. That is:
i) Trimetric ii) Di-metric iii) Isometric
i. TRIMETRIC PROJECTION:
It is formed by arbitrary rotations in arbitrary order about any or all
of the co-ordinate axes, followed by parallel projection onto the z-
plane.
For each projected principal axis (x, y and z), the foreshortening
ratios are disjoint. For any specific trimetric projection, the
foreshortening ratios are obtained by applying the concatenated
transformation matrix to unit vectors along the principal axes.
[U] = Unit vectors matrix along the untransformed x, y, and z axis
respectively.
[T] = Concatenated trimetric projection matrix.
The forecasting or foreshortening factors are:
[U][T] = 1 0
0 1
1
1
0 0
0
0
11
0 [T] = 0
0
1
1
0
Xy*
Xz*
Xx*
1Xx*
Yy*
Yz*
Xx*
Yx*
155
ii. DI-METRIC PROJECTION:
It is a trimetric projection with two foreshortening factors equal
and third arbitrary. It is constructed by a rotation about a y-axis
through an angle ‘Φ’ followed by a rotation about the x-axis through
an angle ‘θ’ and projection at infinity onto the z = 0 plane.
Considering rotations with ‘Φ’ and ‘θ’, the mathematical
interpretation is: [T] = [Ry] [Rx] [Pz].
The unit vectors on x, y and z principal axis transform to:
1
- sinΦ
sinΦ
sinΦ cosΦ
[T] =
0 0
0
0
1
0
00
0
0
0cosΦ
cosθ sinθ
- sinθ cosθ
0 0
0
0
1
0 0
0
0
0
01
1 0
0 0
0 0
0
0
1
0 0
0
0
0
01
cosθ
- cosΦsinθ
cosΦsinθ
sinΦ
sinΦsinθ
=> [T] =
0 0
0
cosθ
0
1
0
00
0
0
0cosΦ
fx = (Xx*)2
+ (Yx*)2
)2
fy = (Xy*)2
+ (Yy*)2
)2
fz = (Xz*)2
+ (Yz*)2
)2
156
The forecasting or foreshortening factors are:
iii. ISOMETRIC PROJECTION:
The problem associated with di-metric projection is eliminated in
isometric projection. The problem is that a di-metric projection allows
two of the three transformed principal axes to be measured with the
same scale factor.
Measurements along the 3rd
transformed principal axis require a
different scale factor. If accurate scaling of the dimensions of the
projected object is required, it leads to error.
The solution to the above problem is isometric projection is that all
3 forecasting factors are kept equal. The projection plane normal
[U*] = [U][T] = 1 0
0 1
1
1
0 0
0
0
11
0
cosθ
- cosΦsinθ
cosΦsinθ
sinΦ
sinΦsinθ
0 0
0
0
1
0
00
0
0
0cosΦ
cosθ
- cosΦsinθ
cosΦsinθ
sinΦ
sinΦsinθ
=
1
cosθ
1
0
00
0
1cosΦ
fx = cos2
Φ + sin2
Φsin2
θ
)2fy = cos2
θ = cosθ
)2
fz = sin2
Φ + cos2
Φsin2
θ
157
makes equal angles with each principal axis. If the projection plane
normal is (dx, dy, dz), then we require that: |dx| = |dy| = |dz|.
The angle that the projected x-axis makes with the horizontal is
important in manual construction of isometric projections.
Transforming the unit vector along the x-axis using the isometric
projection matrix yields:
The angle between projected z-axis and horizontal is:
Since, sinΦ = cosΦ, for θ = 45o
,
A plastic right triangle with included angles of 30o
and 60o
is
commonly used tool for manually constructing isometric projection.
c. OBLIQUE PROJECTION:
It is the part of parallel projection formed by parallel projectors from a
center of projection at infinity that intersect the plane of projection at an
oblique angle.
tanα Yx
*
/Xx
*
= sinΦsinθ/cosΦ = sinθ
α = tan-1
( sin35.26439) = 30o
[U*] = [U][T] = 0 0 11
0
cosθ
- cosΦsinθ
cosΦsinθ
sinΦ
sinΦsinθ
0 0
0
cosθ
0
1
0
00
0
0
0cosΦ
sinθsinΦ= 0cosΦ
158
An oblique projection of these faces is equivalent to an orthographic
front view. Faces are not parallel to the plane of projection are distorted. It is
of 2 types. i.e.: Cavalier Projection and Cabinet Projection.
The Cavalier Projection is obtained when the angle between oblique
projectors and the plane of projection is 45o
and the foreshortening factors of
all the three principal directions are equal.
The Cabinet Projection is used to correct the distortion that is produced
by Cavalier Projection. An oblique projection for which the foreshortening
factor for edge perpendicular to the plane of projection is one-half is called a
Cabinet Projection.
The projection perpendicular to z-axis, the 3 x 3 transformation matrix
using translation is:
The translation is equivalent to shearing in ‘x’ and ‘y’ directions. The
translation matrix is:
1 0
-b 0
0 0
0
0
1
0 0
0
- a
a
0
01
[T2] =
[T1] = 1 0
-b 1
0 0
0
1
-a
159
Now, projection onto the z = 0 plane gives:
cosα = a/f => a = fcosα
cosβ = b/f => b = fsinβ
cotβ = f/1 => β = cos-1
(f)
f = projected length of z-axis unit vector also called as foreshortening
factor.
α = angle between the horizontal and projected z-axis.
The transformation matrix for oblique projection is:
If f = 0, b = 90o
, it is orthographic projection. If f = 1, β = 45o
, the edges
perpendicular to the projection plane are not foreshortened and this is the
condition for a cavalier projection.
‘α’ is still a free parameter. Generally used value of ‘α’ are 30o
and 45o
and (180 – α) are also acceptable.
1
b
α
a
P[0 0 1]
R
Q
f
-b
-
a
a
b
x
0
y
β
β
z
f
1 0
- fsinα 0
0 0
0
0
1
0 0
0
-fcosα
0
01
[T] =
1 0
-b 0
0 0
0
0
1
0 0
0
- a
a
0
01
[T] =
160
ii. PERSPECTIVE PROJECTION:
If the center of projection is at a finite distance in 3D-space, the result
is a perspective projection. The general 4 x 4 transformation matrix is:
It is of 3 types. i.e.: a) single-point b) two-point c) three-point.
a. SINGLE-POINT PERSPECTIVE PROJECTION:
There are 3 types of single point perspective transformation are:
i. When projectors are located at x-axis, it is given by:
Converting into the ordinary co-ordinate, i.e.:
[x* y* z* 1] = [x/(px + 1) y/(px + 1) z/(px + 1) 1]
It has center of projection at [-1/p 0 0 1] and a vanishing point located
on x-axis is at [1/p 0 0 1].
g i j r
a b c p
d e f q
l m n s
4 x 4
[T] =
0 0 1 0
1 0 0 p
0 1 0 0
0 0 0 1
= [x y z (px + 1)][x* y* z* 1] = [x y z 1]
161
ii. The single point perspective transformation when projectors are
placed on y-axis is given by:
The ordinary co-ordinate:
[x* y* z* 1] = [x/(qy + 1) y/(qy + 1) z/(qy + 1) 1]
It has center of projection at [0 -1/q 0 1] and vanishing point is located
at [0 1/q 0 1] on positive y-axis.
iii. The single-point perspective transformation when projectors are
placed at z-axis is given by:
The ordinary co-ordinates are:
[x* y* z* 1] = [x/(rz + 1) y/(rz + 1) z/(rz + 1) 1]
It has center of projection at [0 0 -1/r 1] and vanishing point is located
at [0 0 1/r 1] on +ve z-axis.
0 0 1 0
1 0 0 0
0 1 0 q
0
0 0 0 1
= [x y z (qy + 1)][x* y* z* 1] = [x y z 1]
0 0 1 r
1 0 0 0
0 1 0 0
0
0 0 0 1
= [x y z (rz + 1)][x* y* z* 1] = [x y z 1]
162
b. TWO-POINT PERSPECTIVE PROJECTION:
The general 4 x 4 transformation matrix is:
If any two elements of the fourth column of the above general matrix are
non-zero, the result is a two-point perspective transformation.
The single-point perspective transformation unfortunately does not
provide an adequate view of the three-dimensional shape of an object. So,
our aim is to develop some more complex perspective transformations. i.e.:
the two-point perspective transformation as:
The ordinary co-ordinates are:
[x* y* z* 1] = [x/(px + qy + 1) y/( px + qy + 1) z/( px + qy + 1) 1]
It has the two center of projections, one on x-axis at [-1/p 0 0 1] and
another on y-axis at [0 -1/q 0 1]. It also has two vanishing points, one on the
x-axis at [1/p 0 0 1] and another on y-axis at [0 1/q 0 1]. The two-point
g i j r
a b c p
d e f q
l m n s
4 x 4
[T] =
0 0 1 0
1 0 0 p
0 1 0 q
0
0 0 0 1
= [x y z (px + qy + 1)][x* y* z* 1] = [x y z 1]
163
perspective transformation can also be obtained by concatenation of two
single-point perspective transformation is:
c. THREE-POINT PERSPECTIVE PROJECTION:
When all the 3 elements of fourth column are non-zero, the result is a 3-
point perspective transformation. It is used to reconstruct the shape of a 3D
object, because to draw a cute it is necessary to know the co-ordinate of the
three faces, whenever a viewer stands it is possible to see maximum 3 sides
of a cube which lies in 3D space. The matrix form representation of 3-point
perspective transformation is:
When an object has co-ordinates (x, y, z) then,
0 0 1 0
1 0 0 0
0 1 0 q
0
0 0 0 1
0 0 1 0
1 0 0 p
0 1 0 0
0
0 0 0 1
[Ppq] = [Pp][Pq] =
0 0 1 0
1 0 0 p
0 1 0 q
0
0 0 0 1
=
0 0 1 r
1 0 0 p
0 1 0 q
0
0 0 0 1
[T] =
0 0 1 r
1 0 0 p
0 1 0 q
0
0 0 0 1
= [x y z (px + qy + rz +1)][x* y* z* 1] = [x y z 1]
164
It has 3 center of projections, one on x-axis at [-1/p 0 0 1], second on y-
axis at [0 -1/q 0 1] and third on z-axis at [0 0 -1/r 1]. It also has 3 vanishing
points, one on x-axis at [1/p 0 0 1], one on y-axis at [0 1/q 0 1] and one on z-
axis at [0 0 1/r 1].
The 3-point perspective transformation can also be obtained by
concatenation of 3 single point perspective transformations, that is:
[T] = [Pp] [Pq] [Pr]
VIEWING PIPELINE:
The steps for computer generation of a view of a 3D scene are somewhat
analogous to the processes involved in taking a photograph. To take a snapshot, we
first need to position the camera at a particular point in space. Then we need to
decide on the camera orientation; which do we point the camera and how should
we rotate it around the line of sight to set the up-direction for the picture.
Finally, when we snap the shutter, the scene is cropped to the size of the
window of the camera and light from the visible surfaces is projected onto the
camera film, we need to keep in mind, however that the camera analogy can be
carried only so far, since we have more flexibility and many more options for
generating views of a scene with a graphics package than we do with a camera.
0 0 1 0
1 0 0 0
0 1 0 q
0
0 0 0 1
0 0 1 0
1 0 0 p
0 1 0 0
0
0 0 0 1
=
0 0 1 r
1 0 0 0
0 1 0 0
0
0 0 0 1
0 0 1 r
1 0 0 p
0 1 0 q
0
0 0 0 1
=
165
It shows the general processing steps for modeling and converting a world co-
ordinates description of a scene to device co-ordinates. Once the scene has been
modeled, world co-ordinate positions are converted to viewing co-ordinates. The
viewing co-ordinate system in used in graphics packages as a reference for
specifying the observer viewing position and the position of the projection plane,
which we can think of in analogy with the camera film plane.
Projection operations are performed to convert the viewing co-ordinate
description of the scene to co-ordinate positions on the projection plane, which will
then be mapped to the output device. Objects outside the specified viewing limits
are clipped from further consideration and the remaining objects are processed
through visible surface identification and surface-rendering procedures to produce
the display within the device viewport.
3D CLIPPING:
The general ideas involved in 3D clipping by considering how clipping planes
directly. An algorithm for 3D clipping identifies and saves all surface segments
Modeling
Co-ordinates
Modeling
Transformation
World
Co-ordinates
Viewing
Transformation
Viewing
Co-ordinates
Projection
Transformation
Projection
Co-ordinates
Workstation
Transformation
Device
Co-ordinates
166
within the view volume for display on the output device. All parts of objects that
are outside the view volume are discarded.
Clipping in 3D can be accomplished using extensions of 2D clipping methods.
Instead of clipping against straight line window boundaries, we now clip objects
against the boundary planes of the view volume. To clip, a line segment against the
view volume, we need to test the relative position of the line using the view
volumes boundary plane equations.
By substituting the line endpoint co-ordinates into the plane equation of each
boundary in turn, we could determine whether the endpoint is inside or outside the
boundary. An endpoint (x, y, z) of a line segment is outside the boundary plane, if
Ax + By + Cz + D > 0, where A, B, C and D are the plane parameters for that
boundary.
Similarly, the point is inside the boundary if Ax + By + Cz + D < 0. Lines with
both endpoints outside a boundary plane are discarded and those with both
endpoints inside all boundary planes are saved. The intersection of a line with a
boundary is found using the line equations along with the plane equation.
Intersection co-ordinates (x1, y1, z1) are values that are on the line and that satisfy
the plane equation Ax1 + By1 + Cz1 + D = 0.
To clip a polygon surface, we can clip the individual polygon edges. First, we
could test the co-ordinates extents against each boundary of the view volume to
determine whether the object is completely inside or completely outside the
boundary. If the co-ordinate extents of the object are inside all boundaries, we save
it. If the co-ordinate extents are outside all boundaries, we discard it.
167
NORMALIZED VIEW VOLUME:
Here, at 1st
step, a scene is constructed by transforming object descriptions from
modeling co-ordinates. Next, a view mapping converts the world descriptions to
viewing co-ordinates. At projection stage, the viewing co-ordinates are
transformed to projection co-ordinates, which effectively convert the view volume
into a rectangular parallelepiped. Then the parallelepiped mapped into the unit
cube, a normalized view volume called the normalized projection co-ordinate
system. The normalized view volume is a region defined by the planes x = 0, x = 1,
y = 0, y = 1, z = 0, z = 1 --- (1).
There are several advantages to clip against the unit cube instead of the original
view volume or even the rectangular parallelepiped in projection co-ordinates.
i. The normalized view volume provides a standard shape for representing any
sized view volume. This separates the viewing transformations from any
workstation considerations and the unit cube then can be mapped to a
workstation of any size.
Modeling Co-
ordinates
Modeling
Transformation
World
Co-ordinates
Viewing
Transformation
Viewing
Co-ordinates
Projection
Transformation
Projection
Co-ordinates
Normalized
Transformation
Normalized
Projection
Co-ordinates
Workstation
Transformation
Device
Co-ordinates
168
ii. Clipping procedures are simplified and standardized with unit clipping
planes or the viewport planes and additional clipping planes can be
specified within the normalized space before transforming to device co-
ordinates.
iii. Depth Cueing and visible surface determination are simplified, since z-axis
always points toward the viewer. Front faces of objects are those with
normal vectors having a component along the positive ‘z’ direction and
back surfaces are facing in the –ve z-direction.
Mapping positions within a rectangular view volume to a 3D rectangular
viewport is accomplished with a combination of scaling and translation, similar to
the operations needed for a two-dimensional window-to-viewport mapping. We
can express the 3D transformation matrix for these operations in the form:
Factors Dx, Dy and Dz are the ratio of the
dimensions of the viewport and regular
parallelepiped view volume in the x, y and z
directions.
Dx = XVmax – XVmin / XWmax - XWmin
Dy = YVmax – YVmin / YWmax - YWmin
Dz = ZVmax – ZVmin / Zback – Zfront
Where the view-volume boundaries are established by the window limits
(XWmin, XWmax, YWmin, YWmax) and the position Zfront and Zback of front and back
planes. Viewport boundaries are set with the co-ordinate values XVmin, XVmax,
Dx 0 0 Kx
0 Dy 0 Ky
0 0 Dz Kz
0 0 0 1
169
YVmin, YVmax, ZVmin and ZVmax. The additive translation factors Kx, Ky and Kz in
transformation are:
Kx = XVmin – XWmin Dx
Ky = YVmin – YWmin Dy
Kz = ZVmin – ZWmin Dz
VIEWPORT CLIPPING:
For 3D points, we need to expand the region code to 6 bits. Each point in the
description of a scene is then assigned a 6 bit region code that identifies the relative
position of the point with respect to the viewport.
For a line endpoint at position (x, y, z), we assign the bit positions in the region
code from right to left as:
Example: A region code of 101000 identifies a point as above and behind the
viewport and the region code 000000 indicates a point within the volume. A line
segment can immediately identified as completely within the viewport if both
endpoints have a region code of 000000. If either endpoint of a line segment does
not have a region code of 000000, we perform the logical operation on the two
--- (1)
Bit 1 = 1, if x < XVmin (left)
Bit 2 = 1, if x > XVmax (right)
Bit 3 = 1, if y < YVmin (below)
Bit 4 = 1, if y < YVmax (above)
Bit 5 = 1, if z < ZVmin (front)
Bit 6 = 1, if z < ZVmax (back)
170
endpoint codes. The result of this ‘and’ operation will be non-zero for any line
segment that has both endpoints in one of the 6 outside regions.
Equations for 3D line segments are conveniently expressed in parametric form.
For a line segment with endpoints P1 = (x1, y1, z1) and P2 = (x2, y2, z2). We can
write the parametric line equations as:
Co-ordinates (x, y, z) represent any point on the line between the 2 endpoint. At
u = 0, we have the point ‘P1’ and at u = 1, puts as at ‘P2’. To find the intersection of
a line with a plane of the viewport, we substitute the co-ordinate value for that
plane into the appropriate parametric expression of equation – (2) and solve for ‘u’.
For instance, suppose we are testing at a line against the ZVmin plane of the
viewport. Then, u = ZVmin – z1/z2 – z1 --- (3). When the calculated value for ‘u’ is
not in the range from 0 to 1, the line segment does not intersect the plane under
consideration at any point between endpoints P1 and P2. If the calculated value for
‘u’ is in the interval from 0 to 1, we calculate the intersections ‘x’ and ‘y’ co-
ordinates as:
If either ‘x1’ or ‘y1’ is not in the range of the boundaries of the viewport, then
this line intersects the front plane beyond the boundaries of the volume.
--- (2)
x = x1 + (x2 – x1)u, 0 ≤ u ≤ 1
y = y1 + (y2 – y1)u
z = z1 + (z2 – z1)u
--- (4)
x1 = x1 + (x2 – x1)[(ZVmin – z1)/(z2 – z1)]
y1 = y1 + (y2 – y1)[(ZVmin – z1)/(z2 – z1)]
171
CLIPPING IN HOMOGENEOUS CO-ORDINATE:
At each co-ordinate position enters the transformation pipeline, it is converted
to a homogeneous co-ordinate representation: (x, y, z) → (x, y, z, 1). The various
transformations are applied and we obtain the final homogeneous point is:
Where h = homogeneous parameter, which may not be 1.
Infact, ‘h’ can have any real value. Clipping is then performed in homogeneous
co-ordinates and clipped homogeneous positions are converted to non-
homogeneous co-ordinates in 3D normalized projection co-ordinates:
xꞌ = xh/h, yꞌ = yh/h, zꞌ = zh/h --- (2)
To determine homogeneous viewpoint clipping boundaries we note that any
homogeneous co-ordinate position (xh, yh, zh, h) is inside the viewport, if it satisfies
the inequalities:
XVmin ≤ xh/h ≤ XVmax, YVmin ≤ xh/h ≤ YVmax, ZVmin ≤ xh/h ≤ ZVmax --- (3)
So, the homogeneous clipping limits are:
We can simply negate the co-ordinates for any point with h < 0 and use the
clipping inequalities for h > 0.
a11 a12 a13 a14
a21 a22 a23 a24
a31 a32 a33 a34
a41 a42 a43 a44
x
y
z
1
xh
yh
zh
= --- (1)
hXVmin ≤ xh/h ≤ hXVmax, hYVmin ≤ xh/h ≤ hYVmax, hZVmin ≤ xh/h ≤ hZVmax, if h > 0
hXVmax ≤ xh/h ≤ hXVmin, hYVmax ≤ xh/h ≤ hYVmin, hZVmax ≤ xh/h ≤ hZVmin, if h < 0
--- (4)
172
CHAPTER – 9
CLASSIFICATION OF VISIBLE SURFACE DETECTION ALGORITHM:
Visible surface detection algorithms are broadly classified to whether they deal
with object definitions directly or with their projected images. These 2 approaches
are called object-space methods and image-space methods respectively.
An object-space method compares objects and parts of objects to each other
within the scene definition to determine which surfaces, as a whole, we should
label as visible. In an image-space algorithm, visibility is decided point by point at
each pixel position on the projection plane.
Most visible surface algorithms use image-space methods although object-space
methods can be used effectively to locate visible surfaces in some cases. Line
display algorithms, on the other hand generally use object-space methods to
identify visible lines in wire frame displays, but many image-space visible-surface
algorithms can be adapted easily to visible-line detection.
BACK-FACE DETECTION:
It is a fast object-space algorithm based upon the inside-outside test for
identifying the back-face of polyhedron. Suppose a point (x, y, z) is inside a
polygon surface with plane parameters A, B, C and D, if:
Ax +By + Cz + D < 0 --- (1)
When an inside point is along the line of sight to the surface, the polygon must
be a back-face. That is, we are inside so we cannot see the front of it from our
viewing position. Now our purpose is to simplify the test. We can consider a
173
normal vector ‘N’ to a polygon surface which has the Cartesian components (A, B,
C). Let ‘V’ be the vector in the viewing direction from the eye, we can say a
camera position, then the polygon is back-face, if:
V.N > 0 --- (2)
If object descriptions have been converted to projection co-ordinates and our
viewing direction is parallel to the viewing z-axis, then V = (0, 0, Vz) and V.N =
Vz.c. So, we only need to consider the sign of ‘c’ and the z-component of the
normal vector ‘N’.
In a right handed viewing system with viewing direction along the negative z-
axis, the polygon is back-face. If c < 0, we cannot see any face whose normal has
z-component c = 0. Thus, in general, we can label any polygon as a back-face if its
normal vector has a z-component value c ≤ 0.
Also, back-face has normal vectors that point away from the viewing position
and are identified by c ≥ 0, when the viewing direction is along the positive z-axis.
By examining parameters ‘c’ for the different planes defining an object, we can
immediately identify all the back-faces.
Back-face definition is done differently in different spaces. That is:
i. Object Space: In this approach, we compare one surface with all the other
surfaces. The comparison is done in world co-ordinates.
ii. Image Space: In this approach, we determine the pixels which has
illuminated by the visible surface. The visible surface is determined by
the direction of normal to the plane.
174
DEPTH-BUFFER METHOD/Z-BUFFER METHOD:
This technique is originally developed ‘CATMULL’. A commonly used image-
space approach, to detect visible surfaces is the depth buffer method, which
compares surface depths at each pixel position on the projection plane. This is also
known as z-buffer method, since object depth is usually measured from the view
plane along the z-axis of viewing system.
This method is usually applied to scenes containing only polygon surfaces,
because depth values can be computed very quickly and the method is easy to
implement, but the method can be applied to non-planar surfaces.
With the object descriptions converted to projections co-ordinates, each (x, y, z)
position on a polygon surface corresponds to the orthographic projection point (x,
y) on the view plane. So far, each pixel position (x, y) on the view plane, object
depths can be compared by comparing z-values.
yv
xv
S1
S3
S2
zv
175
Here, 3 surfaces at varying distances along the orthographic projection line
from position (x, y) in a view plane taken as xvyv plane. Surface ‘S1’ is closest at
this position, so its surface intensity value at (x, y) is saved.
We can implement the depth-buffer algorithm is normalized co-ordinates, so
that ‘z’ values range from ‘0’ at the back clipping plane to ‘Zmax’ at the front
clipping plane. The value of ‘Zmax’ can be set either to 1 or to the largest value that
can be stored on the system.
For this method, 2 buffer areas are required. A depth buffer is used to store
depth values for each (x, y) position as surfaces are processed and the refresh
buffer stores the intensity values for each position.
Initially, all positions in depth buffer are set to ‘0’ and the refresh buffer is
initialized to the background intensity. Each surface listed in the polygon tables is
the processed, one scan line at a time, calculating the depth at each (x, y) pixel
position. The calculated depth is compared to the value previously stored in the
depth buffer at that position.
If the calculated depth is greater than the value stored in the depth buffer, the
new depth value is stored and the surface intensity at that position is determined
and placed in the same ‘xy’ location in the refresh buffer.
DEPTH-BUFFER/Z-BUFFER ALGORITHM:
1. Initialize the depth buffer and refresh buffer, so that for all buffer positions
(x, y): depth(x, y) = 0 and refresh(x, y) = Ibackground.
2. For each position on each polygon surface, compare depth values to
previously stored values in the depth buffer to determine visibility.
176
a. Calculate the depth ‘z’ for each (x, y) position on the polygon.
b. If z > depth(x, y), then set,
depth(x, y) = z and refresh(x, y) = Isurface(x, y)
Here, Ibackground = value for the background intensity.
Isurface(x, y) = projected intensity value for the surface at pixel
position (x, y).
After all surfaces have been processed, the depth buffer contains depth values
for the visible surfaces and the refresh buffer contains the corresponding intensity
values for those surfaces.
DEPTH CALCULATION:
The plane equation of the face currently being scan converted is:
Ax + By + Cz + D = 0
The depth values for a surface position (x, y) are calculated from the plane
equation for each surface is:
z = – (Ax + By + D)/C = – Ax – By – D/C
Obviously, this is an excessive amount of computation to carry out at each
pixel. However, the computation can be reduced to a single add per pixel by using
an incremental method. So, along a scan line ‘y’ stays constant while ‘x’ increases
by one. Hence ‘z’ changes by an incremental amount ‘dz’ given by:
177
Similarly, moving from one scan-line to the next the depth increment ‘dz’ in
moving down the left most edge is given by:
dz = – (B + Adx/C)
Here, dx = change in ‘x’ on that edge for a change of ‘1’ in ‘y’.
Thus, at each scan-line, the starting ‘z’ value is produced by a single addition of
a pre-calculated quantity to the initial value at the previous scan-line. This
extension is easily incorporated into the polygon scan-conversion algorithm with
the requisite depth increments for a face being stored with the face in the body data
structure. Only one extra addition per pixel is required over the requirements for
scan conversion.
Along a scan-line, when ‘y’ varies and ‘x’ is constant.
zꞌ = – {Ax – B(y – 1) – D}/C = – Ax – By – D/C + B/C = z + B/C (in y-axis).
Example:
We have 2 surfaces.
1st
Surface: P1: (10, 5, 10), P2: (10, 25, 10), P3: (25, 25, 10) and P4: (25, 5, 10).
dz = – A/C
=> Zꞌ – Z = – A/C => Zꞌ = Z – A/C
This can be calculated once for the
polygon.
Since, the ratio –A/C is constant for each
surface, so succeeding depth values across
a scan line are obtained from preceding
values with a single addition.
178
2nd
Surface: P5: (15, 15, 15), P6: (25, 25, 5), P7: (30, 10, 5)
We can imagine the surface overlapping as:
P5P6 = [10 10 -10] = P6 – P5
P5P7 = [15 -5 -10] = P7 – P5
P5P6 + P5P7
If we substitute the values in the standard equation:
-150x – 50y – 200z + 6000 = 0
=> 3x + y + 4z – 120 = 0
=> z = - (3x + y – 120)/4 = - (Ax + By + D)/C
For the ‘P6’ point i.e.:
At 25, z = - (75 + 25 – 120)/4 = 5
At 24, z = - (75 + 24 – 120)/4 = 21/4 = 5.25 ≈ 5
Ax + By + Cz + D = 0
=> z = – Ax – By – D/C
=
i i (-100 -50) – j (-100 + 150) + k (-50 – 150)
10
j k
10 -10
15 -5 -10
=
= 150i – 50 j – 200k
D = 6000
179
zꞌ = – {A(x + 1) – By – D}/C = – Ax – By – D/C – A/C
=> zꞌ = z – A/C (travelling along the scan line x-axis)
=> zꞌ = z – 3/4
=> zꞌ = 5 – 3/4 = 4.25 ≈ 4
A-BUFFER METHOD:
The A-Buffer Method represents an anti-aliased area average accumulation
buffer method, for implementation in the surface rendering system called REYES
(Renders Everything You Ever Saw).
A drawback of depth-buffer (z-buffer) is that it can only find one visible surface
at each pixel position. i.e.: it deals with only opaque surfaces. In A-Buffer, each
position in the buffer can reference a linked list of surfaces.
So that more than one surface intensity can be taken at each pixel position.
If the depth is positive, the number stored at that position is depth of a single
surface overlapping the corresponding pixel area. The intensity field then stores
RGB components of the surface color at that point and percent of pixel coverage. If
depth field is negative this indicates multiple surface contributions to the pixel
intensity.
d > 0
Depth
field
Intensity
field
d > 0 d > 0 Surface
Depth
Representation of Buffer for opaque surface and
Representation of Buffer for Transparent Surfaces.
180
THE SCAN-LINE METHOD:
This technique processes the scene one scan-line at a time. For each scan-line in
the window, we must determine which polygons the scan-line intersects. Then for
each pixel along the scan-line, determine which polygon is nearest to the eye at
that point; this then determine the color of that pixel.
Because, the scan-line method draws the image scan-line by scan-line, some
pre-processing of the polygon mesh is required before rasterization.
i. Horizontal edges must be removed; these edges will be drawn when the
adjacent edges are processed.
ii. The algorithm uses edge crossing to detect entry and exits of polygons.
Each edge crossed changes the “inside-outside parity”. When a scan-line
passes through the end-point of an edge, it produces two intersections,
one for each edge that meets at that vertex. This is correct if the vertex is
a local minimum or maximum. If the vertex is not a local extremum, the
two intersections will cause the parity to be unchanged. To resolve this
problem, when an intersection is not an extremum, simply reduce the
Yupper co-ordinates of the lower line segment by 1. This will not affect the
accuracy of the method as we will use the slope of the line segment
before shortening.
The scan-line method takes advantage of edge coherence. That is:
i. Many edges that are intersected by scan-line ‘y’ are also intersected
by scan-line ‘y + 1’.
ii. The x-value of the point of scan-line intersection migrates predictably
from scan-line to scan-line. The ‘x’ co-ordinates of the intersection of
181
an edge with a scan-line increase by 1/m for each scan-line, where ‘m’
is the slope of the edge.
An important component in the data structure needed for this algorithm is the
edge node. Each edge in the scene (after clipping) is represented by an edge node.
An edge node contains the following information. That is:
i. Yupper, the ‘y’ co-ordinate of the upper end point of the edge (after
possibly being shortened).
ii. Xint, the ‘x’ co-ordinate of the lower end point of the edge. As the
algorithm progresses, this field will store the x-coordinate of the point of
intersection of the scan-line.
iii. ym, the reciprocal of the slope of the line (1/m).
To keep track of which polygons we are currently drawing we need to build an
edge table, which contains an entry for each scan-line, this entry is a list of all
edges first intersected by a given scan-line. Each edge contains some information
about the edge and a list of associated faces or polygons.
m
Scan-line y + 1
Scan-line y
1
[Incrementing the Xint using 1/m]
182
We also need an Active Edge List (AEL), which contains a list of edge nodes.
The AEL represents edges intersected by the current scan-line. The AEL needs to
be maintained as we move from one scan-line(y) to the next scan-line(y + 1).
i. Some of the edges in the AEL will no longer be intersected by y + 1.
Remove all edges from the AEL, where Yupper is less than y + 1.
ii. The intersection point of the scan-line with the remaining edges will
change for the new scan-line Xint is updated to Xint + ym. Note that Xint
must be stored as a real number to avoid round-off errors.
iii. New edges may need to be added to the AEL. If y + 1 is equal to Ylower of
any edges in the edge table, then those edges must be added to AEL.
iv. The node in the AEL must be stored (for parity checking) in ascending
order of Xint. So, after adding new edges and updating the Xint values of
edges, the AEL must be sorted.
For each polygon in the scene, we maintain a flag which is set IN or OUT
depending on whether we are inside or outside that polygon. As we process a scan-
line, we will cross edges, as we cross an edge we must ‘reset’ the flag for each
polygon which shares the edges. If we are IN a polygon and we pass an edge of
that polygon we must reset the flag to OUT. As we process a scan-line, pixel by
pixel, we need to color the pixels as follows:
i. If no flags are set to IN, then the pixel gets background color.
ii. If only ONE flag is set to IN, then the pixel gets the color face we are in.
iii. If more than one flag is IN, we need to determine which face is closest at
that point by calculating the depth of each face as in the Depth-Buffer
method. The pixel gets the color of closest face.
183
When we are IN two or more polygons, we can calculate the closest face for
each pixel or we can assume that the closest face at the first pixel of the overlap
will remain the closest face until we meet another edge. This way we need only
calculate depths at the beginning of an overlap area and need not do the
calculations for every pixel. This will allow us to implement a very efficient
algorithm.
DEPTH SORTING METHOD:
Depth Sorting Method is also known as Painter’s Algorithm. This method uses
both image-space and object-space operations, the depth-sorting method perform
the following basic functions. That is:
i. Surfaces are sorted in order of decreasing depth
ii. Surfaces are scan converted in order, starting with the surfaces of greatest
depth.
Sorting operations are carried out in both image and object space and the scan
conversion of the polygon surfaces is performed in image space. This method for
solving the hidden surface problem is often referred to as the painter’s algorithm,
where a property of frame buffer used by Newell. The algorithm gets its name
from the manner in which an oil painting is created.
IMPLEMENTATION:
1. First of all, we can process each polygon independently as we did in back-
face check of full screen z-buffer.
2. We must compare each polygon with all of the rest to see which is in front
of which.
184
3. Sort the polygon to determine a property of their display.
4. The sorting will determine the order in which they will be entered into the
display file.
5. For efficiency we try to limit the number of comparison process fast.
The depth sort algorithm is a hybrid algorithm in that it sorts in object space and
does the final rendering in image space. Hence the basic algorithm is:
i. Sort all polygons in descending order of maximum z-values.
ii. Resolve any ambiguities in this ordering.
iii. Scan converts each polygon in the order generated by steps 1 and 2.
The necessity of step-2 can be seen in the simple case: ‘A’ precedes ‘B’ in order
of maximum ‘z’ but ‘B’ should precede ‘A’ in writing order. At step-2, the
ordering produced by ‘1’ must be confirmed. This is done by making more precise
comparison between polygons whose z-extends overlap.
Assume that polygon ‘P’ is currently at the head of the sorted list, before scan
converting it to the frame buffer; it is tested against each polygon ‘Q’, whose z-
extent overlaps that of ‘P’. The following tests of increasing complexity are then
carried out: sorts in object space and does the final rendering in image space.
Hence the basic algorithm is:
A
Bz
x
185
i. If the x-extents of ‘P’ and ‘Q’ don’t overlap then the polygons don’t overlap,
hence their ordering is immaterial.
ii. If the y-extents of ‘P’ and ‘Q’ do not overlap then the polygons do not
overlap, hence their ordering is immaterial.
iii. If ‘P’ is wholly on the far away side of ‘Q’ then ‘P’ is written before ‘Q’.
iv. If the projection of ‘P’ and ‘Q’ do not overlap then the order ‘P’ and ‘Q’ in
the list is immaterial.
If any of these tests are satisfied then the ordering of ‘P’ and ‘Q’ need not be
changed. However, if all five tests fails then it is assumed that ‘P’ obscures ‘Q’ and
they are interchanged in the list. To avoid looping in the case where ‘P’ and ‘Q’
interpenetrate ‘Q’ must be marked as having been moved in the list.
When polygon ‘Q’ which has been marked fails all tests again when tested
against ‘P’, then it must be split into two polygons and each of these polygons
must be treated separately, ‘Q’ is split in the plane of ‘P’ as illustrated below along
AB.
Often the test-5, will not be done. It can be very
complex for general polygons. The Depth Sort
method also has the same disadvantage as the z-
buffer algorithm, namely that all the polygons are
scan converted but many of them might not appear
at all on the final picture.
Q
P
z
x
Q
P
z
x
A
B
Q
P
186
RAY TRACING ALGORITHMS:
The design of hidden surface algorithms to deal with non-polynomial, non-
planner surface patches is an area of active research. One algorithm, in particular,
called ray-tracing algorithm, provides realistic shading, if required. This algorithm
is based on the principles of light and optics.
Currently, let us consider this algorithm only for hidden surface removal
purpose. We shall assume opaque surfaces of given colors and deal directly with
perspective projection transformation without applying perspective to parallel
transformation.
The basic idea is to trace light rays and determine which ones arrive back at the
eye or view-point. Since this involves an infinite number of light rays, we work
backward. i.e.: we trace a ray from the view point through a pixel until it reaches a
surface. Since this represents the first surface seen at the given pixel, we set the
pixel to the color of the surface at the point where the light ray strikes it. If
resolution of screen is x1 * y1, there are ‘x1y1’ pixels and so ‘x1y1’ light rays are
traced.
Each ray is tested for intersections with each object in the picture, including the
non-clipping plane. Since, each ray can intersect several objects; we find the
x
z
p
Ray
Eye
Pixel(x, y)
y p1
p2
[Ray Tracing Algorithm]
187
intersection point ‘I’, which is closest to the viewpoint. We set the pixel belonging
to the given ray to the color of the surface on which this point ‘I’ lies.
This represents the first surface intersected by the ray. We repeat this process
for each pixel. The computational expense can be reduced by use of the extent or
bounding box of an object or surface. If a ray does not intersect a bounding box,
there is no need to check for intersections with enclosed surface. The most
important reason for using ray-tracing method is to create extremely realistic
renderings of pictures by incorporating laws of optics for reflecting and
transmitting light rays.
BASIC RAY-TRACING ALGORITHM:
We first set up a co-ordinate system with the pixel positions designated in the
xy-plane. The scene description is given in this reference frame.
From the center of projection, we then determine a ray path that passes through
the center of each screen pixel position. Illumination effects accumulated along
this ray path are then assigned to the pixel. This rendering approach is based on the
principles of geometric optics.
Light rays from the surfaces in a scene emanate in all directions, and some will
pass through the pixel positions in the projection plane. Since there are infinite
x
z
y
Projection reference point
- Pixel Screen area centered on viewing co-ordinate origin.
188
numbers of ray paths, we determine the contributions to a particular pixel by
tracing a light path backward from the pixel to the scene.
For each pixel ray we test surface in the scene to determine if it intersected by
ray. If a surface is intersected, we calculate the distance from the pixel to the
surface intersection point. The smallest calculated intersection distance identifies
the visible surface for that pixel. We then reflect the ray off the visible surface
along a specular path. If the surface is transparent, we also send a ray through the
surface in the refraction direction. Refraction and Reflection rays are referred to as
Secondary rays
This procedure is repeated for each secondary ray-object is tested for
intersection and the nearest surface along a secondary ray path is used to
recursively produce the next generation of reflection and refraction paths. As the
rays from pixel ricochet (skip off) through the scene, each successively intersected
surface is added to a binary ray-tracing tree.
Here, the left most branches in the tree represent reflection paths and right
branches represent transmission paths. Minimum depth of the ray-tracing trees can
T3
S4
S3
S1
R1
S2
R3
T1
R2
R4
a) Reflection and Refraction ray
paths through screen pixel
Projection
Reference
Point
S3
S2
S4
S3
R3
T1
T3
R1
R2
R4
b) Binary ray tracing tree for the
paths shown in (a)
189
be set as a user option or it can be determined by the amount of storage available.
A path in the tree is then terminated of it reaches the preset maximum or if the ray
strikes a light source.
The intensity assigned to a pixel is then determined by accumulating the
intensity contributions, starting at the bottom of its ray-tracing tree. Surface
intensity from each node in the tree is attenuated by the distance from the “parent”
surface and added to the intensity of the parent surface.
Pixel intensity is then the sum of the attenuated intensities at the root node of
the ray tree. If no surfaces are intersected by a pixel ray, the ray-tracing tree is
empty and the pixel is assigned the intensity value of the background. If a pixel ray
intersects a non-reflecting light source, although light sources are usually placed
beyond the path of the initial rays.
Here, a surface intersected by a ray and the unit vectors needed for the reflected
light intensity calculations. Unit vector ‘u’ is in the direction of the ray path
The path along ‘L’ is referred as the shadow ray. If any object intersects the
shadow ray between the surface and the point light source, the surface is in shadow
is in window with respect to that surface.
N
Refracted ray
R
Incoming ray
H
L
u
[Unit Vector at ace of an object intersected by an incoming ray along direction ‘u’]
N = unit surface normal
R = unit reflection vector
L = unit vector pointing to the light source
H = unit vector halfway between V (opposite
to u) and L
190
Ambient Light at the surface is calculated as KaIa, diffuse reflection due to the
source is proportional to Kd(N.L) and the specular reflection component is
proportional to Ks(H.N)ns
. The specular reflection direction for the secondary ray
path ‘R’ depends on the surface normal and the incoming ray direction is:
R = u – (2u.N)N --- (1)
For a transparent surface, we also need to
obtain intensity contributions from light
transmitted through the material.
We can locate the source of this contribution by tracing a secondary ray along
the transmission direction ‘T’. The unit transmission vector can be obtained from
vectors ‘u’ and ‘N’ as:
T = ηi/ηr u – (cosθr – ηi/ηrcosθi) --- (2)
Parameters ‘ηi’ and ‘ηr’ are the indices of refraction in the incident indices of
refraction in the incident material and the refracting material respectively. Angle of
refraction ‘θr’ can be calculated from Snell’s law:
RAY SURFACE INTERSECTION CALCULATIONS:
A ray can be described with an initial position ‘P0’ and unit direction vector ‘u’.
The co-ordinate of any point ‘P’ along the ray at a distance ‘S’ from ‘P0’ is
computed from the ray equation:
P = P0 + Su --- (1)
cosθr = 1 – (ηi/ηr)2
(1 – cos2
θi) --- (3)
N
Refracted
ray path
θr
Incoming
ray
θi
T
u
191
Initially, P0 can be set to the position of the pixel
on the projection plane or it could be chosen to be
the projection reference point. Unit Vector ‘u’ is
initially obtained from the position of the pixel
through which the ray passes and the projection
reference point.
Unit vector ‘u’ is initially obtained from the position of the pixel through which
the ray passes and the projection reference point:
u = |Ppix – Pprp/Ppix – Pprp| --- (2)
At each intersected surface, vectors ‘P0’ and ‘u’ are updated for the secondary
rays at the ray-surface intersection point. For the secondary rays, reflection
direction of ‘u’ is ‘R’ and the transmission direction is ‘T’. The simplest objects to
ray trace are spheres. If we have a sphere of radius ‘r’ and center position ‘Pc’, then
any point ‘P’ on the surface must satisfy the sphere equation:
|P – Pc|2
– r2
= 0 --- (3)
Substituting the ray equation i.e.: equation – (1), we have:
|P0 + Su – Pc|2
– r2
= 0 --- (4)
If we let ∆P = Pc – P0 and expand the dot product, we obtain the quadratic
equation:
S2
– 2(u.∆P)S + (|∆P| – r2
) = 0 --- (5)
x
z
y ray path
[Describing a ray with an
initial position vector
‘P0’ and unit direction
vector ‘u’]
u
P0
192
Whose solution is:
If the discriminant is negative, the ray
does not intersect the sphere. Otherwise, the
surface-intersection co-ordinates are
obtained from the ray equation – (1) using
the4 smaller of the two values from equation
– (6). For small spheres that are far from the
initial ray position, equation – (6) is
susceptible to round off errors. That is, if:
r2
<< |∆P|2
We could lose the ‘r2
’ term in the precision error of |∆P|2
. We can avoid this for
most cases by re-arranging the calculating for distance ‘S’ as:
If a ray does not intersect the sphere, we do not need to do any further testing on
the polyhedron. But if the ray does intersect the sphere, we first locate front faces
with the test:
u.N < 0 --- (8), where N = Surface Normal
For each face of the polyhedron that satisfies inequality equation – (8), we solve
the plane equation:
N.P = - D --- (9)
S = u.∆P (u.∆P) 2
– (∆P) 2
+ r2
--- (6)
x
z
y
[A ray intersecting a sphere with
radius ‘r’ centered on position Pc]
P0
Pc
u
P
r
S = u.∆P r2
- |∆P - (u. ∆P)u|2 ---
(7)
193
For surface position ‘P’ that also satisfies the ray equation – (1). Here, N = (A,
B, C) and ‘D’ is the fourth plane parameter.
Position ‘P’ is both on the plane and on the
ray path if:
N.(P0 + Su) = - D --- (10)
And the distance from the initial ray position
to the plane is: S = - D + N.P0/N.u --- (11)
This gives us position on the infinite plane that contains the polygon face but
this position may not be inside the polygon boundaries. So we need to perform
inside-outside test for polygon to determine whether the ray intersected this face of
the polyhedron.
AREA SUB-DIVISION METHOD:
It is essentially an image-space method, but object-space operations can be used
to accomplish depth ordering of surfaces. The area sub-division method takes
advantage of area coherence in a scene by locating those view areas that represent
part of a single surface.
This method is applied successively dividing the total viewing area into smaller
and smaller rectangles until each small area is the projection of part of a single
visible surface or no surface at all.
To implement this method, we need to establish tests that can quickly identify
the area as part of a single surface or tell us that the area is too complex to analyze
easily. Starting with the total view, we apply the tests to determine whether we
[Polyhedron enclosed
by a boundary sphere.]
194
should subdivide the total area into smaller rectangles. If the tests indicate that the
view is sufficiently complex, we subdivide it.
We apply the tests to each of the smaller areas subdividing these if the tests
indicate the visibility of a single surface is still uncertain. We continue this process
until the subdivisions area easily analyzed as belonging to the size of a single pixel.
An easy way to do this is to successively divide the area into number of equal
parts.
Tests to determine the visibility of a single surface within a specified area are
made by comparing surfaces to the boundary of the area. There are four possible
relationships that a surface can have with a specified area boundary.
i. Surrounding Surface: One that completely encloses the area.
ii. Overlapping Surface: One that is partly inside and partly outside the area.
iii. Inside Surface: One that is completely inside the area.
iv. Outside Surface: One that is completely outside the area.
The tests for determining surface visibility within an area can be stated in terms
of these four classifications. No further sub-divisions of a specified area are needed
if one of the following conditions is true:
i. All Surfaces are outside surfaces with respect to the area.
ii. Only one inside, overlapping or surrounding surface is in the area.
iii. A surrounding surface obscures all other surfaces within the area boundaries.
Test 1 can be carried out by checking the bounding rectangles of all surfaces
against the area boundaries. Test 2 can also use the bounding rectangles in the xy-
plane to identify an inside surface. For other types of surfaces, the bounding
195
rectangles can be used as an initial check. If a single bounding rectangle intersects
the area in some-way, additional checks are used to determine whether the surface
is surrounding, overlapping or outside. Once a single inside, overlapping or
surrounding surface has been identified, its pixel intensities are transferred to the
appropriate area within the frame.
One method for implementing test 3 is to order surface according to their
minimum depth from the view plane. For each surrounding surface, we then
compute the maximum depth within the area under consideration. If the maximum
depth of one of these surrounding surfaces is closer to the view plane than the
minimum depth of all other surfaces within the area, test 3 is satisfied.
Another method for carrying out test 3 that does not require depth sorting is to
use plane equations to calculate depth values at the four vertices of the area for all
surrounding, overlapping and inside surfaces. If the calculated depth for one of the
surrounding surfaces is less than the calculated depths for all other surfaces, test 3
is true. Then the area can filled with the intensity values of the surrounding
surface.
For some situations, both methods of implementing test 3 will fail to identify
correctly a surrounding surface that obscures all the other surfaces. Further testing
xv
zv
- Zmax (Surrounding Surface)
[Within a specified area, a surrounding surface with a maximum depth
beyond Zmax.]
Area
196
could be carried out to identify the single surface that covers the area but it is faster
to subdivide the area than to continue with more complex testing.
Once outside and surrounding surfaces have been identified for an area, they
will remain outside and surrounding surfaces for all subdivisions of the area. Some
inside and overlapping surfaces can be expected to be eliminated as the subdivision
process continues, so that the areas become easier to analyze.
RAY CASTING METHOD:
If we consider the line of sight from a pixel position on view plane through a
scene, we can determine which objects in the scene intersect the line. After
calculating all ray-surface intersection we identify the visible surface as the one
whose intersection point is closest to the pixel. The visibility detection scheme uses
ray-casting procedures.
Ray Casting, as a visibility-detection tool is bases on geometric, optics methods,
which trace the paths of light rays. Since there are an infinite number of light rays
in a scene and we are interested only in those rays that pass through pixel
positions, we can trace the light ray paths backward from the pixels through the
scene. The ray-casting approach is an effective visibility-detection method for
scenes with curved surfaces, particularly spheres.
pixel
197
In ray casting, we process pixels one at a time and calculate depths for all
surfaces along the projection path to that pixel. Ray casting is a special case of ray
tracing algorithms that trace multiple ray paths to pick up global reflection and
refraction contributions from multiple objects in a scene. With ray casting, we only
follow a ray out from each pixel to the nearest object.
198
CHAPTER – 10
CURVED LINES AND SURFACES:
Display of 3D curved lines and surfaces can be generated from an input set
mathematical function defining the objects or from a set of user specified data
points.
When a set of discrete co-ordinate points is used to specify an object shape, a
functional description is obtained that best fits the designated points according to
the constraints of the application. Spline Representations are examples of this class
of curves and surfaces. These methods are commonly used to design new object
shapes, to digitize drawings and to describe animation paths. Curve and Surface
equations can be expressed in either a parametric or a non-parametric form.
QUADRATIC SURFACES:
Frequently used classes of objects are the Quadratic surfaces, which are
described with second-degree equations. They include sphere, ellipse, tori,
parabola and hyperbola. Quadratic Surfaces particularly sphere and ellipses are
common elements of graphics and they are often available in graphics packages as
primitives from which more complex objects can be constructed.
i. SPHERE:
In Cartesian co-ordinates, a spherical surface with radius ‘r’ centered
on the co-ordinate origin is defined as the set of points (x, y, z) that
satisfy the equation:
x2
+ y2
+ z2
= r2
--- (1)
199
The spherical surface in parametric form using latitude and longitude
angles as:
This parametric representation provides a symmetric range for the
angular parameters ‘θ’ and ‘Φ’. We could write the parametric equations
using standard spherical co-ordinates where angle ‘Φ’ is specified as the
colatitude. Then ‘Φ’ is defined over the range 0 ≤ Φ ≤ π and ‘θ’ is often
taken in the range 0 ≤ θ ≤ 2π. We could also set up the representation
using parameters ‘u’ and ‘v’ defined over the range from 0 to 1 by
substituting Φ = πu and θ = 2πv.
ii. ELLIPSE:
An ellipsoidal surface can be described as an extension of a spherical
surface, where the radii in 3 mutually perpendicular directions can have
different values.
--- (2)
x = rcosΦcosθ, -π/2 ≤ Φ ≤ π/2
y = rcosΦsinθ, -π ≤ θ ≤ π
z = rsinΦ
P = (x, y, z)
z-axis
x-axis
y-axis
Φ
θ
P
z-axis
x-axis
y-axis
Φ
Spherical co-ordinate parameters (r, θ, Φ) using
colatitude for angle ‘Φ’
200
The Cartesian representation for points over the surface of an ellipsoid
centered on the origin is:
(x/rx)2
+ (y/ry)2
+ (z/rz)2
= 1 --- (3)
And a parametric representation for the ellipsoid in terms of the
latitude angle ‘Φ’ and the longitude angle ‘θ’ is:
iii. TORUS:
It is a doughnut-shaped object. It can be generated by rotating a circle
or other conic about a specified axis. The Cartesian representation for
points over the surface of a torus can be written in the form:
Where r = any given offset value.
Parametric representations for a torus are similar to those for an
ellipse, except that angle ‘Φ’ extends over 360o. Using latitude and
longitude angle ‘Φ’ and ‘θ’, we can describe the torus surface as the set
of points that satisfy:
[r - (x/rx)2
+ (y/ry)2
]2
+ (z/rz)2
= 1 --- (5)
--- (4)
x = rxcosΦcosθ, -π/2 ≤ Φ ≤ π/2
y = rycosΦsinθ, -π ≤ θ ≤ π
z = rzsinΦ
z
y
x
rz
rx
ry
An ellipsoid with radii ‘rx’, ‘ry’ and ‘rz’ centered
on the co-ordinate origin.
201
BSP TREES:
It is a representation scheme is similar to octree encoding, except we now
divide space into two partitions instead of eight at each step. With a binary space
partitioning (BSP) tree, we sub-divide a scene into two sections at each step with
a plane that can be at any positions and orientation.
For adaptive subdivision of space, BSP trees can provide a more efficient
partitioning since we can position and orient the cutting planes to suit the spatial
distribution of the objects. This can reduce the depth of the tree representation for a
scene, compared to an octree and thus reduce the time to search the tree. In
addition, BSP trees are useful for identifying visible surfaces and for space
partitioning in ray-tracing algorithm.
--- (6)
x = rx(r + cosΦ)cosθ, -π ≤ Φ ≤ π
y = ry(r + cosΦ)sinθ, -π ≤ θ ≤ π
y = rzsinθ
z-axis
rz
xy-plane
0
Φ
(x, y, z)
rx = ry
0
(x, y, z)
θ
y-axis
202
OCTREES:
Hierarchical tree structures called octree are used to represent solid objects in
graphics systems. Medical image and other applications that require displays of
object cross sections commonly use octree representations.
The octree encoding procedure for a 3D space is an extension of an encoding
scheme for a 2D space, called quad-tree encoding. Quad-tree is generated by
successively dividing a 2D region into quadrants. Each node in the quad-tree has 4
data elements, one for each of the quadrants in the region.
If all pixels within a quadrant tree have the same color, the corresponding data
element in the node stores that color. A flag is set in the data element to indicate
that the quadrant is homogeneous. If all pixels in quadrant 2 are found to be red,
the color code for red is then placed in data element 2 of the node. Otherwise the
quadrant is said to be heterogeneous and that quadrant is itself divided into
quadrants.
The corresponding data element in the node now flags the quadrant as
heterogeneous and stores the pointer to the next node in quad-tree.
Quadrant 4 Quadrant 1
Quadrant 3 Quadrant 2
REGION OF A 2D SPACE
3210
DATA ELEMENTS IN THE
REPRESENTIVE QUAD-TREE NODE
3 2
10
REGION OF 2D SPACE
10 32
10 32
QUAD-TREE REPRESENTATION
203
SPLINE REPRESENTATION:
In drafting terminology, a spline is a flexible strip used to produce a smooth
curve through a designated set of points. Several small weights are distributed
along the length of the strip to hold it in position on the drafting table as the curve
is drawn.
The term spline curve, originally referred to a curve drawn this manner. In
computer graphics, the term spline curve now refers to any composite curve
formed with polynomial sections satisfying specified continuity conditions at the
boundary of the pieces. A spline surface can be described with two sets of
orthogonal spline curves.
Splines are used in graphics applications to design curve and surface shapes to
digitize drawings for computer storage and to specify animation paths for the
objects or the camera in a scene.
INTERPOLATION AND APPROXIMATION SPLINES:
We specify a spline curve by giving a set of co-ordinate positions, called control
points, which indicates the general shape of the curve. The control points are then
fitted with piecewise continuous parametric polynomial functions in one of two
ways. When polynomial sections are fitted so that the curve passes through each
control point, the resulting curve is said to interpolate the set of control points.
When the polynomials are fitted to the general control point path without
necessarily passing through any control point, the resulting curve is said to
approximate the set of control points.
204
Interpolation curves are commonly used to digitize drawings to specify
animation paths. Approximation curves are primarily used as design tools to
structure object surfaces. A spline curve is defined, modified and manipulated with
operations on the control points.
The convex polygon boundary that encloses a set of control points is called the
convex hull. One way to envision the shape of a convex hull is to imagine a rubber
band stretched around the positions of the control points, so that each control point
is either on the perimeter of the hull or inside it.
P0 P1
P2
P3
P0
P1
P2
P3
2
Convex hull shapes (dashed lines)
for 2 sets of control points
P0
P1
P2
2
P3
2
P0
P1
P2
2
P3
Control graphs shapes for 2
different sets of control point.
→ A set of 6 control points
interpolated with piecewise
continuous polynomial
sections.
[A set of 6 control points approximated
with piecewise continuous polynomial
sections.]
205
Convex hulls provide a measure for the deviation of a curve or surface from the
region bounding the control points. Some splines are bounded by the convex hull,
thus ensuring that the polynomials smoothly follow the control points without
erratic oscillations.
A polyline connecting the sequence of control points for an approximation
spline is usually displayed to remind a designer of the control-point ordering. This
set of connected line segments is often referred to as the control graph of the curve.
Other names for the series of straight line sections connecting the control points in
the order specified are control polygon and characteristic polygon.
PARAMETRIC CONTINUITY CONDITIONS:
To ensure a smooth transition from one section of a piecewise parametric curve
to the next, we can impose various continuity conditions at the connection points.
If each section of a spline is described with a set of parametric co-ordinate function
of the form:
x = x(u), y = y(u), z = z(u), u1 ≤ u ≤ u2 --- (1)
We set parametric continuity by matching the parametric derivations of
adjoining curve sections at their common boundary.
a) Zero-Order Parametric Continuity, desired as Co
-Continuity, means
simply that the curve meet. That is the value of x, y and z evaluated at ‘u2’,
for the first curve section are equal respectively to the values of x, y and z
evaluated at ‘u1’ for the next curve section.
b) First-Order Parametric Continuity, referred to as C1
-Continuity, means
that the first parametric derivatives of the co-ordinate function in derivatives
206
of the co-ordinate function in equation-(1) for two successive curve sections
are equal at their joining point.
c) Second-Order Parametric Continuity, referred as C2
-Continuity, means
that both the first and second parametric derivatives of the two curve
sections are the same at the intersection. Higher-order parametric continuity
conditions are defined similarly.
GEOMETRIC CONTINUITY CONDITIONS:
An alternate method for joining two successive curve sections is to specify
conditions for geometric continuity. In this case, we only require parametric
derivatives of the two sections to be proportional to each other at their common
boundary instead of equal to each other.
Zero-Order Geometric Continuity described as Go
-Continuity is the same as
zero-order parametric continuity. i.e.: the 2 curves sections must have the same co-
ordinate position at the boundary point.
First-Order Geometric Continuity or G1
-Continuity means that the
parametric 1st
derivatives are proportional at the intersection of two successive
sections. If we donate the parametric position on the curve as P(u), the direction of
the tangent vector Pꞌ(u), but not necessarily its magnitude, will be the same for
two successive curve sections at their joining point under G1
-Continuity.
C
O
N
T
I
N
U
I
T
Y
C
O
N
D
I
T
I
O
N
S
:
Zero-Order Continuity C
O
N
T
I
N
U
I
T
Y
C
O
N
D
I
T
I
O
N
S
:
First-Order Continuity Second-Order Continuity
207
Second-Order Geometric Continuity or G2
-Continuity means that both the
first and second parametric derivatives of the two curve sections are proportional at
their boundary. Under G2
-Continuity, curvatures of two curve sections will match
at the joining position.
SPLINE SPECIFICATIONS:
There are 3 equivalent methods for specifying a particular spline representation:
i. We can state the set of boundary conditions that are imposed on the spline.
ii. We can state the matrix that characterizes the spline.
iii. We can state the set of blending functions or basis functions that determine
how specified geometric constraints on the curve are combined to
calculate positions along the curve path.
To illustrate these 3 equivalent specifications, suppose we have the following
parametric cubic polynomial representation for the x-co-ordinate along the path of
a spline section:
x(u) = axu3
+ bxu2
+ cxu + dx, 0 ≤ u ≤ 1 --- (1)
Boundary condition for this curve might be set.
E.g.: On the end point co-ordinates x(0) and x(1) and on the parametric 1st
derivatives at the endpoints xꞌ(0) and xꞌ(1). These four boundary conditions are
sufficient to determine the values of the four coefficients ax, bx, cx and dx.
From the boundary conditions, we can obtain the matrix that characterizes this
spline curve by first rewriting equation (1) as the matrix product:
208
Where U = row matrix of powers of parameter ‘u’,
C = coefficient column matrix.
Using equation-(2), we can write the boundary conditions in matrix form and
solve for the coefficient matrix ‘C’ as:
C = Mspline . Mgeom --- (3)
Where, Mgeom = four element column matrix containing the geometric
constraint values on the spline and Mspline = 4 by 4 matrix, which transforms the
geometric constraint values to the polynomial coefficients and provides a
characterization for the spline curve.
Matrix ‘Mgeom’ contains control point co-ordinate values and other geometric
constraints that have been specified. So, we can substitute the matrix representation
for ‘C’ in equation-(2) to obtain:
x(u) = U . Mspline . Mgeom --- (4)
The matrix ‘Mspline’ characterizing a spline representation, sometimes called the
basis matrix, is particularly useful for transforming from one spline representation
to another. Finally, we can expand equation-(4) to obtain a polynomial
representation for co-ordinate ‘x’ in terms of the geometric constraint parameters:
x(u) = Σ gk . BFk(u) --- (5)
k = 0
3
= U . C --- (2)
ax
bx
cx
dx
x(u) = u3
u2
u 1
209
Where, ‘gk’ are the constraint parameters, such as the control-point co-ordinates
and slope of the curve at the control points and BFk(u) are the polynomial blending
functions.
B-SPLINE CURVES AND SURFACES:
B-Splines have two advantages over Bezier Splines. That is:
i. The degree of a B-Spline polynomial can be set independently of the number
of control points.
ii. B-Splines allow local control over the shape of a spline-curve of surface.
The trade-off is that B-Splines are more complex than Bezier Splines.
B-SPLINE CURVES:
A general expression for the calculation of co-ordinate positions along a B-
Spline curve in a blending function formulation as:
Where, Pk = input set of ‘n + 1’ control points.
There are several differences between this B-Spline formulation and that for
Bezier Splines. The range of parameter ‘u’ now depends on how we choose the B-
Splines Parameters and the B-Spline blending functions Bk, d are polynomials of
degree d – 1, where parameter ‘d’ can be chosen to be any integer value in the
range from 2 upto the number of control points n + 1.
P(u) = Σ Pk . Bk, d(u), umin ≤ u ≤ umax and 2 ≤ d ≤ n + 1 --- (1)
k = 0
n
3
210
Local control for B-Splines is achieved by defining the blending functions over
sub-intervals of the total range ‘u’. Blending functions for B-Spline curves are
defined by the Cox-deBoor recursion formulas:
Here, each blending function is defined over ꞌdꞌ sub-intervals of the total range
of ‘u’. The selected set of sub-interval endpoints ‘uj’ is referred to as a knot vector.
We can choose any values for the sub-interval endpoints satisfying the relation that
is: uj ≤ uj + 1. Values for umin and umax then depend on the number of control points
we select. The value we choose for parameter ꞌdꞌ and how we set up the sub-
intervals.
B-Spline Curves have the following properties:
i. The polynomial curve has degree d – 1 and Cd – 2
continuity over the range of
‘u’.
ii. For n + 1 control points, the curve is described with n + 1 blending
functions.
iii. Each blending function Bk, d is defined over ꞌdꞌ sub-intervals of total range of
‘u’, starting at knot value ‘uk’.
iv. The range of parameter ‘u’ is divided into n + d subintervals by n + d + 1
values specified in the knot vector.
Bk, 1(u) = 1, if uk ≤ u ≤ uk + 1
Bk, d(u) =
0, otherwise
u – uk
uk + d - 1 – uk
Bk, d - 1(u) +
uk + d – u
uk + d – uk + 1
Bk + 1, d + 1(u)
+
--- (2)
211
v. With knot values labeled as {u0, u1, … , un + d}, the resulting B-Spline curve
is defined only in the interval from knot value ud – 1 upto knot value un + 1.
vi. Each section of the spline curve is influenced by ꞌdꞌ control points.
vii. Any one control point can affect the shape of at most ꞌdꞌ curve sections.
A B-Spline curve lies within the convex hull of at most ꞌd + 1ꞌ control points, so
that B-Splines are tightly bound to the input positions. For any value of ‘u’ in the
interval from knot value ud – 1 to un + 1, the sum over all basis functions is 1.
a) UNIFORM, PERIODIC B-SPLINES:
When the spacing between knot values is constant, the resulting curve is
called a uniform B-Spline. Example: We can set up a uniform knot vector
as: {-1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0}. Often knot values are normalized
to the range between ‘0’ and ‘1’ as in: {0.0, 0.2, 0.4, 0.6, 0.8, 1.0}.
Σ Bk, d(u) = 1 --- (3)
k = 0
n
3
Local Modification of a B-Spline Curve changing one of the control points in
(a) produces curve, (b) which is modified only in the neighborhood of the
altered control point.
(a) (b)
212
It is convenient in many applications to set up uniform knot values with a
separation of ‘1’ and a starting value of ‘0’. The following knot vector is an
example of this scheme.
B0, 3(u) = {0, 1, 2, 3, 4, 5, 6, 7}
Uniform B-Splines have periodic blending functions. That is: for given
value of ꞌnꞌ and ꞌdꞌ, all blending functions have the same shape. Each
0
54321 6
1
0.2
0.4
0.6
0.8
(u)
B0, 3(u)
0
54321 6
1
0.2
0.4
0.6
0.8
(u)
B1, 3(u)
0
54321 6
1
0.2
0.4
0.6
0.8
(u)
B2, 3(u)
0
54321 6
1
0.2
0.4
0.6
0.8
(u)
B3, 3(u)
[Periodic B-Splines blending functions n = d = 3 and a uniform, integer knot vector]
213
successive blending function is simply a shifted version of the previous
function:
Bk, d(u) = Bk + 1, d(u + ∆u) = Bk + 2, d(u + ∆u) --- (4)
Where ∆u = interval between adjacent knot values.
b) UNIFORM, QUADRATIC B-SPLINES:
Example: illustrate the calculation of B-Spline blending functions for a
uniform integer knot vector, we select parameter values d = n = 3. The knot
values:- {0, 1, 2, 3, 4, 5, 6} and the range of parameter ‘u’ is from 0 to 6,
with n + d = 6 subintervals.
Each of the 4 blending functions spans d = 3 subintervals of the total
range of ‘u’. Using the recurrence relations equation - (2), we obtain the first
blending function as:
We obtain the next periodic blending function using relationship - (4),
substituting u – 1 for ‘u’ in B0, 3 and shifting the staring positions up by 1:
B0, 3(u) = 1/2u2
, for 0 ≤ u < 1
1/2u(2 – u) + 1/2(u – 1)(3 – u), for 1 ≤ u < 2
1/2(3 – u)2
, for 2 ≤ u < 3
B1, 3(u) = 1/2(u – 1)2
, for 1 ≤ u < 2
1/2(u – 1)(3 – u) + 1/2(u – 2)(4 – u), for 2 ≤ u < 3
1/2(4 – u)2
, for 3 ≤ u < 4
214
Similarly, the remaining two periodic functions are obtained by
successively shifting B1, 3 to the right:
A plot of the four periodic, quadratic blending functions is given in the
figure, which demonstrates the local features of B-Splines. The first control
point is multiplied by blending function B0, 3(u). So, changing the position of
the first control point only affects the shape of the curve upto u = 3.
Similarly, the last control point influences the shape of the spline curve in
the interval where B3, 3 is defined.
The range of the resulting polynomial curve is from 2 to 4, we can
determine the starting and ending positions of the curve by evaluating the
blending functions at these points to obtain:
Pstart = 1/2(P0 + P1), Pend = 1/2(P2 + P3)
Thus, the curve starts at the mid position between the first two control
points and ends at the mid position between the last control points.
B2, 3(u) = 1/2(u – 2)2
, for 2 ≤ u < 3
1/2(u – 2)(4 – u) + 1/2(u – 3)(5 – u), for 3 ≤ u < 4
1/2(5 – u)2
, for 4 ≤ u < 5
B3, 3(u) = 1/2(u – 3)2
, for 3 ≤ u < 4
1/2(u – 3)(5 – u) + 1/2(u – 4)(6 – u), for 4 ≤ u < 5
1/2(6 – u)2
, for 5 ≤ u < 6
215
We can also determine the parametric derivatives at the starting and
ending positions of the curve. Taking the derivatives of the blending
functions and substituting the endpoints values for parameter u, we find that:
Pꞌstart = P1 – P0, Pꞌend = P3 – P2
The parametric slope of the curve at the start position is parallel to the
line joining the last two control points.
General expressions for the boundary conditions for periodic B-Splines
can be obtained by re-parameterizing the blending functions. So that
parameter ‘u’ is mapped onto the unit interval from 0 to 1. Beginning and
ending conditions are then obtained at u = 0 and u = 1.
c) CUBIC, PERIODIC B-SPLINES:
Since cubic, periodic B-Splines are commonly used in graphics packages,
we consider the formulation for this class of splines.
Periodic Splines are particularly useful for generating certain closed
curves. E.g.: The closed curve can be generated in sections by cyclically
specifying four of the six control points shown at each step. If any three
consecutive control points are identical, the curve passes through that co-
ordinate position.
For cubic, d = 4 and each blending function spans four subintervals of
the total range of ‘u’. If we are to fit the cubic to four control points, then we
could use the integer knot vector: {0, 1, 2, 3, 4, 5, 6, 7} and the recurrence
relations – equation – (2) to obtain the periodic blending functions, as we did
in the last section for quadratic periodic B-Splines.
216
This is an alternate formulation for periodic
cubic B-Splines. We start with the boundary
conditions and obtain the blending functions
normalized to the internal 0 ≤ u ≤ 1. Using
this formulation, we can also easily obtain
the characteristic matrix. The boundary
conditions for periodic cubic B-Splines with
four consecutive control points, labeled P0,
P1, P2 and P3 are:
The B-Splines curve section starts at a position near P1 and ends at a
position near P2. A matrix formulation for cubic periodic B-Splines with
four control points can then be written as:
Where, the B-Spline matrix for periodic cubic polynomials i.e.:
P(0) = 1/6(P0 +4P1 + P2), Pꞌ(0) = 1/2(P2 - P0)
P(1) = 1/6(P1 +4P2 + P3), Pꞌ(1) = 1/2(P3 – P1)
--- (1)
P0
P1
P3
P2
P5 P4
P2
P(u) = u3 MB
P0
P1
P3
u2
u 1 --- (2)
1
0
0
0
MB =
-1
3
-3
1
-3
3
3
1
3
-6
0
4
--- (3)1/6
217
This matrix can be obtained by solving for the coefficients in a general cubic
polynomial expression using the specified four boundary condition.
We can also modify the B-Spline equations to include tension parameter 't'. The
periodic, cubic B-Spline with tension matrix then has the form:
Which reduces to MB, when t = 1.
We obtain the periodic, cubic B-Spline blending functions over the
parameter range from 0 to 1 by expanding the matrix representation into
polynomial form.
E.g.: For the tension value t = 1, we have:
d) OPEN UNIFORM B-SPLINES:
This class of B-Splines is a cross between uniform B-Splines is a cross
between uniform B-Splines and non-uniform B-Splines. Sometimes, it is
treated as a special type of uniform B-Spline and sometimes it is considered
to be in the non-uniform B-Spline classification.
1
0
0
0
MBt =
- t
3t
- 3t
t
9t - 12
18 – 15t
3t
t
12 – 9t
12t - 18
0
6 – 2t
--- (4)1/6
B0, 3(u) = 1/6(1 – u)3
, 0 ≤ u ≤ 1, B1, 3(u) = 1/6(3u3
– 6u2
+ u)
B2, 3(u) = 1/6(– 3u3
+ 3u2
+ 3u + 1) and B3, 3(u) = 1/6u3 --- (1)
218
For the open uniform B-Splines or open B-Splines, the knot spacing is
uniform except at the ends where knot values are repeated ꞌdꞌ times.
Following are two examples of open uniform, integer knot vectors, each
with a starting value of 0: {0, 0, 1, 2, 3, 3}, for d = 2 and n = 3 and {0, 0, 0,
0, 1, 2, 2, 2, 2}, for d = 4 and n = 4. We can normalize these knot vectors to
the unit interval from 0 to 1:
{0, 0, 0.33, 0.67, 1, 1} for d = 2 and n = 3.
{0, 0, 0, 0, 0.5, 1, 1, 1, 1}, for d = 4 and n = 4.
For any values of parameter ꞌdꞌ and ‘n’, we can generate an open uniform
knot vector with integer values using the calculations:
For values of ‘j’ ranging from 0 to n + d. With this assignment, the first
ꞌdꞌ knots are assigned the value o and the last ꞌdꞌ knots have the value n – d +
2.
Open uniform B-Splines have characteristics that are very similar to
Bezier Splines. In fact, when d = n + 1, open B-Splines reduce to Bezier
Splines and all knot values are either 0 or 1.
Example: With a cubic, open B-Spline (d = 4) and 4 control points, the knot
vector is: {0, 0, 0, 0, 1, 1, 1, 1, the polynomial curve for an open B-Spline
passes through the first and last control points. The slope of the parametric
uj = 0, for 0 ≤ j < d
j – d + 1, for, d ≤ j ≤ n --- (1)
n – d + 2, for j > n
219
curves at the 1st
control point is parallel to the line connecting the 1st
two
control points and the parametric slope at the last control point is parallel to
the line connecting the last 2 control points.
e) OPEN UNIFORM, QUADRATIC B-SPLINES:
From the conditions – (1) with d = 3 and n = 4 (five control points), we
obtain the following 8 values for the knot vector: {u1, u2, u3, u4, u5, u6, u7} =
{0, 0, 0, 1, 2, 3, 3, 3}. The total range of ‘u’ is divided into seven
subintervals, and each of the five blending functions Bk, 3 is defined over 3
subintervals, starting at knot position ‘uk’. So, B0, 3 is defined from u0 = 0 to
u3 = 1. B1, 3 is defined from u1 = 0 to u4 =3 and B4, 3 is defined from u4 = 2
and u7 = 3. Explicit polynomial expressions are obtained for the blending
functions from recurrence relation – (2) as:
B0, 3(u) = (1 – u)2
, 0 ≤ u ≤ 1
B1, 3(u) = 1/2u(u – 3u), for 0 ≤ u < 1
1/2(2 – u)2
, for 1 ≤ u < 2
B2, 3(u) = 1/2u2
, for 0 ≤ u < 1
1/2u(2 – u) + 1/2(u – 1)(3 – u), for 1 ≤ u < 2
1/2(3 – u)2
, for 2 ≤ u < 3
B3, 3(u) = 1/2(u – 1)2
, for 1 ≤ u < 2
1/2(3 – u)(3u – 5), for 2 ≤ u < 3
B4, 3(u) = (u – 2)2
, 2 ≤ u < 3
220
Here, the shapes of these five blending functions are given. The local
features of B-Splines are again demonstrated Blending function B0, 3 is
non-zero only in the sub-internal from 0 to 1. So, the first control point
influences the curve only in this interval. Similarly, function B4, 3 is zero
outside the interval from 2 to 3 and the position of the last control point does
not affect the shape of the beginning and middle parts of the curve.
0
2.50
21.510.5 3
1
0.2
0.4
0.6
0.8
(u)
B0, 3(u)
0
2.50
21.510.5 3
1
0.2
0.4
0.6
0.8
(u)
B1, 3(u)
0
2.50
21.510.5 3
1
0.2
0.4
0.6
0.8
(u)
B2, 3(u)
0
2.50
21.510.5 3
1
0.2
0.4
0.6
0.8
(u)
B3, 3(u)
221
f) NON-UNIFORM B-SPLINES:
For this class of splines, we can specify any values and intervals for the
knot vector. With non-uniform B-Splines, we can choose multiple interval
knot values and unequal spacing between the knot values.
E.g.: {0, 1, 2, 3, 3, 4}, {0, 2, 2, 3, 3, 6}, {0, 0, 0, 1, 1, 3, 3, 3} and {0, 0.2,
0.6, 0.9, 1.0}.
Non-uniform B-Splines provide increased flexibility in controlling a
curve shape. With unequally spaced intervals in the knot vector, we obtain
different shapes for the blending functions in different intervals, which can
be used to adjust spline shapes. By increasing knot multiplicity, we produce
subtle variations in curve shape and even introduce discontinues. Multiple
knot values also reduce the continuity by 1 for each repeat of a particular
value.
We obtain the blending functions for non-uniform B-Spline using
methods similar to those discussed for uniform and open B-Splines. Given, a
0
2.50
21.510.5 3
1
0.2
0.4
0.6
0.8
(u)
B4, 3(u)
222
set of n + 1 control points, we set the degree of the polynomial and select the
knot values. Then using the recurrence relations, we could either obtain the
set of blending functions or evaluate curve positions directly for the display
of the curve.
B-SPLINE SURFACES:
Formulation of a B-Spline surface is similar to that of Bezier Splines. We can
obtain a vector point function over a B-Spline blending functions in the form:
Here the vector values for Pk1.k2 specify positions of (n1 + 1) by (n2 + 1) control
points.
B-Splines surfaces exhibit the same properties are those of their component B-
Spline curves. A surface can be constructed from selected values for parameters
‘d1’ and d2 and from the specified knot vectors.
BEZIER CURVES:
The concept of Bezier Curve was given by Pierre Bezier. A Bezier Curve is
determined by a defining polygon known as convex hull.
PARAMETRIC REPRESENTATION OF BEZIER CURVE:
A Bezier Curve is represented parametrically by:
P(u, v) = Σ Σ Pk1.k2 . Bk1.d1(u) Bk2.d2(v) --- (1)
k1 = 0
n1 n2
k2 = 0
P(u) = Σ Pk . BEZk, n(u), 0 ≤ u ≤ 1 --- (1)
k = 0
n
223
The Bezier blending function BEZk, n(u) are the Bernstein Polynomials, written
as:
BEZk, n(u) = C(n, k)uk
(1 – u)n – k
--- (2)
Here C(n, k) = binomial coefficients, expressed as: C(n, k) = n!/k!(n – k)!.
Equivalently, we can define Bezier blending functions with the recursive
calculation:
BEZk, n(u) = (1 – u)BEZk, n - 1(u) + uBEZk - 1, n - 1(u), n > k ≥ 1 --- (3)
With BEZk, k = uk
and BEZ0, k= (1 – u)k
Vector equation – (1), represents a set of three parametric equations for the
individual curve co-ordinates:
As a rule, a Bezier Curve is a polynomial of degree one less than the number of
control points used: i) 3 points generate a parabola and ii) 4 points generate a cubic
curve and so on.
x(u) = Σ xk . BEZk, n(u)
k = 0
n
y(u) = Σ yk . BEZk, n(u)
k = 0
n
z(u) = Σ zk . BEZk, n(u)
k = 0
n
--- (4)
(a)
p1
p0 p2
(b)
p1
p0
p2
p3
(c)
p1
p0
p2
p3
224
Efficient methods for determining co-ordinate positions along a Bezier Curve
can be set up using recursive calculation. Example: Successive binomial
coefficients can be calculated as:
C(n, k) = n – k + 1/k C(n, k – 1) for n ≥ k
PROPERTIES OF BEZEIR CURVES:
i) It always passes through the first and last control points that is, the
boundary conditions at the 2 ends of the curve are:
P(0) = P0 and P(1) = Pn --- (1)
ii) Values of the parametric first derivatives of a Bezier Curve at the
endpoints can be calculated from control point co-ordinate as:
Pꞌ(0) = – nP0 + nP1 and Pꞌ(1) = – Pn – 1 + nPn --- (2)
Thus, the slope at the beginning of the curve is along the line joining the first
two control points and the slope at the end of the curve is along the line
joining the last 2 endpoints.
iii) The Parametric second derivatives of a Bezier Curve at the endpoints are
calculated as:
(d)
p1
p0
p2
p3
(e)
p1
p0
p2
p3
p4
225
Another important property of any Bezier Curve is that it lies within the
convex hull of the control points. This follows from the properties of Bezier
blending functions. They are all positive and their sum is always 1. That is:
So, that any curve position is simply the weighted sum of the control point
positions. The convex-hull property for a Bezier Curve ensures that the
polynomial smoothly follows the control points without erratic oscillations.
CUBIC BEZIER CURVES:
Cubic Bezier curves are generated with four control points. The 4 blending
functions for cubic Bezier curves obtained by substituting n = 3 into the Bezier
blending functions are:
The form of the blending functions determine how the control points influence
the shape of the curve for values of parameter ‘u’ over the range from 0 to 1. At u
= 0, the only non-zero blending function is BEZ0, 3 which at the value 1. At u = 1,
Σ BEZk, n(u) = 1 --- (4)
k = 0
n
BEZ0, 3(u) = (1 – u)3
BEZ1, 3(u) = 3u(1 – u)2
BEZ2, 3(u) = 3u2
(1 – u)
BEZ3, 3(u) = u3
--- (1)
Pꞌꞌ(0) = n(n – 1)[(P2 – P1) – (P1 – P0)]
Pꞌꞌ(1) = n (n – 1) [(Pn – 2 – Pn – 1) – (Pn - 1 – Pn)]
--- (3)
226
the only non-zero blending function is BEZ3, 3 with a value of 1 at that point. Thus
the cubic Bezier curve will always pass through control points ‘P0’ and ‘P3’.
The other functions BEZ1, 3 and BEZ2, 3 influence the shape of the curve at
intermediate values of parameter ‘u’, so that the resulting curve tends toward
points P1 and P2. Blending function BEZ1, 3 is maximum at u = 1/3 and BEZ2, 3 is
maximum at u = 2/3.
Each of the four blending functions is non-zero over the entire range of
parameter ‘u’. So the Bezier curves don’t allow for local control of the curve
shape. If we decide to reposition any one of the control points, the entire curve will
be affected.
At the end positions of the cubic Bezier curve, the parametric first derivatives
are: Pꞌ(0) = 3(P1 – P0), Pꞌ(1) = 3(P3 – P2) and the parametric second derivatives
are: Pꞌꞌ(0) = 6(P0 – 2P1 + P2), Pꞌꞌ(1) = 6(P1 – 2P2 + P3). We can use these
expressions for the parametric derivatives to construct piecewise curves with C1
or
C2
continuity between sections.
By expanding the polynomial expressions for the blending functions, we can
write the cubic Bezier point function in the matrix form:
--- (2)
P0
P1
P2
P3
u3
u2
u 1P(u) = MBEZ
227
Where Bezier Matrix is:
We could also introduce additional parameters, to allow adjustment of curve
“tension” and “bias”, as we did with the interpolating splines. But the more useful
B-Splines, as well as B-Splines, provide this capability.
BEZIER SURFACES:
Two sets of orthogonal Bezier Curves can be used to design an object surface
by specifying by an input mesh of control points. The parametric vector function
for the Bezier Surface is formed as the Cartesian product of Bezier blending
functions:
With Pj, k specifying the location of the (m + 1) by (n + 1) control points.
Bezier Surfaces have the same properties as Bezier Curves and they provide a
convenient method for interactive design applications.
For each surface patch, we can select a mesh of control points in the xy
“ground” plane then we choose elevations above the ground plane for the z-
coordinates values of the control points. Patches can then be pieced together using
the boundary constraints.
P(u, v) = Σ Σ Pj, k BEZj, m(v)BEZk, n(u) --- (1)
j = 0
m n
k = 0
MBEZ =
-1 3 -3 1
3 -6 3 0
-3 3 0 0
1 0 0 0
--- (3)
228
Example 1: Derive the parametric equation for a cubic Bezier Curve.
For a cubic Bezier curve, n = 3,
=> P(u) = P0BEZ0, 3(u) + P1BEZ1, 3(u) + P2BEZ2, 3(u) + P3BEZ3, 3(u)
BEZk, n(u) = C(n, k)uk
(1 – u)n – k
BEZ0, 3(u) = [3!/0!(3 – 0)!]u0
(1 – u)3
(since, C(n, k) = n!/k!(n – k)!)
= [3 * 2 * 1/1 * (3 * 2 * 1)] * 1 * (1 – u)3
= (1 – u)3
BEZ1, 3(u) = C(3, 1)u1
(1 - u)3 – 1
= [3!/1!(3 – 1)!]u1
(1 – u)2
= [3!/1!(2!)] u1
(1 – u)2
= [3 * 2 * 1/1 * (2 * 1)] * u(1 – u)2
= 3u(1 – u)2
BEZ2, 3(u) = C(3, 2)u2
(1 - u)3 – 2
= [3!/2!(3 – 2)!]u2
(1 – u) = [3!/2!(1!)] u2
(1 – u)
= [3 * 2 * 1/2 * 1 *(1)] * u2
(1 – u) = 3u2
(1 – u)
BEZ3, 3(u) = C(3, 2)u3
(1 - u)3 – 3
= [3!/3!(3 – 3)!]u3
(1 – u )0
= [3!/3!(0!)] u3
(1 – u) 0
= [3 * 2 * 1/3 * 2 * 1 * 1] * u3
* 1 = u3
.
P(u) = Σ Pk BEZk, n(u), 0 ≤ u ≤ 1 => P(u) = Σ Pk BEZk, 3(u), 0 ≤ u ≤ 1
n
k = 0
3
k = 0
229
Hence, P(u) = P0(1 – u)3
+ P13u(1 – u)2
+ P23u2
(1 – u) + P3u3
.
The form of the blending functions determines how the control points influence
the shape of the curve for the values of parameter ꞌtꞌ over the range 0 to 1.
i. At t = 0, the only non-zero blending function is BEZ3, 0 which has
the value 1.
ii. The cubic Bezier curve will always pass through the points P0
and P3.
iii. The other functions BEZ3, 1 and BEZ3, 2 influence the shape of
curve which passes through the intermediate point P1 and P2.
We can write the cubic Bezier point function in matrix form as follows:
BEZ3, 0(u) = (1 – u)3
= -u3
+ 3u2
– 3u + 1
BEZ3, 1(u) = 3u(1 – u)2
= 3u(1 + u2
– 2u) = 3u3
- 6u2
+ 3u + 0
BEZ3, 2(u) = 3u2
(1 – u) = -3u3
+ 3u2
+ 0u + 0
BEZ3, 3(u) = u3
= u3
+ 0u2
+ 0u + 0
P0
P1
P2
P3
u3
u2
u 1P(u) = MBEZ
So, MBEZ =
-1 3 -3 1
3 -6 3 0
-3 3 0 0
1 0 0 0
--- (3)
230
Example 2: Derive all the blending functions for a Bezier Curve with 6 control
points.
Given, n = 6 – 1 = 5, order = 6. Blending function is given as:
BEZn, k(u) = C(n, k)uk
(1 – u)n –
k
=> BEZ5, 0(u) = C(5, 0)u0
(1 – u)5 – 0
= [5!/0!(5 – 0)!]u0
(1 – u)5
= (1 – u)5
(since, C(n, k) = n!/k!(n – k)!)
=> BEZ5, 1(u) = C(5, 1)u1
(1 – u)5 – 1
= [5!/1!(5 – 1)!]u1
(1 – u)4
= [5!/1!(4)!]u1
(1 – u)4
= 5u(1 – u)4
=> BEZ5, 2(u) = C(5, 2)u2
(1 – u)5 – 2
= [5!/2!(5 – 2)!]u2
(1 – u)3
= [5!/2!(3)!]u2
(1 – u)3
= 10u2
(1 – u)3
=> BEZ5, 3(u) = C(5, 3)u3
(1 – u)5 – 3
= [5!/3!(5 – 3)!]u3
(1 – u)2
= [5!/3!(2)!]u3
(1 – u)2
= 10u3
(1 – u)2
=> BEZ5, 4(u) = C(5, 4)u4
(1 – u)5 – 4
= [5!/4!(5 – 4)!]u4
(1 – u) = [5!/4!(1)!]u4
(1 – u)1
= 5u4
(1 – u)
=> BEZ5, 5(u) = C(5, 5)u5
(1 – u)5 – 5
= [5!/5!(5 – 5)!]u5
(1 – u)0
= [5!/5!(0)!]u5
(1 – u)0
= u5
231
Example 3: Given a Bezier Curve with 4 control points P0[1 0], P1[3 3], P2[6 3]
and P4[8 1]. Determine the points lying on the curve for u = 0, 0.2, 0.4, 0.5, 0.7 and
1 and also draw the rough sketch of the curve.
P(u) = P0(1 – u)3
+ P1(3u(1 – u)2
) + P2(3u2
(1 – u)) + P3u3
= [1 0](1 – u)3
+ [3 3](3u(1 – u)2
) + [6 3](3u2
(1 – u)) + [8 1]u3
.
In order to determine any 6 points lying on the curve, any 6 values of ‘u’ have
to be assumed. It has to be in the range 0 ≤ u ≤ 1 and u = 0, 0.2, 0.4, 0.5, 0.7 and 1.
P(0) = P0(1 – 0)3
+ P1(3(0)(1 – 0)2
) + P2(3(0)2
(1 – 0)) + P3(0)3
=> P0 = [1 0].
P(0.2) = P0(1 – 0.2)3
+ P1(3(0.2)(1 – 0.2)2
) + P2(3(0.2)2
(1 – 0.2)) + P3(0.2)3
= [1 0](0.8)3
+ [3 3]( 0.384) + [6 3] (0.096) + [8 1](0.008)
= [1 0](0.512) + [3 3]( 0.384) + [6 3] (0.096) + [8 1](0.008)
= [0.512 0] + [1.512 1.512] + [0.576 0.288] + [0.064 0.008] = [2.304 1.448]
P(0.4) = P0(1 – 0.4)3
+ P1(3(0.4)(0.6)2
) + P2(3(0.4)2
(0.6)) + P3(0.4)3
= [1 0](0.216) + [3 3]( 0.432) + [6 3] (0.288) + [8 1](0.064)
= [0.216 0] + [1.296 1.296] + [1.728 0.864] + [0.512 0.064] = [3.752 2.224]
P(0.5) = P0(1 – 0.5)3
+ P1(3(0.5)(0.5)2
) + P2(3(0.5)2
(0.5)) + P3(0.5)3
= [1 0](0.125) + [3 3]( 0.375) + [6 3] (0.375) + [8 1](0.125)
= [0.125 0] + [1.125 1.125] + [2.25 1.125] + [1 0.125] = [4.5 2.375]
232
P(0.7) = P0(1 – 0.7)3
+ P1(3(0.7)(0.3)2
) + P2(3(0.7)2
(0.3)) + P3(0.3)3
= [1 0](0.027) + [3 3]( 0.189) + [6 3] (0.441) + [8 1](0.343)
= [0.027 0] + [0.567 0.567] + [2.646 1.323] + [2.744 0.343] = [5.984 2.233]
P(1) = P0(1 – 1)3
+ P1(3(1)(1 - 1)2
) + P2(3(1)2
(1 - 1)) + P3(1)3
=> P3 = [8 1]
233
CHAPTER – 11
BASIC ILLUMINATION MODELS:
For calculating light intensities, simplified methods are used. The empirical
models described in this section provide simple and fast methods for calculating
surface intensity at a given point and they produce reasonably good result for most
scenes.
Lighting calculations are based on the optical properties of surfaces, the
background lighting conditions and the light source specifications. Optical
parameters are used to set surface properties, such as glossy, matte, opaque and
transparent. This controls the amount of reflection and absorption of incident light.
All light sources are considered to be point sources, specified with a co-ordinate
position and an intensity value (color).
1. AMBIENT LIGHT:
A surface that is not exposed directly to a light source still will be visible
if nearby objects are illuminated. In our basic illumination model, we can set
a general level of brightness for a scene. This is a simple way to model the
combination of light reflections from various surfaces to produce a uniform
illumination called the ambient light or background light.
Ambient light has no spatial or directional characteristics. The amount of
ambient light incident on each object is a constant for all surfaces and over
all directions.
234
We can set the level for the ambient light in a scene with parameter ‘Ia’
and each surface is then illuminated with this constant value. The resulting
reflected light is a constant for each surface, independent of the viewing
direction and the spatial orientation of the surface.
2. DIFFUSE REFELCTION:
Ambient light reflection is an approximation of global diffuse lighting
effects. Diffuse Reflections are constant over each surface in a scene
independent of the viewing direction. The ratio of light reflected from the
surface to the total incoming light is called the coefficient reflection or
reflexivity.
Reflexivity of white surfaces is near 1 and that back surface near 0. We
can model the diffuse reflections of illumination from a point source in a
similar way. That is: we assume that the diffuse reflections from the surface
are scattered with equal intensity in all directions, independent of the
viewing direction. Such surfaces are sometimes referred to as ideal diffuse
reflectors. They are also called Lambertian Reflectors, since radiated light
energy from any point on the surface is governed by Lambert’s cosine law.
This law states that the radiant energy from any small surface area ‘dA’
in any direction ‘ΦN’ relative to the surface normal is proportional to cosΦN.
The light intensity though depends on the radiant energy per projected area
perpendicular to direction ‘ΦN’ which is dAcosΦN. So, for Lambertian
Reflection the intensity of light is the same over all viewing directions.
235
If ‘IL’ is the intensity of the point light source,
then the diffuse reflection equation for a point
on the surface can be written as:
IL, diff = KdILcosθ --- (1)
If ‘N’ is the unit normal vector to a surface and ‘L’ is the unit direction
vector to the point light source from a position on the surface, then cosθ =
N.L and the diffuse reflection equation for single-point source illumination
is:
IL, diff = KdIL (N.L) --- (2)
The total diffuse reflection equation, using parameter ‘Ka’ is:
Idiff = KaIa + KdIL (N.L) --- (3)
Here both ‘Ka’ and ‘Kd’ depend on surface material properties and are
assigned values in the range from 0 to 1.
3. SPECULAR REFLECTION:
Specular Reflection occurs at the surface of a mirror. The light is
reflected in nearly single direction plastics and many metals have a specular
reflection, which is independent of colors, as all colors are equally reflected.
For specular reflection, light comes in strikes the surface and bounces right
back off. The angle that the reflection beam makes with the surface normal
is called the angle of reflection 0 and equal in magnitude to the angle of
incidence.
Radiant Energy
Direction
dA
ΦN
ΦN
N
236
4. PHONG ILLUMINATION MODEL:
The Phong illumination model is also known as Phong Model. It is used
to set the intensity of specular reflection proportional to cosn
sΦ. Angle ‘Φ’
can be assigned values in the range 0o
to 90o
, so that ‘– cosΦ’ varies from 0
to 1. The value assigned to specular reflection parameter ‘ns’ is determined
by the type of surface that the user wants to display.
A very shiny surface is modeled with a large value for ‘ns’ (say 100 or
more) and smaller values (down to 1) are used for duller surfaces. For
perfect reflection ‘ns’ is infinite. For rough surfaces, such as chalk/cinder
block, ‘ns’ would be assigned value near to 1.
The intensity of specular reflection depends on the material properties of
the surfaces and the angle of incidence as well as other factors such as
polarization and color of incident light.
Users can approximately mode monochromatic specular intensity
variations using a specular reflection coefficient w(θ), for each surface. In
general w(θ) tends to increase as the angle of incidence increases. At θ =
90o, w(θ) = 1 and the entire incident light is reflected. The variation of
specular intensity with angle of incidence is described by Fresnel’s Law of
Reflection. Using the spectral reflection function w(θ), user can write the
Phong specular reflection model as:
Ispec = w(θ)I1cosn
sΦ
Here, I1 is the intensity of light source and Φ is the viewing angle
relative to the specular reflection direction ‘R’.
237
5. COMBINED DIFFUSE AND SPECULAR REFLECTION WITH
MULTIPLE LIGHT SOURCES:
For a single point light source, we can model the combined diffuse and
specular reflection form paint on an illuminated surface as:
I = Idiff + Ispec = KaIa + KdIL(N.L) + KsIL(N.H)ns
--- (1)
If we place more than one point source in a scene, we obtain the light
reflection at any surface point by summing the contributions from the
individual sources:
6. WARN MODEL:
The Warn Model provides a method for simulating studio lighting effects
by controlling light intensity in different directions. Light sources are
modeled as points on a reflecting surface, using the Phong model for the
surface points. Then the intensity in different directions is controlled by
selecting values for the Phong exponent. In addition, light controls such as
“barn doors” and spot lighting used by studio photographers can be
simulated in the Warn Models.
Flaps are used to control the amount of light emitted by a surface in
various directions. Two flaps are provided for each of the x, y and z
directions. Spotlights are used to control the amount of light emitted within a
cone with apex at a point source position.
I = KaIa + Σ ILi[Kd(N.Li) + Ks(N.Hi)ns
--- (2)
n
i = 1
238
7. INTENSITY ATTENUATION:
As radiant energy from a point light source travels through space, its
amplitude is attenuated by the factor 1/d2
, where ꞌdꞌ is the distance that the
light has travelled.
Our simple point source illumination model however does not always
produce realistic pictures, if we use the factor 1/d2
to attenuate intensities.
The factor 1/d2 produces too much intensity variations, when ꞌdꞌ is small and
it produces very little variation when ꞌdꞌ is large.
Graphics packages have compensated for these problems by using
inverse linear or quadratic functions of ꞌdꞌ to attenuate intensities. E.g.: a
general inverse quadratic attenuation function can be set up as:
f(d) = 1/a0 + a1d + a2d2
--- (1)
A user can fiddle with the coefficients a0, a1 and a2 to obtain a variety of
lighting effects for a scene. The value of the constant term ‘a0’ can be
adjusted to prevent f(d) from beginning too large when ꞌdꞌ is very small.
With a given set of attenuation coefficients, we can limit the magnitude of
the attenuation function to 1 with the calculation:
f(d) = min(1, 1/a0 + a1d + a2d2
) --- (2)
Using this function, we can then write our basic illumination model as:
di = distance light travelled from light source ‘i’.
I = KaIa + Σ f(di)ILi[Kd(N.Li) + Ks(N.Hi)ns
--- (2)
n
i = 1
239
8. COLOR CONSIDERATION:
Most graphics displays of realistic scenes are in color. One way to set
surface colors is by specifying the reflectivity coefficients as 3-element
vectors. The diffuse reflection coefficient vector would have RGB
components (KdR, KdG, KdB).
If we want an object to have a blue surface, we select a non-zero value in
the range from 0 to 1, for the blue reflectivity component, KdB, while the red
and green reflectivity components are set to zero (KdR = KdG = 0). Any
non-zero red or green components in the incident light are absorbed, and
only the blue component is reflected. The intensity calculation for this
example reduces to the single expression:
Another method for setting surface color is to specify the components of
diffuse and specular color vectors for each surface, while retaining the
reflectivity coefficients as single-valued constants. For an RGB color
representation, for instance, the components of these two surface-color
vectors can be denoted as: (SdR, SdG, SdB) and (SSR, SSG, SSB). The blue
component of the reflected light is then calculated as:
This approach provides somewhat greater flexibility, since surface-color
parameters can be set independently from reflectivity values.
IB = KaBIaB + Σ fi(d)ILBi[KdB(N.Li) + KsB(N.Hi)ns
--- (1)
n
i = 1
IB = KdSdIaB + Σ fi(d)ILBi[KdSdB(N.Li) + KsSs'B(N.Hi)ns
--- (2)
n
i = 1
240
We can simply represent any component of a color specification with its
spectral wavelength ‘λ’. Intensity calculations can then be expressed as:
9. TRANSPARENCY:
A transparent surface produces both reflected and transmitted light. The
relative contribution of the transmitted light depends on the degree of
transparency of the surface and whether any light sources or illuminated
surfaces are behind the transparent surface.
When a transparent surface is to be modeled, the intensity equations must
be modified to include contributions from light passing through the surface.
Realistic transparency effects are modeled by considering light refraction.
When light is incident upon a transparent surface, part of it is reflected and
part is refracted. Because the speed of light is different in different materials,
the path of the refracted light is different from that of incident light. The
direction of the refracted light specified by the angle of refraction is a
function of the index of refraction of each material and the direction of the
incident light.
Intensity
light
Transparent
object
Light Emission from a transparent surface is in
general a combination of reflected and
transmitted light.
Iλ = KdSdλIaλ + Σ fi(d)ILλi[KdSdλ(N.Li) + KsSsλ(N.Hi)ns
--- (3)
n
i = 1
241
Angle of refraction ‘θr’ is calculated from the angle of incidence ‘θi’, the
index of refraction ‘ηi’ of the incidence material and the index of refraction
‘ηr’ of the refracting material according to Snell’s law:
sinθr = (ηi/ηr) sinθi --- (1)
From Snell’s law, we can obtain the unit transmission vector ‘T’, in
refraction direction ‘θr’ as:
T = ηi/ηr (cosθi - cosθr) N – ηi/ηr L --- (2)
Here, N = unit surface normal, L = unit vector in the direction of light source
and T = transmission vector can be used to locate intersections of the
refraction path with objects behind the transparent surface.
We can combine the transmitted intensity ‘Itrans’ through a surface form a
background object, with the reflected intensity ‘Irefl’ from the transparent
surface using transparency coefficient ‘Kt’. We assign the parameter ‘Kt’, a
value between 0 and 1; specify how much of the background light is to be
transmitted. Total surface intensity is then calculated as:
I = (1 – Kt) Irefl + Kt Itrans --- (3)
The term (1 – Kt) is the opacity factor.
10. SHADOWS:
Hidden surface methods can be used to locate areas where light sources
produce shadows. By applying a hidden-surface method with a light source
242
at the view position, we can determine which surface sections can’t be
“seen” from the light source. These are the shadow areas.
Shadow patterns generated by a hidden-surface method are valid for any
selected viewing position, as long as the light source positions are not
changed.
HALFTONING TECHNIQUES:
Halftoning is a process of breaking up an area of gray into lots of individual
black dots. It is well established function of printing which uses regularly spaced
patterns of small dots. The intensity of dot varies at different levels according to
the picture information. These dots vary in size for the representation of the
intensities where image is light, the dots are small and where the image is dark, the
dots are large.
For better resolution, a single cell is divided into sub-cells constructing patterns
of threshold values called a dither matrix does it.
By the above method, a single dot is capable of representing 5 intensity levels
with better resolution. By this technique pixel can have one of 256 possible
intensity values.
[Division of single cell into
sub-cells]
[2 x 2 Dither Pattern Representing 5 levels of
intensity]
243
HALFTONE APPROXIMATIONS:
In computer graphics, halftone reproductions are approximated using
rectangular pixel regions, called halftone patterns/pixel patterns. The number of
intensity levels that we can display with this method depends on how many pixels
we include in the rectangular grids and how many levels a system can display with
‘n’ by ‘n’ pixels for each grid on a bi-level system, we can represent n2
+ 1
intensity levels.
It shows one way to set up pixel patterns to represent five intensity levels that
could be used with a bi-level system. In pattern 0, all pixels are turned off. In
pattern 1, one pixel is turned on and in pattern 4, all pixels are turned on and an
intensity value ‘I’, in a scene is mapped to a particular pattern according to the
range listed below. Pattern 0 is used for 0 ≤ I < 0.2. Pattern 1 is used for 0.2 ≤ I <
0.4 and Pattern 4 is used for 0.8 ≤ I < 1.0. Similarly, 3 by 3 pixels grids on a bi-
level system, we can display 10 intensity levels.
0
0 ≤ I < 0.2
1
0.2 ≤ I < 0.4
2
0.4 ≤ I < 0.6
3
0.6 ≤ I < 0.8
4
0.8 ≤ I ≤ 1.0
0
0 ≤ I < 0.1
1
0.1 ≤ I < 0.2
2
0.2 ≤ I < 0.3
3
0.3 ≤ I < 0.4
4
0.4 ≤ I < 0.5
5
0.5 ≤ I < 0.6
6 8
0.6 ≤ I < 0.7 0.8 ≤ I < 0.9
9
0.9 ≤ I ≤ 1.0
7
0.7 ≤ I < 0.8
244
For any pixel grid-size, we can represent the pixel patterns for the various
possible intensities with a “mask” of pixel position numbers. E.g.: The following
mask can be used to generate the nine 3 by 3 grid parameters for intensity levels
above 0.
To display a particular intensity with level number ‘k’, we
turn on each pixel whose position number is less than or
equal to ‘k’.
Although the use of ‘n’ by ‘n’ pixel patterns increases the number of intensities
that can be displayed, they reduce the resolution of displayed picture by a factor of
1/n along each of the ‘x’ and ‘y’ axes. Halftone approximations also can be used to
increase the number of intensity options on systems that are capable of displaying
more than 2 intensities per pixel.
DITHERING TECHNIQUES:
The term ‘Dithering’ is used in various contexts. It refers to techniques for
approximating halftones without reducing resolution, as pixel-grid patterns, do.
But the term is also applied to halftone approximation methods using pixel grids
and sometimes it is used to refer to color halftone approximations only.
Random values added to pixel intensities to break up contours are often referred
to as dither noise. Ordered-dither methods generate intensity variations with a one-
to-one mapping of points in a scene to the display pixels. To obtain, n2
intensity
levels, we set up an ‘n’ by ‘n’ dither matrix ‘Dn’, whose elements are distinct
positive integers in the range 0 to n2
- 1.
8 3
5 1
7
2
4 9 6
245
E.g.: we can generate ‘4’ intensity levels and ‘9’ intensity levels with following
matrix:
For a bi-level system, we then determine display intensity values by comparing
input intensities to the matrix elements. Each input intensity is first scaled to the
range 0 ≤ I ≤ n2
. If the intensity ‘I’ is to be applied to screen position (x, y), we
calculate row and column numbers for the dither matrix as:
i = (x mod n) + 1, j = ( y mod n) + 1
if I > Dn(i, j), we turn on the pixel at position (x, y) otherwise the pixel is not
turned on.
Typically, the number of intensity levels is taken to be a multiple of 2 higher-
order dither matrices are then obtained from lower-order matrices with the
recurrence relation:
Assuming n ≥ 4, parameter un/2 is the unity matrix.
E.g.: if ‘D2’ is specified in equation – (1), then recurrence relation yields:
4Dn/2 + D2(1, 1)un/2
4Dn/2 + D2(2, 1)un/2
4Dn/2 + D2(1, 2)un/2
4Dn/2 + D2(2, 2)un/2
--- (3)
7 2
4 0
6
1
3 8 5
D3 = --- (2)
3 1
0 2
D2 = --- (1)
15 7
3 11
13
1
12 4 14
D3 =
5
9
6
0 8 2 10
246
Another method for mapping a picture with ‘m’ by ‘n’ points to display area
with ‘m’ by ‘n’ pixels is error diffusion. Here, the error between an input intensity
value and the displayed pixel intensity level at a given position is dispersed or
diffused to pixel positions to the right and below the current pixel position.
POLYGON RENDERING METHODS/SHADING MODELS FOR
POLYGONS:
We can shade any surface by calculating the surface normal at each visible
point and applying the desired illumination pattern at that point. But this is
expensive, so we would consider more efficient shading models for surfaces
defined by polygons.
1. CONSTANT INTENSITY SHADING:
It is the simplest shading model for a polygon and is also known as flat
shading. This approach applies to single intensity value that is then used to
shade an entire polygon. This approach is valid if several assumptions are true.
i. The light source is at infinity. So it is constant across
the polygon face.
ii. The viewer is at infinity. So it is constant across the
polygon face.
iii. The polygon represents the actual surface being
modeled and is not an approximation to a curved surface.
Even if all these assumptions are not true, we can still reasonably
approximate the surface lighting effects using small polygon faults with flat
shading and calculate the intensity for each fact, say at the center of polygon.
247
2. POLYGON MESH SHADING:
Many objects are curved, rather than polyhedral, yet representing them as a
polygon mesh allows the use of efficient polygon visible surface algorithms.
If each polygonal face is in the mesh is shaded individually, it is easily
distinguished from its neighbors whose orientation is different, producing a
“faceted” appearance. This is true if the polygons are rendered using constant
shading, interpolated shading or even per-pixel illumination calculations,
because two adjacent polygons of different orientation have different intensities
along their borders. At the border between facets, the dark facet looks darker
and the light facet looks lighter.
Macsh banding is caused by later inhibition of the receptors in the eye. The
more light a receptor received the more that receptor inhibits the response of the
receptors adjacent to it. The response of the receptor to light is inhibited by its
adjacent receptors in inverse relation to the distance to the adjacent receptor.
Two basic models for polygon meshes take advantage of the information
provided by adjacent to simulate a smooth surface. That is: a) Gouraud Shading
and b) Phong Shading.
a. GOURAUD SHADING:
It is also called as intensity interpolation shading or color interpolation
shading.
It eliminates intensity discontinues. It extends the concept of interpolated
shading applied to individual polygons by interpolating polygon vertex
illuminated values that take into account the surface being approximated.
248
This process requires that the normal be known for each vertex of the
polygonal mesh. Alternatively, if the vertex normal are not stored with the
mesh and can’t be determined directly from the actual surface, the Gouraud
suggested. We can approximate them by averaging the surface normal of all
polygonal facets sharing each vertex.
Normalized polygon surface normal can be averaged to obtain vertex
normal.
i. If an edge is meant to be visible, then
we find 2 vertex normals, one for
each side of the edge, by averaging
the normals of polygon on each side
of the edge separately.
ii. The next step in Gouraud shading is
to find vertex intensities by using
vertex normals with any desired
illumination model.
iii. Finally, each polygon is shaded by
linear interpolation of vertex
intensities along each edge and then
between edges along each scan-line.
The term Gouraud Shading is often generalized to refer to intensity
interpolation shading of even a single polygon, in isolation or to the
interpolation of arbitrary colors, associated with polygon vertices. The
interpolation along edges can easily be integrated with the scan-line visible
surface algorithm. With each color component, the starting intensity and the
N1
N2
N3
N4
The normal vector is calculated as
the Average of the surface Normals
for each polygon sharing that
vertex.
249
change of intensity for each unit change is ‘y’. A visible span on a scan–line
is filled in by interpolation the intensity values of the two edges bounding
the span.
b. PHONG SHADING:
It is also known as normal-vector interpolating shading, which
interpolates the surface normal vector ‘N’, rather than the intensity.
Interpolation occurs across a polygon span on a scan-line, between starting
and ending normals for the span. These normals are themselves interpolated
along polygon edges from vertex normals that are completed, if necessary
just as in Gouraud shading.
The interpolation along edges can again be done by means of incremental
calculations, with all three components of the normal vector being
incremented for scan-line to scan-line.
At each pixel along a scan-line, the interpolated normal is normalized and
is back mapped into the world co-ordinates system or one isometric to it and
a new intensity calculation is performed using any illumination model.
Normal vector is calculated as:
[Incremental Interpolation of Intensity values along a polygon edge]
La = L1 – (L1 – L2) [y1 – y3/y1 – y2]
Scan-line
Y2
Y1
Y3 LbLpLa
L3L2
L1
Lb = L1 – (L2 – L3) [y1 – y3/y1 – y3]
Lp = Lb – (Lb – La) [yb – yp/yb – ya]
Nv = ΣNk/|ΣNk|, (normal unit vector)
k = 1
n
k = 1
n
250
N = (y – y2/y1– y2)N1 + (y1 – y/y1 – y2)N2 --- (1)
It shows two edge normals and the
normals interpolated from them,
before and after normalization. Phong
shading yields substantial
improvements over Gouraud shading
when such illumination models are
used, because highlights are
reproduced more faithfully.
Phong Shading also requires highlights to be located in a polygon’s
interior whereas Gouraud Shading may miss it entirely. Even with an
illumination model that does not take into account specular reflection, the
results of normal vector interpolation are in general superior to intensity
interpolation, because an approximation to the normal is used at each point.
A polygon surface is rendered using Phong shading by the following
steps:
i. Determine the average unit normal vector at each polygon vertex.
ii. Linearly interpolate the vertex normals over the surface of the polygon.
iii. Apply an illumination model along each scan-line to calculate projected
pixel intensities for the surface points.
ANIMATION:
It is a technique of building progressive images and running it in a sequence to
create an effect of motion. In animation, for a moving sequence, different
Pa P2
P1P0
[Normal Vector Implementation]
10
N~
Pb
N~ N~ N~ N~
251
stationary images are drawn and each of them shows some advancement of motion
form the previous one.
These images are called frames. These progressively build frames are rapidly
moved in front of human eye and this is perceived as the motion TV/Video plays
30 frames every second. It is the speed with which each frame is replaced by the
next one that makes the image appear to blend smoothly into movement.
ANIMATION TECHNIQUES:
1. CEL ANIMATION:
This is the animation technique which uses a series of different graphics
on each frame of a movie film. The term ‘cel’ is derived from the clear
celluloid sheets that were used for drawing each frame.
Cel Animation artwork begins with key frames i.e.: the 1st
and last frame
of an action. E.g.: When an animated figure of a child walks across the
screen, he balances the weight of his entire body on one foot and then other
in a series of falls and recoveries, with opposite foot and leg catching upto
balance the body.
Thus, the 1st
key frame to portray a single step might be child pitching his
body weight forward off the left foot leg, while his center of gravity shifts
forward; the feet close together and the appears to be falling. The last key
frame might be the right foot and leg catching the body’s fall, with the center
of gravity now centered, between the outstretched stride and the left and
right feet positioned for apart.
252
The series of frames in between the key-frames are drawn in a process
called Tweening. Tweening is the process of calculating the number of
frames between key-frame and the patch the action takes and then actually
sketching into a cel with pencil the series of progressively different outlines.
As tweening advances, the action sequence is checked by flipping
through the frames. The penciled frames are brought together and then
actually filmed as a pencil test to check smoothness, continuity and timing.
When the pencil frames are satisfactory they are permanently inked and
acrylic colors are painted on the same.
2. COMPUTER ANIMATION:
Computer Animation programs implement the same logic and concept as
cel animation, using layer key-frame and tweening techniques. The
developer can set his own frame rates on the computer but it will depend on
the speed and power of display platform and hardware.
MORPHING:
It is an effect in which one image changes into another. Morphing applications
and modeling tools offering the morphing effect can transition not only between
still images but often between moving images as well.
Morphing is applied as follows:
i. First of all, 2 images are supplied to the morphing application
ii. The morphing application selects key points on both the images. Setting of
key points is crucial for smooth transition between two images.
253
iii. Transformations are applied on the key points of first image to change it to
the corresponding key point of second image.
Morphed images are built at a rate of 8 frames per second, with each transition
taking a total of 4 seconds and the numbers of key points are held to a minimum to
shorten the rendering time.
Some product offering morphing features are:
i. Avoid’s Elastic Reality
ii. Gryphon Software’s morph.
iii. Image Ware’s Morph Wizard
iv. North Coast’s photo-morph.
v. Black Belt’s Win Images.
vi. Human Software’s squizz.
vii. Meta Tool’s Digital Morph.
INTRODUCTION TO HIERARCHICAL MODELING WITH
STRUCTURES:
A hierarchical model of a system can be created with structures by nesting the
structures into one another to form a tree organization. Each structure is placed into
the hierarchy properly into the overall model.
The various graphical symbols to be used in an application are each defined in
an independent co-ordinate reference called the modeling co-ordinate system.
Modeling co-ordinates are also referred to as local co-ordinates or master co-
ordinates.
254
Transformations applied to the modeling co-ordinate definitions of symbols are
referred to as modeling transformations, which involve translation, rotation and
scaling to position a symbol in world co-ordinates, but other transformations might
also be used in some applications.
The modeling package co-ordinates individually do transformations to construct
a homogeneous co-ordinate modeling transformation matrix ‘MT’. An instance of
a symbol in world co-ordinates is then produced by applying MT’ to modeling co-
ordinate positions (Pmc) to generate corresponding world co-ordinate positions
(Pwc). That is: Pwc = MT . Pmc
DISPLAYING LIGHT INTENSITIES:
Values of intensity calculated by illumination model must be converted to one
of the allowable intensity levels for the particular graphics system in use. Some
systems are capable of displaying several intensity levels while others are capable
of only two levels for each pixel (on or off).
In 1st
case, we convert intensities from the lighting model into one of the
available levels for storage in the frame buffer. For bi-level systems, we can
convert intensities into halftone patterns.
ASSIGNING INTENSITY LEVELS:
If the ratio of two intensities is the same as the ratio of two other intensities, we
perceive the difference between each pair of intensities to be the same.
E.g.: We perceive the difference between intensities 0.20 and 0.22 to be the
same as the difference between 0.80 and 0.88. So, to display n + 1 successive
255
intensity levels with equal perceived brightness, the intensity levels in the monitor
should be spaced so that the ratio of successive intensities is constant:
I1/I0 = I2/I1 = … = In/In – 1 = r --- (1)
Here, we denote the lowest level that can be displayed on the monitor as ‘I0’
and the highest as ‘In’.
Any intermediate intensity can then be expressed in terms of I0 as:
IK = rK
I0 --- (2)
We can calculate the value of ‘r’ given the values of ‘I0’ and ‘n’ for a particular
system by substituting K = n in the proceeding expression. Since In = 1, we have:
r = (1/I0)1/n
--- (3)
So, the calculation for ‘IK’ can be rewritten as:
IK = I0(n – K)/n --- (4)
E.g.: if I0 = 1/8 for a system with n = 3, we have r = 2 and the 4 intensity values
are 1/8, 1/4, 1/2 and 1.
With a color system, we set up intensity levels for each component of the color
model. Using the RGB model, we can related the blue component of intensity at
level ‘K’ to the lowest attainable blue value, as equation – (2). So,
IB = rB
K
IBO --- (5), where rB = (1/IBO)1/n
--- (6)
256
GAMMA CORRECTION AND VIDEO LOOKUP TABLES:
Another problem associated with the display of calculated intensities is the non-
linearity of display device.
A video monitor is a non-linear device. If we set the voltages for the electron
gun proportional to the linear pixel values, the displayed intensities will be shifted
according to the monitor response curve.
To correct for monitor, non-linearity, graphics
systems use a video looking table that adjusts the
linear pixel values. The monitor response curve is
described by the exponential function:
I = aVγ
--- (7)
Here, I = displayed intensity, V = input voltage.
ꞌaꞌ, ꞌγꞌ depend on the characteristics of the monitor
used in graphics system.
If we want to display a particular intensity value ‘I’, the correct voltage value to
produce this intensity is:
V = (I/a)1/γ
--- (8)
This calculation referred to as Gamma correction of intensity.
Monitor gamma values are typically between 2.0 and 3.0. The National
Television System Committee (NTSC) signal standard is γ = 2.2.
1.0
[Normalized electron
gun voltage]
1.00.5
Intensity
0.5
257
We can combine gamma correction with
logarithmic intensity mapping to produce a lookup
table that contains both conversions. If ‘I’ is an input
intensity value from an illumination model.
We first locate the nearest intensity ‘IK’ from a table
of values created with equation - (1) or equation - (4).
Alternatively we could determine the level number for this intensity value with
the calculation:
K = round[logr(I/I0)] --- (9)
Then we compute the intensity value at this level using equation – (4). Once we
have the intensity value ‘IK’, we can calculate the electron-gun voltage:
VK = (IK/a)Vγ
--- (10)
Values ‘VK’ can then be placed in the lookup tables and values for ‘K’ would be
stored in the frame buffer pixel positions.
If a particular system has no lookup table, computed values for ‘VK’ can be
stored directly in the frame buffer.
The combined conversion to a logarithmic intensity scale followed by
calculation of the ‘VK’ using equation – (10) is also sometimes referred to as
Gamma correction.
1.0
Norma
lized
electro
n gun
voltag
e
1.00.5
0
0.5 γ = 2.2
258
DISPLAYING CONTINUOUS – TONE IMAGES:
High quality computer graphics systems generally provide 256 – intensity levels
for each color component, but acceptable displays can be obtained for many
applications with fewer levels.
A 4-level system provides minimum shading capability for continuous – tone
images, while photo realistic images can be generated on system that are capable
of from 32 to 256 intensity levels per pixel.
When a small number of intensity levels are used to reproduce a continuous –
tone image, the borders between the different intensity regions called counters are
clearly visible.
Using four intensity levels, we begin to identify the original shading patterns,
but the contouring effects are glaring. With 8 intensity levels, contouring effects
are still obvious, but we begin to have a better indication of the original shading.

More Related Content

PPTX
Output primitives in Computer Graphics
PPT
Polygon clipping
PPTX
Computer Graphics
PPTX
Attributes of output primitives( curve attributes & area fill attributes)
PPTX
Distributed DBMS - Unit 1 - Introduction
PDF
Natural language processing (nlp)
PPTX
Watershed Segmentation Image Processing
PDF
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Output primitives in Computer Graphics
Polygon clipping
Computer Graphics
Attributes of output primitives( curve attributes & area fill attributes)
Distributed DBMS - Unit 1 - Introduction
Natural language processing (nlp)
Watershed Segmentation Image Processing
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...

What's hot (20)

PPTX
Video display devices
PPT
2D transformation (Computer Graphics)
PPTX
Introduction to computer graphics
PDF
Unit 3
PPTX
Character generation techniques
PPTX
Line Drawing Algorithms - Computer Graphics - Notes
PPTX
ANIMATION SEQUENCE
PPTX
Raster animation
PPT
Line drawing algo.
PDF
3D Transformation
PPTX
Color Models Computer Graphics
PPTX
Polygons - Computer Graphics - Notes
PPTX
Computer animation Computer Graphics
PPT
applications of computer graphics
PPT
Quadric surfaces
PPTX
Cohen-Sutherland Line Clipping Algorithm
PPTX
Bezier curve & B spline curve
PPT
Computer animation
PPT
Visible surface detection in computer graphic
PPTX
Attributes of Output Primitives
Video display devices
2D transformation (Computer Graphics)
Introduction to computer graphics
Unit 3
Character generation techniques
Line Drawing Algorithms - Computer Graphics - Notes
ANIMATION SEQUENCE
Raster animation
Line drawing algo.
3D Transformation
Color Models Computer Graphics
Polygons - Computer Graphics - Notes
Computer animation Computer Graphics
applications of computer graphics
Quadric surfaces
Cohen-Sutherland Line Clipping Algorithm
Bezier curve & B spline curve
Computer animation
Visible surface detection in computer graphic
Attributes of Output Primitives
Ad

Similar to Computer graphics notes (20)

DOCX
Graphics file
PPTX
Computer Graphics definition types and application .pptx
PDF
GV Computing - Lesson 1 (Intro to graphics and visual computing).pdf
DOCX
Computer Graphics Practical
PDF
CG Module-01 Ntes Search Creators and .pdf
PPT
computer graphics unit 1.ppt
PDF
Chapter 1 Computer graphics by Kushal Bhattarai
PDF
COMPUTER GRAPHICS AND VISUALIZATION :MODULE-1 notes [BCG402-CG&V].pdf
PPTX
introduction to computer graphics unit 1
PDF
topic_- introduction of computer graphics.
PDF
Computer graphics by bahadar sher
PPT
Lecture applications of cg
PPT
applications.ppt
PPTX
L1-Introduction to CG aaaaaaaaaaaaaaa.pptx
PDF
PPTX
computer graphics unit 1-I.pptx
PDF
Computer graphics Applications and System Overview
PPT
Applications of cg
PDF
Graphics pdf
Graphics file
Computer Graphics definition types and application .pptx
GV Computing - Lesson 1 (Intro to graphics and visual computing).pdf
Computer Graphics Practical
CG Module-01 Ntes Search Creators and .pdf
computer graphics unit 1.ppt
Chapter 1 Computer graphics by Kushal Bhattarai
COMPUTER GRAPHICS AND VISUALIZATION :MODULE-1 notes [BCG402-CG&V].pdf
introduction to computer graphics unit 1
topic_- introduction of computer graphics.
Computer graphics by bahadar sher
Lecture applications of cg
applications.ppt
L1-Introduction to CG aaaaaaaaaaaaaaa.pptx
computer graphics unit 1-I.pptx
Computer graphics Applications and System Overview
Applications of cg
Graphics pdf
Ad

More from smruti sarangi (7)

PDF
Daa notes 3
PDF
Daa notes 2
PDF
Daa notes 1
PDF
Software engineering study materials
PPTX
Data structure using c module 1
PPTX
Data structure using c module 2
PPTX
Data structure using c module 3
Daa notes 3
Daa notes 2
Daa notes 1
Software engineering study materials
Data structure using c module 1
Data structure using c module 2
Data structure using c module 3

Recently uploaded (20)

PDF
RMMM.pdf make it easy to upload and study
PDF
Business Ethics Teaching Materials for college
PPTX
Pharma ospi slides which help in ospi learning
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
master seminar digital applications in india
PDF
Insiders guide to clinical Medicine.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Institutional Correction lecture only . . .
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
RMMM.pdf make it easy to upload and study
Business Ethics Teaching Materials for college
Pharma ospi slides which help in ospi learning
O7-L3 Supply Chain Operations - ICLT Program
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
2.FourierTransform-ShortQuestionswithAnswers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Microbial disease of the cardiovascular and lymphatic systems
master seminar digital applications in india
Insiders guide to clinical Medicine.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
STATICS OF THE RIGID BODIES Hibbelers.pdf
TR - Agricultural Crops Production NC III.pdf
Institutional Correction lecture only . . .
VCE English Exam - Section C Student Revision Booklet
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Microbial diseases, their pathogenesis and prophylaxis

Computer graphics notes

  • 1. Computer Graphics By: Smruti Smaraki Sarangi Assistant Professor IMS Unison University, Dehradun
  • 2. 1 C O N T E N T S Sl.no Chapter Page 1 Introduction to graphics, and its application 2-6 2 Video display devices: CRT, Flat panel display, Raster Scan system, Random scan system, Input and Output devices, Graphics software and Functions, GUI. 7-29 3 Line drawing algorithms, Circle generating and ellipse generating algorithms, Filled area primitives: flood-fill, boundary-fill and scan-line polygon fill algorithm and antialiasing. 30-59 4 Line attributes, Curve attributes, Area-fill attributes, Character attributes, Bundled and Marker Attributes 60-75 5 2D basic transformation, 2D composite transformation, Matrix representation and homogeneous co-ordinate, Transformation between co- ordinate system and Affine transformation 76-102 6 Viewing Pipeline, View Co-ordinate reference frame, Window to viewport Transformation, Clipping and Types of Clipping 103-125 7 Representation of point, 3D Transformation and its types 126-149 8 3D Viewing, Projection and its types, Viewing Pipeline. 3D Clipping and Viewport Clipping 150-171 9 Visible surface detection algorithms (back-face detection, z-buffer, a-buffer, scan-line method, depths sorting method) Ray-tracing algorithm and its surface intersection calculation and ray casting method. 172-197 10 Curved line and surfaces, BSP Trees and Octree, Spline Representation and specifications, B-Spline curves and surfaces, Bezier curve and surfaces 198-232 11 Basic Illumination Models, Halftoning and Dithering Techniques, Polygon Rendering Methods, Animation Techniques and Morphing, Hierarchical modeling structures, Displaying light Intensities and continuous tone image 233-258
  • 3. 2 CHAPTER -1 COMPUTER GRAPHICS: Computer graphics are graphics created using computers and more generally, the representation and manipulation of image data by a computer with help from specialized software and hardware. The development of computer graphics has made computers easier to interact with, and better for understanding and interpreting many types of data. Developments in computer graphics have a profound impact on many types of media and have revolutionized animation, movies and the video game industry. APPLICATION OF COMPUTER GRAPHICS: Computers have become a powerful tool for the rapid and economical production of pictures. Advances in computer technology have made interactive computer graphics a practical tool. Today, computer graphics is used in the areas as science, engineering, medicine, business, industry, government, art, entertainment, advertising, education and training. I. COMPUTER AIDED DESIGN (CAD): A major use of computer graphics is in design purposes, generally referred to as CAD. Computer Aided Design methods are now routinely used in the design of buildings, automobiles, aircraft, watercraft, spacecraft, computers, text-tiles and many other products. For some design applications, objects are first displayed in wireframe outline from that shows the overall shapes. Software packages for CAD
  • 4. 3 applications typically provide the designer with the multi-window environment. Animations are often used in CAD applications. Realistic displays of architectural designs permit both architect and their clients to study the appearance of a single building or a group of buildings. With virtual reality systems, designers can even go for a simulated “walk” through the room or around the outsides of buildings to better appreciate to overall effect of a particular design. In addition to realistic exterior building displays architecture, CAD packages also provide facilities for experimenting with 3-dimensional interior layouts and lighting. II. PRESENTATION GRAPHICS: It is used to produce illustrations for reports or to generate 35 mm slides or transparencies for use with projectors. It is commonly used in summarize financial, statistical, mathematics, scientific and economic data for research reports, managerial reports, consumer information, bulletins and other types of reports. E.g.: Bar Charts, Line Graphs, Surface Graphs and Pie Charts. Three dimensional graphs are used simply for effect they can provide a more dramatic or more attractive presentation of data relationships. III. COMPUTER ART: Computer Graphics methods are widely used in both fine art and commercial art applications.
  • 5. 4 Artists use a variety of computer methods, including special purpose hardware, artist’s paint brush programs, other paint packages, specially developed software, symbolic mathematics packages, CAD packages, desktop publishing software and animation packages that provide facilities for designing object shapes and specifying object motions. The basic idea behind a “paint brush” program is that, it allows artists to paint pictures on the screen of video monitor. The picture is usually painted electronically on a graphics tablet using a stylus, which can simulate different brush strokes, brush widths and colors. The art work of electronic art created with the aid of mathematical relationships is designed in relation to frequency variations and other parameters in a musical composition to produce a video that integrates visual and aural patterns. IV. ENTERTAINMENT: Computer Graphics methods are now commonly used in making motion pictures, music videos and television shows. A graphics scene generated for the movie “Star-Trek – The wrath of Khan” is one of the uses, in entertainment field. Many TV series regularly employ compute graphics method. E.g.: Deep Space Nine and Stay Tuned. Music videos use graphics and image processing technique can be used to produce a transformation of one person or object into another or morphing.
  • 6. 5 V. EDUCATION AND TRAINING: Computer generated models of physical, financial and economic systems are often used as educational aids, models of physical systems, physiological systems and population trends or equipment such as the color-coded diagram can help trainings, to understand the operation of the system. For some training applications, special systems are designed. E.g.: Simulators for practice sessions for training of ship, contains pilots, heavy equipment operators and air-traffic control personnel. VI. VISUALIZATION: It is an application for computer graphics. Producing graphical representations for scientific engineering and medical data sets and processes is generally referred to as scientific visualization and the term business visualization is used in connection with data sets related to commerce, industry and other non-scientific areas. There are many different kinds of data sets and effective visualization schemes depend on the characteristics of the data. A collection of data can contain scalar values vectors, higher order tensors or any combination of these data types. Color coding is just one way to visualize the data sets. Additional techniques include contour plots, graphs and charts, surface renderings and visualization of volume interiors.
  • 7. 6 VII. IMAGE PROCESSING: Image Processing applies techniques to modify or interact existing pictures such as photographs and TV scans. Two principal applications of image processing are: i) improving picture quality and ii) machine perception of visual information. To apply image processing methods, we first digitize a photograph or other picture into an image file. Then digital methods can be applied to rearrange picture parts to enhance color separations or to improve the quality of shading. An example of the application of image processing methods is to enhance the quality of a picture. Image processing and computer graphics are typically combined in many applications. The last application is generally referred to as computer-aided surgery. VIII. GRAPHICAL USER INTERFACE(GUI): It is common now for software packages to provide a graphical interface. A major component of a graphical interface is a window manager that allows a user to display multiple-window areas. Each window can contain a different process that can contain graphical and non-graphical displays. An “icon” is a graphical symbol that is designed to look like the processing option it represents. The advantages of icons are that they take up less screen space than corresponding textual description and they can be understood more quickly, if well designed.
  • 8. 7 CHAPTER -2 VIDEO DISPLAY DEVICES: The display devices are known as output devices. The most commonly used output device in a graphics video monitor. The operations of most video monitors are based on the standard cathode-ray-tube (CRT) design. How the Interactive Graphics display works: The modern graphics display is extremely simple in construction. It consists of three components: 1) A digital memory or frame buffer, in which the displayed Image is stored as a matrix of intensity values. 2) A monitor 3) A display controller, which is a simple interface that passes the contents of the frame buffer to the monitor. Inside the frame buffer the image is stored as a pattern of binary digital numbers, which represent a rectangular array of picture elements, or pixel. The pixel is the smallest addressable screen element. In the Simplest case where we wish to store only black and white images, we can represent black pixels by 0's in the frame buffer and white Pixels by 1's. The display controller simply reads each successive byte of data from the frame buffer and converts each 0 and 1 to the corresponding video signal. This signal is then fed to the monitor. If we wish to change the displayed picture all we need to do is to change of modify the frame buffer contents to represent the new pattern of pixels.
  • 9. 8 CATHODE-RAY-TUBES: A Cathode-Ray Tube (CRT) is a video display device, whose design depends on the operation of most video. BASIC DESIGN OF A MAGNETIC DEFLECTION: A beam of electronic emitted by an electron gun, passes through focusing and deflection systems that direct the beam towards specified position on the phosphor- coated screen. The phosphor then emits a small spot of light at each position contacted by the electron beam. Because the light emitted by the phosphor fades very rapidly. Some method is needed for maintaining the screen picture. One way to keep phosphor glowing is to redraw the picture repeatedly by quickly directing the electron beam back over the same points. This type of display is called a “refresh rate”. Phosphor coated screen Deflected Electron beam Electron beam Connector Pins Electron Gun (Cathode) Base Focusing System Magnetic Deflection Coils Horizontal Deflection Amplifier
  • 10. 9 OPERATION OF AN ELECTRON GUN WITH AN ACCELERATING MODE: The primary components of an electron gun in a CRT are the heated metal cathode and a central grid. Heat is supplied to the cathode by directing a current through a coil of wire called the “filament”, inside the cylindrical cathode structure. This causes electrons to be ‘boiled off”, the hot cathode surface. In a vacuum, inside the CRT envelope, the free negatively charged electrons are then accelerated towards the phosphor coating by a high positive voltage. The accelerating voltage can be generated with a positively charged metal coating on the inside of the CRT envelope near the phosphor screen or an accelerating anode can be used. Intensity of the electron beam is controlled by setting voltage levels on the control grid, which is a metal cylinder that fits over the cathode. A high negative voltage applied to the central grid will shut off the beam by repelling electrons and stopping them from passing through the small hole at the end of the control grid structure. A smaller negative voltage on the control grid simply decreases the number of electrons passing through. The focusing system in CRT is needed to force the electron beam to coverage into a small spot as it strikes the phosphor. Otherwise, the electrons would repel each other and the beam would spread out as it approaches the screen. The electron beam will be focused properly only at the center of the screen. As the beam moves to the outer edges of the screen, displayed images become blurred. To compensate for this, the system can adjust the focusing according to the screen position of the beam, when the picture presentation is more than the refresh rate, then it is called “blurred/overlapping”.
  • 11. 10 Cathode ray tubes are now commonly constructed with magnetic deflection coils mounted on the outside of the CRT envelope. Two pairs of coils are used with the coils in each pair mounted on opposite sides of the neck of the CRT envelope. The magnetic field produced by each pair of coils results in a traverse deflection force that is perpendicular both to the direction of the magnetic field and to the direction of travel of the electron beam. Horizontal deflection is accomplished with one pair of coils and vertical deflection is accomplished with another pair of coils. When electrostatic deflection is used 2 pairs of parallel plates is mounted horizontally to control the vertical deflection and other is mounted vertically to control horizontal deflection. Different kinds of phosphors are available for use in a CRT. Besides color, a major difference between phosphors in their “persistence”, how long they continue to emit light after the CRT beam is removed. “Persistence” is defined as the time; it takes the emitted light from the screen to delay to one-tenth of its original intensity. i.e.: Persistence α 1/Refreshment The intensity is greatest at the center of the spot and decreases with a Gaussian distribution out to the edges of the spot. The distribution corresponds to the cross sectional electron density distribution of CRT beam. The maximum number of points that can be displayed without overlap on a CRT is referred to as “resolution”. “Resolution” is the number of points/centimeter that can be plotted horizontally and vertically. Resolution of : Intensity distribution of an illuminated phosphor spot on a CRT screen.
  • 12. 11 CRT is dependent on the type of phosphor, the intensity to be displayed and the focusing and the deflection system. “Aspect Ratio” is the property of video monitors. This number gives the ratio of vertical points to horizontal points necessary to produce equal length lines in both directions on the screen. An aspect ratio of 3/4 means that a vertical line plotted with 3 points has the same length as a horizontal line plotted with 4 points. COLOR CRT MONITORS: The CRT monitor displays color pictures by using a combination of phosphors that emit different colored light. By combining the emitted light from the different phosphor a range of colors can be generated. The 2 basic techniques for producing color display with a CRT are the beam- penetration method and the shadow-mask method. I. BEAM PENETRATION METHOD: The beam penetration method for displaying color pictures has been used with random scan monitors. Two layers of phosphor, usually red and green are coated onto the inside of the CRT screen and the displayed color depends on how for the electron beam penetrates into the phosphor layers. A beam of slow elements excites only the outer red layer. A beam of very fast electrons penetrates through the red layer and excites the inner green layer. An intermediate beam speeds, combinations of red and green lights are emitted to show two additional colors, orange and yellow. The speed of the electrons and hence the screen color at any point is controlled by the beam accelerating voltage.
  • 13. 12 II. SHADOW MASK METHOD: It is commonly used is raster scan systems because they produced a much wider range of colors than the beam penetration method. One phosphor dot emits a red light, another emits a green light and the 3rd emits a blue light. This type of CRT has 3 electron guns, one for each color dot and a shadow mask grid just behind the phosphor coated screen. The 3 electron beams are deflected and focused as a group onto the shadow mask, which contains a series of holes aligned with the phosphor-dot patterns. When the 3 beams pass through a hole in the shadow mask they activate a dot triangle, which appears as a smaller color spot on the screen. “Composite Monitors” are adaptations of TV sets that allow bypass of the broadcast cirentry. These display devices still require that the picture information be combined, but no carrier signal is needed. Color CRTs in graphics systems are designed RGB monitors. These monitors use shadow mask methods and take the intensity level for each electron gun directly from the computer system without any immediate processing. A RGB color system with 24 bits of storage per pixel is generally referred to as a full-color system or a true color system. FLAT PANEL DISPLAY: This refers to a class of video devices that have reduced volume, weight and power requirements compared to a CRT. A significant feature of flat panel displays is that they are thinner than CRTs.
  • 14. 13 Current uses for flat panel displays include small TV monitors and calculators, pocket video games, laptop computers and as graphics display in applications requiring rugged portable monitors. Flat panel display is of 2 types i.e.: emissive display and non-emissive display. Flat Panel Display commonly use threadlike liquid crystal compounds, which tend to keep the long-axes of the rod shaped molecules aligned. A Flat Panel Display can be constructed with a nematic liquid crystal. It has 2 glass plates, each containing a light polarizes at right angles to the other plate, sandwich the liquid crystal material. Horizontal transparent conductors’ rows are built into one glass plate and vertical conductors’ columns are put into other plate. The intersection of 2 conductors defines a pixel position. Polarized light passing through the material is twisted, so that it will pass through the opposite polarizer. The light is then reflected back to the viewer. The turn off the pixel, we apply a voltage to the 2 intersecting conductors to align the molecules, so that the light is not twisted. These types of flat panel device are called as “Passive Matrix LCD”. Another method for constructing LCDs is to place a transistor at each pixel location, using thin film transistor at each pixel location, using thin film transistor technology. The transistors are used to control the voltage at pixel locations and to prevent charge from gradually leaking out of the liquid-crystal cells. These devices are called active matrix displays.
  • 15. 14 I. EMMISIVE DISPLAY: The Emissive Displays (Emitters) are the devices that convert electrical energy into light. E.g.: Plasma Panels, Thin Film Electroluminescent Displays and Light Emitting Diodes are example of emissive displays. a. PLASMA PANEL: The plasma panel also called gas-discharge displays are constructed by filling the region between two glass plates with a mixture of gases that usually includes Neon. A series of vertical conducting ribbons is placed on one glass panel and a set of horizontal ribbons is built into the other glass panel. Firing voltages applied to a pair of horizontal and vertical conductors causes the gat at the intersection of the two conductors to breakdown into glowing plasma of electron and ions. One disadvantage of plasma panels has been that they were strictly monochromatic devices, but systems have been developed that are now capable of displaying color and gray scale. b. THIN-FILM ELECTROLUMINISCENT DISPLAYS: Thin-Film Electroluminescent displays are similar in construction to plasma panel. The difference is that the region between the glass plates is filled with a phosphor, such as zinc sulphide dopped with manganese, instead of a gas.
  • 16. 15 When a high voltage is applied to a pair of crossing electrodes, the phosphor becomes a conductor in the area of the intersection of two electrodes; the phosphor becomes a conductor in the area of the intersection of two electrodes. Electrical energy is then absorbed by manganese, which release the energy as a spot of light similar to the glowing plasma effect in a plasma panel. Electroluminescent displays require more power than plasma panels and good color and gray scale displays are hard to achieve. c. LIGHT-EMITTING DIODE(LED): In Light Emitting Diode (LED), a matrix of diodes are arranged to form the pixel positions in the display and picture definition is stored in a refresh buffer. II. NON-EMISSIVE DISPLAY: The Non-Emissive Displays (Non-Emitters) use optical effects to convert sunlight or light from some other source into graphics patterns. E.g.: Liquid Crystal Display. The Non-Emissive devices produce by passing polarized light from the surroundings or from an internal light source through a liquid crystal material that can be aligned to either block or transmit the light. Liquid crystal refers to the fact that these compounds have a crystalline arrangement of molecules. a. LIQUID CRYSTAL DISPLAY (LCD): Liquid Crystal Displays (LCDs) are commonly used in small systems such as calculators, laptops and computers.
  • 17. 16 RASTER-SCAN SYSTEM: Raster-Scan Systems typically employ several processing units. In addition to the central processing unit or CPU, a special purpose, processor called the “video controller” or “display controller”, is used to control the operation of the display device. Here, the frame buffer can be anywhere in the system memory and the video controller, more sophisticated raster systems employ other processors as co- processors and accelerators to implement various graphics. VIDEO CONTROLLER: A fixed area of the system memory is reserved for the frame buffer and the video controller is given direct access to the frame buffer memory. Frame buffer locations and the corresponding screen positions are referenced in Cartesian coordinate origin is defined at the lower left screen corner. The screen surface is then represented as the first quadrant of 2D system, with positive ‘x’ values increasing to the right and positive ‘y’ values increasing from bottom to top. CPU SYSTEM MEMORY VIDEO CONTROLLER SYSTEM BUS I/O DEVICES MONITOR CPU SYSTEM MEMORY VIDEO CONTROLLER SYSTEM BUS I/O DEVICES MONITORFRAME BUFFER
  • 18. 17 Here, 2 registers are used to store the co-ordinates of the screen pixels. Initially the x-register is set too and y-register is set to ‘ymax’. The value stored in the frame buffer for this pixel position is then retrieved and used to set the intensity of CRT beam. The x-register is incremented by 1 and the process repeated for the next pixel on the top scan line. This procedure is repeated for each pixel along the scan line. After the last pixel on the top scan line has been processed, the x-register is rest to 0 and y-register decremented by 1. This procedure is repeated for each successive scan line. After cycling through all pixels along the bottom scan line y = 0, the video controller resets the registers to the 1st pixel position on the top scan line and the refresh process start over. When the frame/pixel presentation is less than the refresh rate, then it is called flickering. Flickering is a problem occurred in raster-scan system and it is solved by interlacing technique. RASTER-SCAN DISPLAY: It is based on TV technology. Here electron beam is swept across the screen, on row at a time from top to bottom. The picture definition is stored in a memory area called refresh buffer/frame buffer. Here each screen point is referred as a pixel or pel (picture element). The capacity of raster-scan system is to store intensity information for each screen point for realistic display of scenes containing shading and color patterns. In black and white system, a bit value of ‘1’ represents the electron beam intensity is turned on and a value of ‘0’ indicates the beam intensity is to be off.
  • 19. 18 In black and white system, a bit value of ‘1’ indicates the electron beam intensity is turned on and a value of ‘0’ indicates the beam intensity is to be off. A system with 24 bits/pixel requires 2 megabytes of storage for the frame buffer. On black and white system with one bit/pixel, the frame buffer is called bitmap. For multiple bits/pixel, the frame buffer is called pixmap. Raster-Scan display is carried out at the rate of 60 to 80 frames/second. It has units of cycle/sec or hertz. It contains a separate display processor called “graphics controller” or “display co-processor” to free the CPU. A major task of display processor is digitizing a picture definition given in an application program into a set of pixel intensity values for storage in the frame buffer. This is called “Scan Conversion”. RANDOM-SCAN DISPLAY: In this system, an application program is input and stored in the system memory along with a graphics package. The display file is accessed by the display processor to refresh the screen. The display processor is called as display- processing unit or graphics controller. DISPLAY PROCESSOR MEMORY VIDEO CONTROLLER I/O DEVICES MONITOR FRAME BUFFER CPU DISPLAY PROCESSOR SYSTEM MEMORY [RASTER-SCAN SYSTEM WITH A DISPLAY PROCESSOR]
  • 20. 19 RANDOM-SCAN SYSTEMS: When a random-scan display unit is operated a CRT has the electron beam directed only to the parts of the screen, where a picture is to be drawn. Random- scan monitors draw a picture one line at a time and for this reason is also refreshed to as vector displays or stroke-writing or calligraphic display. Refresh rate on a random-scan system depends on the number of lines to be displayed. Picture definition is now stored as a set of line drawing commands in an area of memory referred to as the refresh display file or display list or display program or refresh buffer. Random-scan systems are designed for line drawing applications and can’t display realistic shaded scenes. INPUT DEVICES: The various input devices are: Keyboard, Mouse, Trackball and Space-ball, Joysticks, Data glove, Digitizers, Image Scanner, Light Pens, Touch Panels and Voice System. I. KEYBOARD: It is used primarily as a device for entering that strings. It is an efficient device for inputting non-graphics data as picture labels associated with a graphics display. It provided with features to facilitate entry of screen co- ordinates, menu selections or graphics functions. CPU SYSTEM MEMORY DISPLAY PROCESSOR SYSTEM BUS I/O DEVICES MONITOR
  • 21. 20 Cursor-control keys and function keys are common feature on general purpose keyboards. Function keys allows users to entry frequently used operations in a single keystroke and a cursor control keys can be used to select displayed objects or co-ordinate positions by positioning the screen cursor. II. MOUSE: A mouse is a small hand-held box used to position the screen cursor. Wheels or rollers on the bottom of the mouse can be used to record the amount of direction of movement. III. TRACKBALL AND SPACEBALL: A track-ball is a ball that can be rotated with fingers or palm of the hand produce screen-cursor movement. It is a 2-dimensional positioning device. A space-ball provides 6 degrees of freedom. It does not actually move. It is used for 3-dimensional positioning. IV. JOYSTICKS: It consists of a small, vertical layer mounted on a base that is used to steer the screen cursor around. Most joysticks select screen positions with actual stick movement, other respond to pressure on the stick. In movable joystick, the stick is used to activate switches that cause the screen cursor to move at a constant rate in the direction selected. V. DATA GLOVE: A data glove can be used to grasp a ‘virtual object’. It is constructed with a series of sensors that detect hand and finger motion.
  • 22. 21 VI. DIGITIZERS: It is a common device used for drawing, painting or interactively selecting co-ordinate positions on an object. These devices can be used to input co-ordinate values in either a 2D or 3D space. It is used to scan over a drawing or object and to input a set of discrete coordinate positions, which can be joined with straight line segments to approximate the cure or surface shapes. One type of digitizers is the “Graphics Tablet”, which is used to input 2D co-ordinates by activating a hand cursor or stylus at selected positions on a flat structure. A hand cursor contains cross hairs for sighting positions, while a stylus is a pencil shaped device that is pointed at positions on the tablet. VII. IMAGE SCANNER: Drawings, graphs, color and black and white photos or text can be stored for computer processing with an image scanner by passing an optical scanning mechanism over the information to be stored. VIII. LIGHT PENS: This is a pencil shaped device are used to select screen position by detecting the light coming from points on the CRT screen. An activated light pen, pointed at a spot on the screen as the electron beam lights up that spot generates an electrical plate that causes the co-ordinates position of the electron beam to be recorded.
  • 23. 22 IX. TOUCH PANELS: It allows displayed objects or screen positions to be selected with the touch of a finger. A typical application of touch panels is for the selection of processing options that are represented with graphical icons. Optical touch panels employ a line of infrared light emitting diodes (LEDs) along one vertical edge and along one horizontal edge contain light- detectors. These detectors are used to record which beams are interrupted when the panel is touched. An electrical touch panel is constructed with 2 transparent plates separated by a small distance. One plate is coated with conducting material and other with a resistance material. X. VOICE SYSTEM: It can be used to initiate graphics operations or to enter data. These systems operate by matching an input against a predefined dictionary of words and phrases. HARD COPY OUTPUT DEVICES: Hard-Copy output devices gives images in several format. For presentations or archiving, we can send files to devices or service bureaus that will produce 35mm slides or overhead transparencies. The quality of pictures obtained from a device depends on dot size and the number of dots per inch or lines per inch that can be displayed. Printer produces output by either impact or non-impact methods. Impact printers press format character faces against an inked ribbon onto the paper. A line
  • 24. 23 printer is an example of impact device. Non-impact printers and plotters use laser techniques methods and electro-thermal methods to get images into paper. Character impact printers have a dot matrix print head containing a rectangular array of protruding wire pins with the number of pins depending on the quality of the printer. In a laser device, a laser beam creates a charge distribution on a rotating drum coated with a photoelectric material, such as selenium. Toner is applied to the drum and then transferred to paper. Ink-jet methods produce output by squirting ink in horizontal rows across a roll of paper wrapped on a drum. The electrically charged ink stream is deflected by an electric field to produce dot-matrix patterns. An electrostatic device places a negative charge on the paper, one complete row at a time along the length of the paper. Then the paper is exposed to a toner. The toner is positively charged and so is to the negatively charged areas, where it adheres to produce the specified output. Electro-thermal methods use heat in a dot- matrix print head to output patterns on heat-sensitive paper. GRAPHICS SOFTWARE: Graphics Software is of 2 types. That is: i) General Programming Packages ii) Special Purpose Application Packages. A general programming package provides an extensive set of graphics functions that can be used in a high level programming language. Application graphics packages are designed for non-programmers. So, that user can generate displays without worrying about how graphics operations.
  • 25. 24 CO-ORDINATE REPRESENTATIONS: With few exceptions, general graphics packages are designed to be used with Cartesian co-ordinate specifications. If co-ordinates values for a picture are specified in some other references frame, they must be converted to Cartesian co- ordinates before they can be input to the graphics package. Special purpose packages may allow using of other co-ordinate frames that are appropriate to the application. We can construct the shape of individual objects, in a scene within separate co-ordinate reference frames, called “modeling co- ordinates” or “local co-ordinates” or “master co-ordinates”. Only individual object shapes have been specified, we can place the objects into appropriate positions within the scene using a reference frame called world co- ordinates. The world co-ordinates description of the scene is transferred to one or more output device reference frames for display. The display co-ordinate systems are referred to as device co-ordinates/screen co-ordinates in the case of video monitors. Generally, a graphics system first converts world co-ordinates to specific device co-ordinate to specific device co-ordinates. An initial modeling co-ordinate position (xmc, ymc) is transferred to advice co-ordinate position (xdc, ydc) with the sequence (xmc, ymc) → (xwc, ywc) → (xnc, ync) → (xdc, ydc). The normalized co- ordinates satisfy the inequalities 0 ≤ xnc ≤ 1, 0 ≤ ync ≤ 1 and the device co-ordinates ‘xdc’ and ‘ydc’ are integers within the range (0,0) to (xmax, ymax) for particular device.
  • 26. 25 GRAPHICS FUNCTIONS: A general purpose graphics package provides users with a variety of functions for creating and manipulating pictures. The basic building blocks for pictures are referred to as output primitives. They include character strings and geometric entities such as points, straight lines, curved lines, filled areas and shapes defined with arrays of color points. Attributes are the properties of the output primitives that is an attribute describe how a particular primitive is to be displayed. We can change the size, position or orientation of an object within a scene using geometric transformations similar modeling transformations are used to construct a scene using object description given in modeling co-ordinates. Viewing transformations are used to specify the view that is to be presented and the portion of the output display area that is to be used. Pictures can be subdivided into component parts called structures/segments/objects, depending on the software package in use. Interactive graphics applications use various kinds of input devices, such as a mouse, a tablet or a joystick. Input functions are used to control and process the data flow from those interactive devices. A graphics package contains a number of housekeeping tasks, such as clearing a display screen and initializing parameters. The functions for carrying out these chores under the heading control operations. SOFTWARE STANDARDS: The primary goal of standardized graphics software is probability. When packages are designed with standard graphics functions, software can be moved
  • 27. 26 easily from one hardware system to another and used in different implementations and applications. International and National standards planning organization have co-operated in an effort to develop a generally accepted standard for computer graphics. After considerable effort, this work on standards led to the development of the Graphical Kernel System (GKS). This system was adopted as the first graphics software standard by International Standard Organization (ISO), and by others. The 2nd software standard to be developed and approved by the standards organizations was Programmer’s Hierarchical Interactive Graphics Standard (PHIGS), which is an extension of GKS. Standard Graphics functions are defined as a set of specifications that is independent of any programming language. A language binding is then defined for a particular high level programming language. Standardization for device interface methods is given in Computer Graphics Interface (CGI) system and the Computer Graphics Metafile (CGM) system specifies standards for archiving and transporting pictures. PHIGS WORKSTATION: The workstation is a computer system with a combination of input and output device that defined for a single user. In PHIGS and GKS, the term workstation is used to identify various combinations of graphics hardware and software. A PHIGS workstation can be a single output device, single input device, a combination of input and output devices, a file or even a window displayed on a video monitor. To define and use various “workstations” within an application program, we need to specify a workstation identifier and the workstation type.
  • 28. 27 COMPONENTS OF GUI: A GUI uses a combination of technologies and devices to provide a platform the user can interact with for the tasks of gathering and producing information. A series of elements confirming a visual language have evolved to represent information stored in computers. This makes it easier for people with little computer skill to work with and use computer software. The most common combination of such elements in GUIs is the WIMP paradigm, especially in personal computers. A window manager facilitates the interactions between windows, applications and the windowing system. The windowing system handles hardware devices, such as pointing devices and graphics hardware as well as the positioning of the cursor. In personal computers all these elements are modeled through a desktop metaphor, to produce a simulation called a desktop environment in which the display represents a desktop, upon which documents and folders of documents can be placed. USER INTERFACE AND INTERACTION DESIGN: Designing the visual composition and temporal behavior of GUI is an important part of software application programming. Its goal is to enhance the efficiency and ease of use for the underlying logical design of a stored program, a design discipline known as usability. Techniques of user-centered design are used to ensure that the visual language introduced in the design is well tailored to the tasks it must perform.
  • 29. 28 The widgets of a well-designed interface are selected to support the actions necessary to achieve the goals of the user. A model-view controller allows for a flexible structure in which the interface is independent from and indirectly linked to application functionality, so the GUI can be easily customized. This allows the user to select or design a different skin at will and eases the designer’s work to change the interface as the user needs evolve. The visible graphical interface features of an application are sometimes referred to as “chrome”. Larger widgets such as windows usually provide a frame or container for the main presentation content, such as a web page, email message or drawing. A GUI may be designed for the rigorous requirements of a vertical market. This is known as “Application Specific Graphical User Interface”. Examples of an application specific GUI are: i) Touch screen point of sale software used by wait staff in a busy restaurant. ii) Self-service checkouts used in a retail store. iii)Automated Teller Machines (ATM) iv) Information kiosks in a public space, like a train station or a museum. v) Monitors or control screens in an embedded industrial application which employ a real-time operating system (RTOS). COMMAND LINE INTERFACES: GUIs were introduced in reaction to the steep learning curve of command line interfaces (CLI), which require commands to be typed on the keyboard. Since the commands available in command line interfaces can be numerous, complicated operations can be completed using a short sequence of words and symbols. This allows for greater efficiency and productivity once many commands are learnt but
  • 30. 29 reaching this level takes some time because the command words are not easily discoverable and not mnemonic. Command line interfaces use modes only in limited forms, such as the current directory and environment variables. Most modern operating systems provide both a GUI and some level of a CLI, although the GUIs usually receive more attention. THREE-DIMENSIONAL USER INTERFACES: Three-dimensional images are projected on them in two dimensions. Since this technique has been in use for many years, the recent use of the term three- dimensional must be considered a declaration by equipment marketers that the speed of three dimensions to two dimension projection is adequate to use in standard GUIs.
  • 31. 30 CHAPTER – 3 LINE DRAWING ALGORITHMS: 1. SIMPLE LINE DRAWING ALGORITHM: The Cartesian slope intercept equation for a straight line is: y = mx + b => b = y – mx, Where m = slope of line, b = y-intercept form. If 2 end points of a line segment is specified at position (x1, y1) and (x2, y2). So the values for the slope ‘m’ and y-intercept form ‘b’ is: m = ∆y/∆x = (y2 – y)/(x2 – x1) => ∆y = m∆x ------- (1) and ∆x = ∆y/m ------ (2) b = y1 –mx1 Here, ‘∆y’ is the y-interval computed for the given x-interval ∆x along a line is ∆y = m∆x. Similarly the x-interval ∆x corresponding to a specified ∆y as: ∆x = ∆y/m. For lines with slope magnitude, |m| < 1, ‘∆x’ increases. So calculate ‘∆y’ as: ∆y = m∆x. For |m| > 1, ‘∆y’ increases. So calculate ‘∆x’ as: ∆x = ∆y/m. For |m| = 1, ∆x and ∆y both incremented and have the same value for horizontal and vertical segments. x1 x2 ∆x y1 y2 ∆y
  • 32. 31 Example: Draw a line for points (3, 2) to (7, 8). Here, (x1, y1) = (3, 2) and (x2, y2) = (7, 8). So m = y2 –y1/x2 – x1 = 8 – 2/7 – 3 = 6/4 = 3/2 > 1. That is, for m > 1, ∆y increases and ∆x = ∆y/m. ∆x ∆y x = x1 + ∆x y = y1 + ∆y 2/3 1 11/3 3 4/3 2 13/3 4 2 3 5 5 8/3 4 17/3 6 10/3 5 19/3 7 4 6 7 (x2) 8 (y2) 2. DIGITAL DIFFERENTIAL ANALYSER ALGORITHM (DDA): This is a scan conversion line algorithm based on calculating either ∆y or ∆x as: ∆y = m∆x and ∆x = ∆y/m. We sample the line at unit intervals in one co-ordinate and determine corresponding integer values nearest the line path for the other co-ordinate. Consider first a line with positive slope. If m ≤ 1, we sample at unit x- intervals (∆x = 1) and calculate successive ‘y’ values as: yk+1 = yk + m. (∆x increases by 1 always, so ∆x = 1). Where, k = subscript and integer values starting from 1, for 1st point and increase by 1 until the final end point is reached. Since ‘m’ can be any real number between 0 and x1 x2 y1 y2
  • 33. 32 1, the calculated ‘y’ values must be rounded to the nearest integer. If m > 1, we sample at unit y-intervals (∆y = 1) and calculate each succeeding ‘x’ values as: xk+1 = xk + 1/m. (∆y increases by 1 always, so ∆y = 1). Here, the lines are processes from left end point to right end point. If the lines processed from right end to left end point, then ∆x = -1 and yk+1 = yk – m (for, m ≤ 1), when ∆y = -1 and m > 1, then xk+1 = xk - 1/m. Example: Draw a line for points (3, 2) to (7, 8). Here, xk = 3, yk = 2 and m = y2 –y1/x2 – x1 = 8 – 2/7 – 3 = 6/4 = 3/2 > 1. So, m > 1, so yk increases by 1 always. xk+1 = xk + 1/m yk+1 = yk + m 11/3 3 13/3 4 15/3 = 5 5 17/3 6 19/3 7 7 (x2) 8 (y2) 3. BRESENHAM’S LINE DRAWING ALGORITHM: An accurate and efficient raster line generating algorithm is developed by Bresenham. In this approach, at slope m < 1, pixel positions along a line path are then determined by sampling at unit x-intervals. Starting from left end point (x0, y0) of a given line, we step to each successive column (x –
  • 34. 33 position) and plot the pixel, whose scan-line ‘y’-value is closest to the line ‘p’. For kth step, we determine the pixel at (xk, yk) is to be displayed we need to decide which pixel to plot in column, xk+1 and the choice of pixel position are: (xk+1, yk) and (xk+1, yk+1). At xk+1, we label vertical pixel separations from the mathematical line path as ‘d1’ and ‘d2’. So at xk+1, the ‘y’ co-ordinate is: y = m(xk + 1) + b ------- (1) d1 = y – yk = m(xk +1) + b – yk d2 = (yk + 1) – y = yk + 1 – m(xk + 1) – b The difference between these 2 separations is: d1 – d2 = m(xk + 1) + b – yk – (yk +1) + m(xk + 1) + b = 2m(xk + 1) + 2b - yk – (yk +1) = 2m(xk + 1) + 2b - yk – yk – 1 => d1 – d2 = 2m(xk + 1) + 2b - 2yk – 1 ------- (2) The decision parameter ‘Pk’ for kth step in the line algorithm is calculated with substitution of m = ∆y/∆x. So, Pk = ∆x(d1 – d2) = ∆x(2m(xk + 1) + 2b - 2yk – 1) yk+3 yk+2 yk+1 yk xk xk+1 xk+2 xk+3 y = mx + b
  • 35. 34 = ∆x(2∆y/∆x (xk + 1) + 2b - 2yk – 1) = 2∆y(xk + 1) + 2b∆x - 2yk ∆x - ∆x = 2∆yxk + 2∆y + 2b∆x - 2yk ∆x - ∆x = 2∆yxk - 2∆xyk + 2∆y + 2b∆x - ∆x = 2∆yxk - 2∆xyk + 2∆y + ∆x(2b -1) = 2∆yxk - 2∆xyk + C => Pk = 2∆yxk - 2∆xyk + C ------- (3) The sign of ‘Pk’ is same as the sign of d1 – d2, since ∆x > 0, C = constant and value of C = 2∆y + ∆x(2b -1), independent of pixel position. If the pixel at ‘yk’ is closer to the line path than the pixel at yk+1 (i.e. d1 < d2), then the decision parameter ‘Pk’ is negative. At step k + 1, the decision parameter is evaluated as: Pk+1 = 2∆y(xk +1) - 2∆x(yk +1) + C ------- (4) Now, subtract equation – (3) from equation – (4), we get: Pk+1 – Pk = 2∆y(xk+1 – xk) - 2∆x(yk+1 – yk), but xk+1 = xk + 1, so that Pk+1 = Pk + 2∆y(xk+1 – xk) - 2∆x(yk+1 – yk) => Pk+1 = Pk + 2∆y - 2∆x(yk+1 – yk) ------- (5) Where, yk+1 – yk is either 0 or 1, depending on the sign of parameter Pk.
  • 36. 35 The recursive calculation of decision parameters is performed at each integer x-position, starting at the left co-ordinate end point of the line. The 1st parameter ‘P0’ is evaluated from equation – (3), at the starting pixel position (x0, y0) and with ‘m’ evaluated as ∆y/∆x. So, P0 = 2∆y - ∆x --- (6). ALGORITHM: STEP 1: Input the two line end points and store the left end point in (x0, y0) STEP 2: Load the (x0, y0) or the initial point of the line into the frame buffer then plot the first point. STEP 3: Calculate the constant ∆x, ∆y, 2∆y, 2∆y - 2∆x and obtain the starting value for the decision parameter: P0 = 2∆y - ∆x STEP 4: At each ‘xk’ along the starting at k = 0, perform the following point. If Pk < 0, plot (xk + 1, yk) and Pk+1 = Pk + 2∆y If Pk > 0, plot (xk + 1, yk + 1) and Pk+1 = Pk + 2∆y - 2∆x. STEP 5: Repeat STEP – 4, ∆x times. Example: To illustrate the algorithm, we digitize the line with end points (20, 10) and 30, 18) Here the line has a slope: m = y2 –y1/x2 – x1 = 18 – 10/30 – 20 = 8/10 = 0.8 < 1
  • 37. 36 ∆x = 30 – 20 = 10 and ∆y = 18 – 10 = 8. The initial decision parameter is: P0 = 2∆y - ∆x = 2 x 8 – 10 = 16 – 10 = 6 and the increments for the calculating successive decision parameters are: ∆x = 10, ∆y = 8, 2∆y = 16, 2∆y - 2∆x = 16 – 20 = - 4. At k = 0, we plot the initial point (xk, yk) = (x0, y0) = (20, 10) and determine successive pixel positions along the line path from the decision parameter as: k Pk (xk +1, yk +1) Decision parameter calculation 0 6 (21, 11) P0 = 2∆y - ∆x = 2 x 8 – 10 = 16 – 10 = 6 1 2 (22, 12) Pk+1 = Pk + 2∆y - 2∆x = 6 + 2 x 8 – 2 x 10 = 2 2 -2 (23, 12) Pk+1 = Pk + 2∆y - 2∆x = 2 + 2 x 8 – 2 x 10 = -2 3 14 (24, 13) Pk+1 = Pk + 2∆y = -2 + 2 x 8 = 14 4 10 (25, 14) Pk+1 = Pk + 2∆y - 2∆x = 14 + 2 x 8 – 2 x 10 = 10 5 6 (26, 15) Pk+1 = Pk + 2∆y - 2∆x = 10 + 2 x 8 – 2 x 10 = 6 6 2 (27, 16) Pk+1 = Pk + 2∆y - 2∆x = 6 + 2 x 8 – 2 x 10 = 2 7 -2 (28, 16) Pk+1 = Pk + 2∆y - 2∆x = 2 + 2 x 8 – 2 x 10 = -2 8 14 (29, 17) Pk+1 = Pk + 2∆y = -2 + 2 x 8 = 14 9 10 (30, 18) Pk+1 = Pk + 2∆y - 2∆x = 14 + 2 x 8 – 2 x 10 = 10 It will continue upto 10 times, starting from 0 to 9, because ∆x = 10. CIRCLE GENERATING ALGORITHMS: 1. PROPERTIES OF THE CIRCLE: A Circle is defined as the set of points that are all at given distance ‘r’ from a center position (xc, yc). This distance relationship is expressed by the Cartesian co-ordinates as:
  • 38. 37 (x – xc)2 + (y – yc)2 = r2 ------ (1) The general equation of a circle is: x2 + y2 = r2 ------- (2) To calculate the position of points on a circle circumference by stepping along the x-axis in unit steps from xc – r to xc + r and calculating the corresponding ‘y’ – values at each position as: ------ (3) To calculate the points along the circular boundary, polar co-ordinates ‘r’ and ‘θ’ are used. Expressing the circle equation in parametric polar form yields the pair of equations is: x = xc + rcosθ and y = yc +rsinθ Computation can be reduced by considering the symmetry of circles. The shape of the circle is similar in each quadrant. We can generate the circle section in the second quadrant of the xy-plane by noting that the two circle sections are symmetric with respect to the y-axis and the circle sections in 3rd and 4th quadrants can be obtained from sections in the first and second quadrants by considering symmetry about the x-axis. Circle sections in adjacent octants within one quadrant are symmetric with respect to the 45 degree line dividing the two octants. These symmetry conditions are illustrated in given figure, where a point at position (x, y) on a one eight circle sector is mapped onto the seven circle points in the other r xc yc
  • 39. 38 octants of the xy-plane. Taking the advantage of the circle symmetry, we can generate all pixel positions around a circle by calculating only the points within the sector from x = 0 to x = y. 2. MID-POINT CIRCLE/BRESENHAM’S CIRCLE GENERATING ALGORITHM: We set up the algorithm to calculate pixel positions around a circle path centered at the co-ordinate origin (0, 0). Then each calculated position (x, y) is moved to its proper screen position by adding ‘xc’ to ‘x’ and ‘yc’ to ‘y’, where (xc, yc) is the center position of the circle with radius ‘r’. Along the circle section from x = 0 to x = y in 1st quadrant, the slope of the curve varies from 0 to 1. To apply the midpoint method, we define the circle function with (0, 0) as its center is: Fcircle(x, y) = x2 + y2 – r2 --- (1) It has 3 properties, at any point (x, y). That is: (x, y) (y, x) (-x, y) (-y, x) (y, -x) (x, -y) (-x, -y) (-y, -x) 45o Fcircle(x, y) = < 0, if (x, y) is inside the circle boundary = 0, if (x, y) is on the circle boundary --- (2) > 0, if (x, y) is outside the circle boundary
  • 40. 39 We have plotted the pixel at (xk, yk) and next to determine whether the pixel at position (xk+1, yk) or one at position (x k+1, yk – 1) is closer to the circle. The decision parameter is the circle function and equation – (1) is evaluated at the midpoint between these 2 pixels (x k+1, yk) and (x k+1, y k – 1). So, the decision parameter is: Pk = Fcircle(xk+1, yk -1/2) = (xk+1)2 + (yk -1/2)2 – r2 --- (3) [Since midpoint = (yk + yk-1)/2 = (2yk -1)/2 = yk – 1/2] If Pk < 0, the midpoint is inside the circle and the pixel on scan line ‘yk’ is closer to the circle boundary, otherwise the midpoint is outside or on the circle boundary and we select the pixel on ‘yk - 1’. The recursive expression for the next decision parameter is obtain by evaluating the circle function at sampling position xk+1 + 1 = xk + 2, then, Pk+1 = Fcircle(xk+1 + 1, yk +1 -1/2) = [(xk+1) + 1]2 + (yk+1 – 1/2)2 – r2 => Pk+1 – Pk = 2(xk + 1) + (yk+1 2 – yk 2 ) – (yk+1 – yk) + 1 => Pk+1 = Pk + 2(xk + 1) + (yk+1 2 – yk 2 ) – (yk+1 – yk) + 1 --- (4), where yk+1 is either ‘yk’ or ‘yk-1’, depending on the sign of Pk. Increments for obtaining Pk+1 are either 2xk+1 + 1 (if Pk is negative) or 2xk+1 + 1 – 2yk+1. Evaluation of terms 2xk+1 and 2yk+1 can also be done incrementally as: 2xk+1 = 2xk + 2, 2yk+1 = 2yk - 2. At the start position (0, r), the initial decision parameter is obtained by evaluating the circle function at the start position (x0, y0) = (0, r). So,
  • 41. 40 P0 = Fcircle(1, r – 1/2) = 1 + (r – 1/2)2 – r2 = 1 + r2 + 1/4 – 2 x r x 1/2 – r2 = 5/4 – r --- (5) If the radius ‘r’ is specified as an integer, we can simply round the ‘P0’ to P0 = 1 – r (for ‘r’ is an integer). ALGORITHM: STEP 1: Input radius ‘r’ and circle center (xc, yc) and obtain the first point on the circumference of a circle centered on the origin as: (x0, y0) = (0, r). STEP 2: Calculate the initial value of decision parameter as P0 = 5/4 – r. STEP 3: At each ‘xk’ position, starting at k = 0, perform the following test: i) If Pk < 0, the next point along the circle centered on (0, 0) is (xk+1, yk) and Pk+1 = Pk + 2xk+1 + 1, otherwise, ii) The next point along the circle is, (xk+1, yk-1) and Pk+1 = Pk + 2xk+1 + 1 – 2yk+1, Where 2xk+1 = 2xk + 2 and 2yk+1 = 2yk – 2, we will continue this upto xk ≤ yk STEP 4: Determine symmetry points in other screen octants. STEP 5: Move each calculated pixel position (x, y) onto the circular path centered on (xc, yc) and plot the co-ordinate values x = x + xc and y = y + yc. STEP 6: Repeat STEP – 3 through S, until x ≥ y.
  • 42. 41 Example: Given a circle radius r = 10, we demonstrate the midpoint circle algorithm by determining positions along the circle algorithm by determining positions along circle octant in the first quadrant from x = 0 to x = y. The initial value of decision parameter is P0 = 1 –r = - 9. For the circle centered on the co-ordinates origin, the initial point is (x0, y0) = (0, 10) and initial increment terms are: 2x0 =0, 2y0 = 20. Successive decision parameter values and positions along the circle path are calculated using the midpoint method as: k Pk (xk+1, yk -1) 2xk+1 2yk+1 0 - 9 (1, 10) 2 20 1 - 6 (2, 10) 4 20 2 - 1 (3, 10) 6 20 3 6 (4, 9) 8 18 4 - 3 (5, 9) 10 18 5 8 (6, 8) 12 18 6 5 (7, 7) 14 16 ELLIPSE GENERATING ALGORITHM: 1. PROPERTIES OF THE ELLIPSE: An ellipse is the set of points, such that the sum of the distances from two fixed position is the same for all positions (Foci) is the same for all points. If the distances to the two foci from any point P = (x, y) on the ellipse are labeled ‘d1’ and ‘d2’, then the general equation of ellipse stated as:
  • 43. 42 d1 + d2 = Constant --- (1) Expressing distance ‘d1’ and ‘d2’ in terms of the focal co-ordinates F1 = (x1, y1) and F2 = (x2, y2), we have: By squaring this equation, isolating the remaining radica and then squaring again, we write the general ellipse equation in the form: Ax2 + By2 + Cxy +Dx + Ey + F = 0 --- (3) Here the coefficients A, B, C, D, E and F are evaluated in terms of the focal co-ordinates and dimensions of the major and minor axes of the ellipse. An ellipse in standard position with major and minor axes oriented parallel to ‘x’ and ‘y’ axes. Parameter ‘rx’ is the semi-major axis and parameter ‘ry’ is the semi-minor axis. The equation of the ellipse can be written in terms of the ellipse center co-ordinates and parameters ‘rx’ and ‘ry’ as: (x – xc/rx)2 + (y – yc/ry) 2 = 1 --- (4) Using polar co-ordinates ‘r’ and ‘θ’, the parametric equations of the ellipse is: (x – x1)2 + (y – y1)2 + (x – x2)2 + (y – y2)2 = Constant --- (2) d1 d2 F1 F2 P = (x, y) ry rx yc xc y x
  • 44. 43 x = xc +rxcosθ and y = yc + rysinθ --- (5) Symmetric consideration can be used to further reduce computation. 2. MID-POINT ELLIPSE/BRESENHAM’S ELLIPSE GENERATING ALGORITHM: This is applied throughout the 1st quadrant in 2 parts. The division of 1st quadrant is according to the slope of an ellipse with rx < ry. When we process this quadrant by taking unit steps in the x-direction, where slope of the curve has a magnitude less than 1 and taking unit steps in y-direction, when slope has the magnitude greater than 1. For a sequential implementation of the midpoint algorithm, we take the start position at (0, ry) in clockwise order throughout the 1st quadrant. The ellipse function from equation (4) with (xc, yc) = (0, 0) as: Fellipse(x, y) = ry 2 x2 + rx 2 y2 – rx 2 ry 2 --- (6) -x, y x, -y ry rx x, y y x -x, -y Region 2 Region 1 ry rx Slope m = -1 y x
  • 45. 44 It has 3 properties, at any point (x, y). That is: Thus the ellipse function Fellipse(x, y) serves as the decision parameter in midpoint algorithm. Starting at (0, ry), we take unit steps in the x-direction until we reach the boundary between region 1 and region 2. The slope is calculated from equation – (6) is: m = dy/dx = -2ry 2 x/2rx 2 y --- (8) At the boundary between region 1 and region 2, dy/dx = -1 and 2ry 2 x = 2rx 2 y. So we move to region 1, when 2ry 2 x ≥ 2rx 2 y. In region 1, the midpoint between the two candidate pixels at sampling position xk + 1 in the 1st region. Assuming position (xk, yk) has been selected at the previous step. We determine the next position along the ellipse path by evaluating the decision parameter at this midpoint is: Pk 1 = Fellipse(xk+1, y k -1/2) = ry 2 (xk+1)2 + rx 2 (yk -1/2)2 – rx 2 ry 2 --- (9) If Pk 1 < 0, the midpoint is inside the ellipse and the pixel on scan line ‘yk’ is closer to the ellipse boundary, otherwise the midpoint is outside or on the ellipse boundary and we select the pixel on ‘yk - 1’. Fellipse(x, y) = < 0, if (x, y) is inside the ellipse boundary = 0, if (x, y) is on the ellipse boundary --- (7) > 0, if (x, y) is outside the ellipse boundary
  • 46. 45 At the next sampling position (xk+1 + 1 = xk + 2), the decision parameter for region 1 is evaluated as: Pk+1 1 = Fellipse(xk+1 + 1, yk +1 -1/2) = ry 2 [(xk+1) + 1]2 + rx 2 (yk+1 – 1/2)2 – rx 2 ry 2 => Pk+1 1 = Pk 1 + 2ry 2 (xk + 1) + ry 2 + rx 2 [(yk+1 – 1/2)2 – (yk – 1/2)2 ] --- (10), Where, ‘yk+1’ is either ‘yk’ or ‘yk -1’, depending on the sign of Pkꞌ. Decision parameters are incremented by following amounts: At the initial position (0, ry), the two terms evaluated to 2ry 2 x = 0 --- (11) 2rx 2 y = 2rx 2 ry --- (12) As ‘x’ and ‘y’ are incremented, updated values are obtained by adding 2ry 2 to equation – (11) and subtract 2rx 2 from equation – (12). The updated values are compared at each step and we move from region 1 to region 2, when 2ry 2 x ≥ 2rx 2 y is satisfied. In region 1, the initial value of decision parameter is obtained by evaluating the ellipse function at start position (x0, y0) = (0, ry). So, P0 1 = Fellipse(1, ry – 1/2) = ry 2 – rx 2 (ry – 1/2)2 – rx 2 ry 2 => P0 1 = ry 2 – rx 2 ry – 1/4rx 2 --- (13) Increment = 2ry 2 xk+1 + ry 2 , if Pkꞌ < 0 2ry 2 xk+1 + ry 2 – 2rx 2 yk + 1, if Pkꞌ ≥ 0
  • 47. 46 Over region 2, we sample at unit steps in negative y-direction and midpoint in now taken between horizontal pixels at each step. For this region 2, the decision parameter is evaluated as: Pk 2 = Fellipse(xk+1/2, yk -1) = ry 2 (xk+1/2)2 + rx 2 (yk -1)2 – rx 2 ry 2 --- (14) If Pk 2 > 0, the midpoint is outside the ellipse and we select the pixel at scan line ‘xk’. If Pk 2 ≤ 0, the midpoint is inside or on the ellipse boundary and we select pixel position on ‘xk + 1’. To determine the relationship between successive decision parameters in region 2, we evaluate the ellipse function at the next sampling step: yk+1 – 1 = yk – 2. Pk+1 2 = Fellipse(xk+1 + 1/2, yk +1 -1) = ry 2 (xk+1+ 1/2)2 + rx 2 [(yk – 1) – 1]2 – rx 2 ry 2 => Pk+1 2 = Pk 2 - 2rx 2 (yk - 1)2 + rx 2 + ry 2 [(xk+1 + 1/2)2 – (xk + 1/2)2 ] --- (15), Here, ‘xk+1’ set either ‘xk’ or ‘xk+1’, depending on the sign of Pk 2 . When we enter region 2, the initial position (x0, y0) is taken as the last position selected in region 1 and the initial decision parameter in region 2 is: P0 2 = Fellipse(x0 + 1/2, y0 – 1) = ry 2 (x0 + 1/2) 2 – rx 2 (y0 – 1)2 – rx 2 ry 2 --- (16) To simplify the calculation of P0 2 , we could select pixel position in counter clockwise order starting at (rx, 0) unit steps would then be taken in the positive y-direction upto the last position selected in region 1.
  • 48. 47 ALGORITHM: STEP 1: Input rx, ry and ellipse center (xc, yc) and obtain the first point on an ellipse centered on the origin as: (x0, y0) = (0, ry). STEP 2: Calculate the initial value of decision parameter in region 1 as: P0 1 = ry 2 – rx 2 ry – 1/4rx 2 STEP 3: At each ‘xk’ position in region 1, starting at k = 0, perform the following test: i) If Pk 1 < 0, the next point along the ellipse centered on (0, 0) is (xk+1, yk) and Pk+1 1 = Pk 1 + 2ry 2 xk + 1 + ry 2 , otherwise, ii) The next point along the circle is, (xk+1, yk-1) and Pk+1 1 = Pk 1 + 2ry 2 xk + 1 - 2rx 2 yk+1 + ry 2 With 2ry 2 xk + 1 = 2ry 2 xk + 2ry 2 , 2rx 2 yk+1 = 2rx 2 yk - 2rx 2 and continue until 2ry 2 x ≥ 2rx 2 y. STEP 4: Calculate the initial value of the decision parameter in region 2, using the last point (x0, y0). Calculated in region 1 as: P0 2 = ry 2 (x0 + 1/2) 2 – rx 2 (y0 – 1)2 – rx 2 ry 2 STEP 5: At each ‘yk’ position in region 2, starting at k = 0, perform the following test: i) If Pk 2 > 0, the next point along the ellipse centered on (0, 0) is (xk, yk – 1) and Pk+1 2 = Pk 2 - 2rx 2 yk + 1 + rx 2 , otherwise, ii) The next point along the circle is, (xk + 1, yk - 1) and
  • 49. 48 Pk+1 2 = Pk 2 + 2ry 2 xk + 1 - 2rx 2 yk+1 + rx 2 Using the same incremental calculations for ‘x’ and ‘y’ as in region 1. STEP 6: Determine symmetry points in the other 3 quadrants. STEP 7: Move each calculated pixel position (x, y) onto the elliptical path centered on (xc, yc) and plot the co-ordinate values: x = x + xc, y = y + yc. STEP 8: Repeat the steps for region 1, until 2ry 2 x ≥ 2rx 2 y. Example: Given input ellipse parameter rx = 8, ry = 6. We illustrate the steps in the midpoint ellipse algorithm by determining raster positions along the ellipse path in the first quadrant. Initial values and increments for the decision parameter calculations as: 2ry 2 = 0 (with increment 2ry 2 = 72) and 2rx 2 y = 2rx 2 ry (with increment -2rx 2 = -128) For Region 1: The initial point for the ellipse centered on the origin is (x0, y0) = (0, 6) and the initial decision parameter value is: P0 1 = ry 2 – rx 2 ry – 1/4rx 2 = - 332. Successive decision parameter values and positions along the ellipse path are calculated using the midpoint method as:
  • 50. 49 k Pk 1 (xk+1, yk +1) 2ry 2 xk + 1 2rx 2 yk+1 0 -332 (1, 6) 72 768 1 -224 (2, 6) 144 768 2 - 44 (3, 6) 216 768 3 208 (4, 5) 288 640 4 - 108 (5, 5) 360 640 5 288 (6, 4) 432 512 6 244 (7, 3) 504 384 We now move out of region 1, since 2ry 2 x > 2rx 2 y. For Region 2: The initial point is: (x0, y0) = (7, 3) and the initial decision parameter value is: P0 2 = Fellipse(7 + 1/2, 2) = -151 The remaining positions along the ellipse path in the 1st quadrant are then calculated as: k Pk 2 (xk+1, yk +1) 2ry 2 xk + 1 2rx 2 yk+1 0 -151 (8, 2) 576 256 1 233 (8, 1) 576 128 2 745 (8, 0) - - FILLED AREA PRIMITIVES: A standard output primitives is a solid color or patterned polygon area. Other kinds of area primitives are sometimes available, but polygons are easier to process since they have linear boundaries.
  • 51. 50 POLYGON FILLING: It is the process of coloring in a defined area or regions. The region can be classified as: Boundary defined region and Interior defined region. When the region is defined in terms of pixels, if comprised of it is known as interior defined region. The algorithm used for filled interior-defined regions are known as Flood-Fill Algorithm. When the region is defined in terms of bounding pixels, that outline, it is known as boundary defined region. The algorithm used for filling boundary defined region is known as: Boundary-Fill Algorithm. FLOOD-FILL ALGORITHM: While using this, the user generally provides an initial pixel, which is known as seed pixel, starting from the seed pixel, the algorithm will inspect each of the surrounding eight pixels to determine whether the extent has been reached. In 4-connected region, only 4 pixels are surrounding pixels. i.e.: left, right, top and bottom. The process is repeated until all pixels inside the region have been inspected. INTERIOR-DEFINED REGION BOUNDARY-DEFINED REGION
  • 52. 51 The flood-fill procedure for a 4-connected region is: void floodfill4(int x, int y, int fillcolor, int oldcolor) { if(getPixel(x, y) == oldcolor) { setColor(fillcolor); setPixel(x, y); floodfill4(x + 1, y, fillcolor, oldcolor); floodfill4(x – 1, y, fillcolor, oldcolor); floodfill4(x, y + 1, fillcolor, oldcolor); floodfill4(x, y – 1, fillcolor, oldcolor); } } P P P P S P P P P P P S P P 8 - CONNECTED 4 - CONNECTED
  • 53. 52 The flood-fill procedure for an 8-connected region is: void floodfill8(int x, int y, int fillcolor, int oldcolor) { if(getPixel(x, y) == oldcolor) { setColor(fillcolor); setPixel(x, y); floodfill4(x + 1, y, fillcolor, oldcolor); floodfill4(x – 1, y, fillcolor, oldcolor); floodfill4(x, y + 1, fillcolor, oldcolor); floodfill4(x, y – 1, fillcolor, oldcolor); floodfill4(x + 1, y + 1, fillcolor, oldcolor); floodfill4(x + 1, y - 1, fillcolor, oldcolor); floodfill4(x - 1, y + 1, fillcolor, oldcolor); floodfill4(x - 1, y – 1, fillcolor, oldcolor); } }
  • 54. 53 BOUNDARY-FILL ALGORITHM: A Boundary-Fill Algorithm or procedure accepts as input, the co-ordinates of an interior point (x, y), a fill color and a boundary color. Starting from (x, y) the procedure test neighboring positions to determine whether they are of the boundary color, if not they are painted with fill color and their neighbors are tested. There are 2 methods are used for area filled i.e.: 4-connected and 8-connected. In 4-connected form the current positions, four neighboring points are tested. Those pixel positions are right, left, above and below the current pixel. In 8- connected, the set of neighboring positions to be tested includes the 4 diagonal pixels. An 8-connected boundary fill algorithm would correctly fill the interior of the area. The procedure or a recursive method for filling a 4-connected area with intensity specified in parameter fill upto a boundary color specified with parameter boundary. That is: void boundaryfill4(int x, int y, int fill, int boundary) { int current; S S 8 - CONNECTED4 - CONNECTED
  • 55. 54 current = getPixel(x, y) if((current != boundary) && (current != fill)) { setColor(fill); setPixel(fill); boundaryfill4 (x + 1, y, fill, boundary); boundaryfill4 (x – 1, y, fill, boundary); boundaryfill4 (x, y + 1, fill, boundary); boundaryfill4 (x, y – 1, fill, boundary); } } We can extend this procedure to fill an 8-connected region by including 4 additional statements to test diagonal positions, such as (x + 1, y – 1). The procedure for 8-connected area is: void boundaryfill8(int x, int y, int fill, int boundary) { int current; current = getPixel(x, y)
  • 56. 55 if((current != boundary) && (current != fill)) { setColor(fill); setPixel(fill); boundaryfill8(x + 1, y, fill, boundary); boundaryfill8(x – 1, y, fill, boundary); boundaryfill8(x, y + 1, fill, boundary); boundaryfill8(x, y – 1, fill, boundary); boundaryfill8(x + 1, y + 1, fill, boundary); boundaryfill8(x + 1, y - 1, fill, boundary); boundaryfill8(x - 1, y + 1, fill, boundary); boundaryfill8(x - 1, y – 1, fill, boundary); } } SCANLINE POLYGON-FILL ALGORITHM: For each scan line crossing a polygon, the area-fill algorithm locates the intersection points of the scan line with the polygon edges. These intersection
  • 57. 56 points are then sorted from left to right and the corresponding frame buffer positions between each intersection pair are set to specified fill color. Here, the four pixel intersection positions with the polygon boundaries define two stretches of interior pixels from x = 10 to x = 14 and from x = 18 to x = 24. A scan line passing through a vertex intersects two polygon edges at that position, adding two points to the list of intersections for the scan line. Here, 2 scan-lines at position ‘y’ and ‘yꞌ’ that intersect edge endpoints. Scan-line ‘y’ intersects five polygon edges. Scan-line ‘yꞌ’ intersects an even number of edges although it also passes through a vertex. Intersection point along scan-line ‘y’ correctly identifies the interior pixel spans. But with scan-line ‘y’, we need to do some additional processing to determine the correct interior points. The topological difference between scan-line ‘y’ and scan-line ‘yꞌ’ is identified by noting the position of the intersecting edge relative to the scan-line. For scan- line ‘y’, the two intersecting edges sharing a vertex are on opposite sides of the scan-line. But for scan-line ‘yꞌ’, the two intersecting edges are both above the scan- line. 10 14 18 24 Scan line y’ Scan line y 1 2 1 2 1 1
  • 58. 57 Calculations performed in scan-conversion and other graphics algorithms typically take advantage of various coherence properties of a scene that is to be displayed. Coherence is simply that the properties of one part of a scene are related in some way to other parts of the scene, so that the relationship can be used to reduce processing. Here, two successive scan-lines crossing a left edge of a polygon. The slope of this polygon boundary line can be expressed in terms of scan-line intersection co-ordinate is: m = yk+1 – yk/xk+1 - xk --- (1) Since the change in ‘y’- coordinates between two scan-lines is: yk+1 – yk = 1 --- (2). This x-intersection value xk+1 on the upper scan-line can be determined from the x-intersection value xk on the proceeding scan-line as: xk+1 = xk + 1/m --- (3). Along an edge, with slope ‘m’, the intersection ‘xk’ value for scan-line ‘k’ above the initial scan-line can be calculated as: xk = x0 + k/m --- (4). In a sequential fill algorithm, the increment of ‘x’ values by the amount 1/m along an edge can be accomplished with interior operations by recalling that the slope ‘m’ is the ratio of 2 integers : m = ∆y/∆x. Here ∆x and ∆y are the differences between the edges, endpoint ‘x’ and ‘y’ co- ordinate values. So incremental calculations of ‘x’- intercepts along an edge for successive scan lines can be expressed as: xk+1 = xk + ∆x/∆y --- (5) Scan-line yk+1 Scan-line yk (xk+1, yk+1) (xk, yk)
  • 59. 58 Using this equation, we can perform the integer evaluation if the x-intercepts by initializing a counter to 0, then incrementing the counter by the value ‘∆x’ each time we move upto new scan-line. Whenever the counter value becomes equal to or greater than ∆y, we increment the current x-intersection value by 1 and decrease the counter by the value ∆y. ANTIALIASING: The distortion of information due to low frequency sampling is called aliasing. We can improve the appearance of displayed raster lines by applying antialiasing methods compensate for the under-sampling process. To avoid losing information from such periodic objects, we need to set the sampling frequency to at least twice of the highest frequency occurring in the object referred to as Nyquist Sampling Frequency/Nyquist Sampling Rate i.e.: fs = 2fmax Another way to state this is that: the sampling interval should be no longer than one-half the cycle interval called Nyquist Sampling interval. For x-interval sampling, the Nyquist Sampling interval ∆xs i.e.: ∆xs = ∆xcycle/2, where, ∆xcycle = 1/fmax * * * * * : Sampling Position It shows the effects of under- sampling
  • 60. 59 In the above figure, the sampling interval is one and one-half times the cycle interval, so the sampling interval is at least 3 times too big. A straight forward antialiasing method is to increase sampling rate by treating the screen as if it were covered with a finer grid that is actually available. We can then use multiple sample points across this finer grid to determine an appropriate intensity level for each screen pixel. This technique of sampling object characteristics at a high resolution and displaying the results at a lower resolution is called super-sampling/post-filtering. An alternative to super-sampling is to determine pixel intensity by calculating the areas of overlap of each pixel with the objects to be displayed. Antialiasing by computing overlap areas is referred to as Area Sampling/Pre-filtering. Pixel overlap areas intersect individual pixel boundaries. Raster objects can also be anti- aliased by shifting the display location of pixel areas. This technique is called pixel phasing is applied by “micro-positioning” the electron beam is relation to object geometry.
  • 61. 60 CHAPTER -4 LINE ATTRIBUTES: This basic attributes of a straight line segment are its type, its width and its color. Lines can also be displayed using selected pen or brush options. i. LINE TYPE: This attribute includes solid lines, dashed lines and dotted line. The line drawing algorithm is modifying to generate lines by setting the length and spacing of displayed solid sections along the line path. A dashed line could be displayed by generating an inter-dash spacing that is equal to the length of the solid sections. Both the length of the dashes and the inter-dash spacing are often specified as user options. A dotted line can be displayed by generating very short dashes with the spacing equal to or greater than the dash size. To set the line type attributes with command is: set linetype (lt); where parameter ‘lt’ is assigned to a positive integer values of 1, 2, 3 or 4 to generate lines that are respectively solid, dashed, dotted or dash-dotted. The line-type parameter ‘lt’ could be used to display variations in dot-dash patterns.
  • 62. 61 ii. LINE WIDTH: Implementation of line-width options depends on the capabilities of the output device. A line-width command is used to set the current line-width value in the attribute set. The command for this is: set linewidthscalefactor(lw) Here line-width parameter ‘lw’ is assigned to a positive number to indicate the relative width of the line to be displayed. A value ‘1’ specifies a standard width line. If a user set ‘lw’ to a value 0.5 to plot a line whose width is half of the standard line. Values greater than ‘1’ produce lines thicker than the standard. Line-caps are used to adjust the shape of the line ends and give better appearance. One kind of line cap is butt cap, obtained by adjusting the end positions of the component parallel lines, so that the thick line is displayed with square ends that are perpendicular to the line path. If the specified line has slope ‘m’, the square end of the thick line has slope 1/m. Another line- cap is the round cap, obtained by adding a filled semicircle to each butt cap. The circular arcs are centered on the line endpoints and have a diameter equal to the line thickness. A third type of line cap is the projecting square cap, where we simply extended the line and add butt caps that are positioned one-half of the line with beyond the specified end points. [BUTTCAP] [ROUNDCAP] [PROJECTING SQUARE CAP]
  • 63. 62 We can generate thick polylines that are smoothly joined at the cost of additional processing at the segment endpoints. A meter join is accomplished by extending the outer boundaries of each of the two lines until they meet. A round join is produced by capping the connection between the two segments with a circular boundary whose diameter is equal to the line width. A bevel join is generated by displaying the line segments with butt caps and filling in the triangular gap where the segments meet. iii. LINE WIDTH: Lines can be displayed with pen and brush selections options in this category include shape, size and pattern. E.g.: , , , , , , :, etc. These shapes can be stored in a pixel mask, which identifies the array of pixel positions that are to be set along the line path. Lines generated with pen or brush shapes can be displayed in various widths by changing the size of the mask. iv. LINE COLOR: When a system provides color or intensity options, a parameter giving the current color index is included in the list of system attribute values. [MITER JOIN] [ROUND JOIN] [BEVEL JOIN]
  • 64. 63 A polyline routine displays a line in the current color by setting this color value in the frame buffer at pixel locations along the line path using the set pixel procedure. The number of color choices depends on the number of bits available per pixel in the frame buffer. The function of line color is: Set PolylineColorIndex(lc), where lc = line color parameter A line drawn in background color is invisible and a user can ensure a previously displayed line by specifying it in the background color. E.g.: set linetype (2); set linewidthscalefactor (2); set PolylineColorIndex (5); Polyline (n1, wcpoints1); set PolylineColorIndex (6); Polyline (n2, wcpoints2); CURVE ATTRIBUTES: Parameters of curve attributes are same as line attributes we can display curves with varying colors, widths, dot-dash patterns and available pen and brush options methods are also same as line attributes. We can generate the dashes in the various octants using circle symmetry, but we must shift the pixel positions to maintain the correct sequence of dashes and spaces as we move from one octant to the next. Raster curves of various widths can be displayed using the method of horizontal or vertical pixel spans, where the magnitude of the curve slope is less than 1, we
  • 65. 64 plot vertical spans, where the slope magnitude is greater than 1, and we plot horizontal spans. Using circle symmetry, we generate the circle path with vertical spans in the octant from x = 0 to x = y and then reflect pixel positions about the line y = x to obtain the remainder of the curve. For displaying the thick curves is to fill area between two parallel curve paths, whose separation distance is equal to the desired width. AREA FILL ATTRIBUTES: i. FILL STYLES: Areas are displayed with 3 basic fill styles. i.e.: hollow with a color border, filled with a solid color or filled with specified pattern or design. The function for basic fill style is: set Interiorstyle(fs); Where fs = fill style parameter and the values include hollow, solid and pattern. Another value for fill style is hatch, which is used to fill an area with selected hatching patterns i.e.: parallel lines or crossed lines. Fill style parameter ‘fs’ are normally applied to polygon areas, but they can also be implemented to fill regions with curved boundaries. Hollow areas are displayed using only the boundary outline with the interior color, same as the background color. A solid fill displayed in a single color upto and including the borders of the region. The color for a solid interior or for a hollow area outline is chosen with: set InteriorColorIndex(fc);
  • 66. 65 Where fc = fill color parameter is set to desired color code. ii. PATTERN FILL: We select fill patterns with set InteriorStyleIndex(Pi), where Pi = Pattern index parameter, specifies a table position. Example: The following set of statements would fill the area defined in the fill area command with the second pattern type stored in the pattern table: set InteriorStyle(Pattern); set InteriorStyleIndexI2); fill Area(n, points); Separate tables are set up for hatch patterns. If we had selected hatch fill for the interior style in this program segment, then the value assigned to parameter ‘Pi’ is an index to the stored patterns in the hatch table. For fill style pattern, table entries can be created on individual output devices with: set PatternRepresentation (ws, Pi, nx, ny, cp); Where, parameter ‘Pi’ sets the pattern index number for workstation ws. cp = two dimensional array of color codes with ‘nx’ columns and ‘ny’ rows. HOLLOW SOLID PATTERN N DIAGONAL HATCH FILL DIAGONAL CROSS HATCH FILL
  • 67. 66 Example: The 1st entry in the pattern table for workstation1 is cp[1, 1] = 4; cp[2, 2] = 4; cp[1, 2] = 0; cp[2, 1] = 0; set PatternRepresentation(1, 1, 2, 2, cp); Index(Pi) Pattern(cp) 1 4 0 0 4 Here, 1st 2 entries for the color table-color array ‘cp’ specifies a pattern that produces alternate red and black diagonal pixel 2 2 1 2 1 2 1 2 1 2 When a color array ‘cp’ is to be applied to fill a region, we specify the size of the area that is to be converted by each element of the array. We do this by setting the rectangular co-ordinate extents of the pattern: set Patternsize(dx, dy); Here dx and dy is the co-ordinate width and height of the array mapping. A reference position for starting a pattern fill is assigned with the statement: set PatternReferencepoint(position); Here, position = pointer to co-ordinate (xp, yp) that fix the lower left corner of the rectangular pattern. Form this starting position, the pattern is then replicated in the ‘x’ and ‘y’ directions until the defined area is covered by non-overlapping copies of pattern array. The process of filling an area
  • 68. 67 with a rectangular pattern is called tiling and rectangular fill patterns are sometimes referred to a tiling pattern. If the row positions in the pattern array are referred in reverse (i.e.: from bottom to top starting at 1), a pattern value is then assigned to pixel position (x, y) in screen or window co-ordinate as: set Pixel(x, y, cp(y mod ny + 1), (x mod nx + 1)) Where, ‘nx’ and ‘ny’ = number of rows and columns in pattern array. iii. SOFT FILL: Modified boundary fill and flood fill procedures that are applied to repaint areas, so that the fill color is combined with background colors are referred to as Soft-fill/Tint-fill algorithm. A linear soft fill algorithm repaints an area that was originally painted by merging a foreground color ‘F’ with a single background color ‘B’. Assume, we know the values for ‘F’ and ‘B’, we can determine how these colors were originally combined by checking the current color contents of the frame buffer. The current RGB color ‘P’ of each pixel within the area to be refilled is some linear combination of ‘F’ and ‘B’. P = tF + (1 – t)B --- (1) Where, the transparency factor ꞌtꞌ has a value between 0 and 1 for each pixel. For value of ꞌtꞌ less than 0.5, the background color contributes more to the interior color of the region that does the fill color.
  • 69. 68 The vector equation – (1) holds for each, P = (PR, PG, PB), F = (FR, FG, FB), B = (BR, BG, BB) --- (2). So, we can calculate the value of parameter ꞌtꞌ using one of the RGB color component as: t = PK – BK/FK – BK --- (3), Where K = R, G or B and FK ≠ BK. The parameter ꞌtꞌ has the same value for each RGB component but round off to integer codes can result in different values of 't' for different components. We can minimize this round off error by selecting the component with the largest difference between ‘F’ and ‘B’. This value of ꞌtꞌ is then used to mix the new fill color ‘NF’ with the background color, using either a modified flood-fill or boundary-fill procedure. Soft-fill procedures can be applied to an area whose foreground color is to be merged with multiple background color areas. E.g.: check board pattern. When two background colors B1 and B2 are mixed with foreground color ‘F’, the resulting pixel color ‘P’ is: P = t0F + t1B1 + (1 – t0 – t1)B2 --- (4) Where the sum of the coefficients ‘t0’, ‘t1’ and (1 – t0 – t1) on the color terms must equal to 1. These parameters are then used to mix the new fill color with parameters are then used to mix the new fill color with the two background colors to obtain the new pixel color.
  • 70. 69 FILLED AREA ATTRIBUTES WITH IRREGULAR BOUNDARY: i. CHARACTER ATTRIBUTES: Here, we have to control the character attributes, such as font size, color and orientation. Attributes can be set both for entire character string (text) and for individual characters defined as marker symbols. a. Text Attributes: It includes the font (type face) which is a set of characters with a particular design style, such as: Courier, Times Roman etc. This is also displayed with assorted underlying styles. i.e.: solid, dotted, double and also the text may be boldface, italics or in outline or shadow style. A particular font and associated style is selected by setting an interior code for the text font parameter ‘tf’ in the function: set Textfont(tf); Color setting for displayed text is done by the function: set TextColorIndex(tc); Here ‘tc’ = text color parameter specifies an allowable color code. Text size can be adjusted without changing the width to height ratio of characters with: set CharacterHeight(ch); Here ‘ch’ is assigned a real value greater than 0 to set the coordinate height of capital letters.
  • 71. 70 The width of text can be set with the function: set CharacterExpansionFactor(cw); Here, cw = character-width parameter is set to positive real value that scales the body width of characters. Text height is unaffected by this attributed setting. Spacing between characters is controlled separately with: set CharacterSpacing(cs); Here cs = character spacing parameter can be assigned any real value. The value assigned to ‘cs’ determine the spacing between character bodies along print lines. Negative values for ‘cs’ overlap character bodies positive values insert space to spread out the displayed characters. The orientation for a displayed character string is set according to the direction of the character up vector: set CharacterUpVector(upvect); Parameter ‘upvect’ in this function is assigned two values that specify the ‘x’ and ‘y’ vector components. Text is then displayed, so that the orientation of characters from baseline to cap line in the direction of the up-vector. A procedure for orienting text rotates characters so that the sides of character bodies, from baseline to cap line are aligned with the up-vector. The rotated character shapes are then scan converted into the frame buffer. An attributes parameter for this option is set with the statement: set TextPath(tp);
  • 72. 71 Here tp = text path can be assigned with the value right, left, up, down, horizontal, vertical etc. For text alignment, the attribute specifies how text is to be positioned with respect to the start coordinates. Alignment attributes are set with: set TextAlignment(h, v); Here ‘h’ and ‘v’ control horizontal and vertical alignment respectively. Horizontal alignment is set by assigning ‘h’, a value of left, center and right. Vertical alignment is set by assigning ‘v’, a value of top, cap, half, base or bottom. A precision specification for text display is given with: set TextPrecision(tpr); Here tpr = text precision parameter is assigned one of the values: string, char or stroke. The highest quality ‘text’ is displayed when the precision parameter is set to the value stroke. For this precision setting, greater detail would be used in defining the character shapes and the processing of attributes selection and other string manipulation procedures would be carried out to the highest possible accuracy. The lowest quality precision setting, string is used for faster display of character string.
  • 73. 72 b. Marker Attributes: A marker symbol is a single character that can be displayed in different colors and in different sizes. Marker attributes are implemented by procedures that load the choses character into the raster at the defined positions with the specified color and size. We select a particular character to be the marker symbol with: set MarkerType(mt); Here, mt = marker type parameter is set to an integer code. Typical codes for marker type are integers 1 through 5, specifying respectively, a dot (.), a vertical cross (+), an asterisk (*), a circle (O) and a diagonal cross (x). Displayed marker types are centered on the marker coordinates we set the marker size with: set MarkerSizeScaleFactor(ms); Here, ms = marker size parameter, assigned a positive number. It is applied to the normal size for the particular marker symbol chosen, values greater than 1 produce character enlargement; values less than 1 reduce the marker size. Marker color is specified with: set PolymarkerColorIndex(mc); Here, mc = selected color code, stored in current attribute list and used to display subsequently specified market primitives. ii. BUNDLED ATTRIBUTES: When each function references a single attribute, then that specifies exactly how a primitive is to be displayed with that attribute setting. These
  • 74. 73 specifications called Individual/Unbundled Attributes and they are used with an output device that is capable of displaying primitives in the way specified. A particular set of attribute values for a primitive on each output device is then chosen by specifying the appropriate table index. Attributes specified in this manner are called Bundled Attributes. The table for each primitive that defined groups of attributes values to be used when displaying that primitive on particular output device is called a Bundle table. Attributes that may be bundled into the workstation table entries are those that don’t involve co-ordinate specifications, such as color and line type. The choice between a bundled and an unbundled specification is made by setting a switch called the aspect source flag for each of these attributes: set IndividualASF(attribute ptr, flag ptr); Where ‘attribute ptr’ parameter points to a list of attributes and parameter ‘flag ptr’ points to the corresponding list of aspect source flags. Each aspect source flag can be assigned a value of individual or bundled. a. Bundled Line Attributes: Entries in the bundle table for line attributes on a specified workstation are set with function: set PolylineRepresentation(ws, li, lt, lw, lc); Here, ws = workstation identifier, li = line index parameter, defined the bundle table position. Parameter lt, lw and lc are then bundled and assigned values to set the line type, line width and line color specifications respectively for the designated table index.
  • 75. 74 E.g.: set PolylineRepresentation(1, 3, 2, 0, 5, 1); set PolylineRepresentation(4, 3, 1, 1, 7); Here, a polyline that is assigned a table index value of 3 would then be displayed using dashed lines at half thickness in a blue color on workstation ‘1’ while on workstation 4, this same index generates solid standard sized white lines. Once the bundle tables have been set up a group of bundled line attributes is chosen for each workstation by specifying the table index value. set PolylineIndex(li); b. Bundled Area Fill Attributes: Table entries for bundled area-fill attributes are set with: set InteriorRepresentation(ws, fi, fs, Pi, fc); This defines the attribute list corresponding to fill index ‘fi’ on workstation ws. Parameter ‘fs’, ‘Pi’, and ‘fc’ are assigned values for the fill style, pattern index and fill color respectively on the designated workstation. Similar bundle tables can also be set up for edge attributes of polygon fill areas. A particular attribute bundle is then selected from the table with the function: set InteriorIndex(fi); Subsequently defined fill areas are then displayed on each active workstation according to the table entry specified by the fill index parameter ‘fi’.
  • 76. 75 c. Bundles Text Attributes: The function is: set TextRepresentation(ws, ti, tf, tp, te, ts, tc); Which bundles value for text font, precision, expansion factor, size, and color in a table position for workstation ‘ws’ that is specified by the value assigned to text index parameter ‘ti’. Other text attributes, including character up vector, text, path, character height and text alignment are set individually. A particular text index value is then chosen with the function: set TextIndex(ti); Each text function that is then invoked is displayed on each workstation with the set of attributes referenced by this table position. d. Bundled Marker Attributes: Table entries for bundled marker attributes are set up with: set PolymarkerRepresentation(ws, mi, mt, ms, mc); This defined the marker type, marker scale factor and marker color for index ‘mi’ on workstation ws. Bundle table sections are then made with the function: set PolymarkerIndex(mi);
  • 77. 76 CHAPTER -5 2D TRANSFORMATION: A fundamental objective of 2D transformation is to simulate the movement and manipulation of objects in the plane. There are 2 points of view are used for describing the object movement. That is: i. The object itself is moved relative to a stationary co-ordinate system or background. The mathematical statement of this viewpoint is described by geometric transfer motions applied to each point of the object. ii. The second view holds that the object is held stationary, while the co- ordinate system is moved relative to the object. This effect is attained through the application of co-ordinate transformations. The transformations are used directly by application programs and within many graphic sub-routines. BASIC TRANSFORMATION IN 2D: In 2D Transformation, the basic transformation includes 3 parameters to reposition and resize the 2D objects. i.e.: Translation, Rotation and Scaling. i. TRANSLATION: A translation is applied to an object by repositioning it along a straight line path from one-coordinate location to another. We translate a 2D point by adding translation distance ‘tx’ and ‘ty’ to the original co-ordinate position (x, y) to move the point to a new position (xꞌ, yꞌ). So,
  • 78. 77 xꞌ = x + tx, yꞌ = y + ty --- (1) The translation distance pair (tx, ty) is called a translation vector or shift vector. The equation can be express as a single matrix equation by using the column vector to represent co-ordinate positions and the translation vector are: ii. ROTATION: A 2D Rotation is applied to an object by repositioned it along a circular path in xy-plane. To generate a rotation angle θ, and the position (xr, yr) of the rotation or pivot point, about which the object is to be rotated. Positive values for the rotation angle define counter clockwise rotations about the pivot point and negative values rotate objects in clockwise direction. This transformation can also be described as a rotation about a rotation axis, which is perpendicular to xy-plane and passes through pivot point. The transformation equations for rotation of point position ‘P’, when the pivot point is at the co-ordinate origin. r = constant distance of the point from origin. θ = rotation angle Φ = original angular position of the point from horizontal. X1 X2 P = Xꞌ1 Xꞌ2 Pꞌ = tx ty T = --- (2)
  • 79. 78 So, transformed co-ordinates in terms of angle θ and Φ are: The original co-ordinates of the point in polar co-ordinates are: Substitute equation – (2), in equation – (1), we get the transformation equation, for rotating a point of position (x, y) through an angle ‘θ’ about the origin. We can write the rotation equation in matrix from is: Pꞌ = R.P --- (4), where rotation matrix is: When co-ordinate positions are represented as row vectors instead of column vectors, the matrix product in rotation equation – (4) is transposed, so that the transformed row co-ordinate vector [xꞌ, yꞌ] is calculated as: xꞌ = rcos(θ + Φ) = rcosΦcosθ – rsinΦsinθ yꞌ = rsin(θ + Φ) = rcosΦsinθ + rsinΦcosθ --- (1) x = rcosΦ y = rsinΦ --- (2) xꞌ = xcosθ – ysinθ yꞌ = xsinθ + ycosθ --- (3) cosθ - sinθ sinθ sinθ cosθ R = --- (5) (Clockwise direction) cosθ sinθ - sinθ cosθ R = --- (6) (Anti-Clockwise direction)
  • 80. 79 PꞌT = (R.P)T = PT .RT --- (7) Where PT = [x y] RT = Transpose of ‘R’ obtain by interchanging the rows and columns. The transformation equation for rotation of a point about any specified rotation position (xr, yr) is: Example 1: Consider an object ‘ABC’ with co-ordinates A(1, 1), B(10, 1), C(5, 5). Rotate the object by 90 degree in anticlockwise direction and give the co-ordinates of the transformed object. Example 2: Perform a 45 degree rotation of the object A(2, 1), B(5, 1) and C(5, 6) in clockwise direction and give the co-ordinates of the transformed objects. xꞌ = xr + (x –xr)cosθ – (y – yr)sinθ yꞌ = yr + (x –xr)sinθ + (y – yr)cosθ --- (8) A B C 1 10 5 1 1 5 X = cosθ sinθ - sinθ cosθ R = cos90 sin90 - sin90 cos90= 0 1 -1 0 = 1 10 5 1 1 5 Xꞌ = [X].[R] = 0 1 -1 0 -1 -1 -5 1 10 5 = A B C
  • 81. 80 iii. SCALING: A scaling transformation alters the size of the object. This operation can be carried out for polygons by multiplying the co-ordinate values (x, y) of each vertex by scaling factors ‘Sx’ and ‘Sy’ to produce the transformed co- ordinates (xꞌ, yꞌ) as: xꞌ = x . Sx and yꞌ = y . Sy --- (1) Scaling factors ‘Sx’ scales objects in the x-direction, while ‘Sy’ scales in the y-direction. The transformation equation in matrix form is: Or, Pꞌ = S. P --- (3) The scaling factors ‘Sx’ and ‘Sy’ is less than 1, reduce the size of objects, values greater than 1 produce an enlargement. Specifying a value of 1for both ‘Sx’ and ‘Sy’ leaves the size of objects unchanged. When ‘Sx’ and ‘Sy’ A B C 2 5 5 1 1 6 X = cosθ - sinθ sinθ cosθ R = cos45 - sin45 sin45 cos45 = 1/√2 -1/√2 1/√2 1/√2 = Xꞌ = [X].[R] = 2 5 5 1 1 6 1/√2 -1/√2 1/√2 1/√2 3/√2 6/√2 11/√2 -1/√2 -4/√2 1/√2 = B C A xꞌ yꞌ = Sx 0 0 Sy x y --- (2)
  • 82. 81 are assigned the same value, a uniform scaling is produced that maintains relative object proportions. We can control the location of a scaled object by choosing a position, called the fixed point that is to remain unchanged after the scaling transformation. Co-ordinates for the fixed point (xf, yf) can be chosen as one of the vertices, the object centroid or any other position. For a vertex, with co-ordinates (x, y), the scaled co-ordinates (xꞌ, yꞌ) are calculated as: xꞌ = xf + (x – xf)Sx and yꞌ = yf + (y – yf)Sy --- (4) The scaling transformations to separate the multiplicative and additive items: xꞌ = x . Sx + xf(1 – Sx) and yꞌ = y . Sy + yf(1 – Sy) --- (5) Where, the additive terms xf(1 – Sx) and yf(1 – Sy) are constant for all points in the object. Example 1: Scale the object with co-ordinates A(2, 1), B(2, 3), C(4, 2) and D(4, 4) with a scale factor Sx = Sy = 2. Sx 0 0 Sy S = 2 0 0 2 = X = 2 4 4 1 3 2 2 4
  • 83. 82 Example 2: What will be the effect of scaling factor Sx = 1/2 and Sy = 1/3 on a given triangle ABC whose co-ordinates are: A[4, 1], B[5, 2], C[4, 3]? OTHER TRANSFORMATION: i. REFLECTION: A reflection is a transformation that produces a mirror image of an object. The mirror image for a 2D reflection is generated relative to an axis of reflection by the object 180 degree about the reflection axis. Reflection about x-axis, the line y = 0, the x-axis is accomplished with the transforming matrix is given below. This transformation keeps ‘x’ values the same, but flips the y-value of co-ordinate positions. Xꞌ = [X].[S] = 4 4 5 1 2 3 1/2 0 0 1/3 = 2 2 1/3 2/3 1 5/2 X = 4 4 1 2 3 5 Sx 0 0 Sy S = 1/2 0 0 1/3 = Xꞌ = [X].[S] = 2 4 2 4 1 3 2 4 2 0 0 2 = 4 8 8 2 6 4 4 8
  • 84. 83 The reflection about y-axis flips ‘x’ co-ordinates while keeps ‘y’ co- ordinates the same. The matrix for this transformation is: We flip both ‘x’ and ‘y’ co-ordinates of a point by reflecting relative to an axis that is perpendicular to xy-plane and that passes through the co- ordinate origin. The transformation referred to as a reflection relative to the co-ordinate origin has the matrix representation is: 1 2 3 2ꞌ 3ꞌ 1ꞌ x y Original Position Reflected Position or ---- (1) 1 0 0 -1 0 1 0 0 0 1 0 0 -1 1 2 3 2ꞌ 3ꞌ 1ꞌ y x Original Position Reflected Position or ---- (2) -1 0 0 1 0 1 0 0 0 -1 0 0 1 12 3 2ꞌ 3ꞌ 1ꞌ y x Original Position Reflected Position or ---- (3) -1 0 0 -1 0 1 0 0 0 -1 0 0 -1
  • 85. 84 If we choose the reflection axis as the diagonal line y = x, the reflection matrix is: To obtain a transformation matrix for reflection about the diagonal y = -x, we could concatenate matrices for transformation sequence. i. Clockwise rotation by 45 degree ii. Reflection about y-axis. iii. Counter clockwise rotation by 45 degree. The resulting transformation matrix is: or ---- (4) 0 1 1 0 0 1 0 0 0 0 1 1 0 12 3 2ꞌ 3ꞌ 1ꞌ y x Original Position Reflected Position or 0 1 1 0 0 1 0 0 0 0 1 1 0 12 3 2ꞌ 3ꞌ 1ꞌ y x Original Position Reflected Position y = x 450 y x 450
  • 86. 85 Example: Consider a triangle ABC whose co-ordinate are: A= [4 1], B = [5, 2], and C = [4, 3]. a) Reflect the given triangle about x-axis; b) reflect the given triangle about y-axis, c) reflect the given triangle about y = x and d) reflect the given triangle about y = -x. a) The transformation matrix for reflection about x-axis is: b) The transformation matrix for reflection about y-axis: c) The transformation matrix for reflection about y = x is: d) The transformation matrix for reflection about y = -x is: ii. SHEARING: A transformation that distorts the shape of an object such that transformed shape appears as if the object were composed of internal layers that had been called to slide over each other is called a ‘Shear’. Two X = 4 5 1 2 [T] = => Xꞌ = [X][T] = 4 3 1 0 0 -1 4 5 -1 -2 4 -3 X = 4 5 1 2 [T] = => Xꞌ = [X][T] = 4 3 -1 0 0 1 - 4 - 5 1 2 - 4 3 X = 4 5 1 2 [T] = => Xꞌ = [X][T] = 4 3 0 1 1 0 1 2 4 5 3 4 X = 4 5 1 2 [T] = => Xꞌ = [X][T] = 4 3 0 -1 -1 0 -1 -2 -4 -5 -3 -4
  • 87. 86 common shearing transformations are those shift co-ordinate x-values and those that shift y-values. An x-direction shear relative to x-axis is produced with transformation matrix is: This transforms co-ordinate position as: xꞌ = x + shx . y and yꞌ = y --- (2) A y-direction shear relative to y-axis is produced with transformation matrix is: This transforms co-ordinate position as: xꞌ = x and yꞌ = shy . x + y --- (4) Any real number can be assigned to the shear parameter ‘Shx’. A co- ordinate position (x, y) is then shifted horizontally by an amount proportional to its distance (y-value) from x-axis (y = 0). We can generate x- direction shears relative to other reference lines with: --- (1) 1 0 shx 1 0 1 0 0 0 --- (3) 1 shy 0 1 0 1 0 0 0
  • 88. 87 With co-ordinate positions transformed as: xꞌ = x + shx(y – yref) and yꞌ = y --- (6) A y-direction shear relative to the line x = xref is generated with transformation matrix is: This generates transformed co-ordinate position: xꞌ = x and yꞌ = shy(x – xref) + y --- (8) Example: Consider a unit square, find the co-ordinate of transformed object when the transformed matrix of shearing for x-axis, shx = 2. --- (5) 1 0 shx 1 -shx . yref 1 0 0 0 --- (7) 1 shy 0 1 0 1 -shy . xref 0 0 Xꞌ = [X].[T] =X = 0 1 0 0 0 1 1 1 1 2 0 1 T = = 0 1 1 0 2 3 1 1 1 2 0 1 0 1 0 0 0 1 1 1
  • 89. 88 MATRIX REPRESENTATION AND HOMOGENEOUS CO-ORDINATES: The basic transformations can be expressed in the general matrix form: Pꞌ = M1.P +M2 --- (1) With co-ordinate positions ‘P’ and ‘Pꞌ’ represented as column vectors. Matrix ‘M’ is a 2 by 2 array containing translational terms. For translation, M1 = identity matrix. For rotation or scaling, M2 contains the translational terms associated with the pivot point or scaling fixed point. To express any 2D transformation as a matrix multiplication, we represent each Cartesian co-ordinate position (x, y) with the homogeneous co-ordinate triple (xh, yh, h) where: x = xh/h, y = yh/h --- (2) A general homogeneous co-ordinate representation can also be written as (h.x, h.y, h). For 2D geometric transformations, the homogeneous parameter ‘h’ must be any non-zero value. Thus there are an infinite number of equivalent homogeneous representations for each co-ordinate point (x, y). A D C B 1 1 (1, 1) (0, 0) A* D* C* B* 1 1(0, 0) 2 3
  • 90. 89 A convenient choice is simply to set h = 1. Each 2D position is then represented with homogeneous co-ordinates (x, y, 1). Other values for parameter ‘h’ are needed. The homogeneous co-ordinates are used in mathematics to refer to the effect of this representation on Cartesian equations. When a Cartesian point (x, y) is converted to a homogeneous representation (xh, yh, h) equations containing ‘x’ and ‘y’ such as f(x, y) = 0, become homogeneous equations in the three parameters xh, yh and h. If each of the three parameters replaced by any value ‘v’ times that parameter, the value ‘v’ can be factored out of the equations. Expressing positions in homogeneous co-ordinates allows us to represent all geometric transformation equation as matrix multiplications. Co-ordinates are represented with three element column vectors and transformation operations are written as 3 by 3 matrices. For translation, we have: This can be written in abbreviated form: Pꞌ = T(tx, ty).P --- (4) Here T(tx, ty) as the 3 by 3 translation matrix. The inverse of the translation matrix is obtained by replacing the translation parameter ‘tx’ and ‘ty’ with their negatives ‘- tx’ and ‘- ty’. Rotation transformation equations about the co-ordinate origin are now written as: xꞌ yꞌ 1 1 0 0 0 1 0 tx ty 1 x y 1 = --- (3)
  • 91. 90 Or as, Pꞌ = R(θ).P --- (6) The rotation transformation operation R(θ) is the 3 by 3 matrix with rotation parameter ‘θ’. We get the inverse rotation matrix when ‘θ’. We get the inverse rotation matrix when ‘θ’ is replaced with ‘- θ’. Finally a scaling transformation relative to the co-ordinate origin is now expressed as the matrix multiplication. Or as, Pꞌ = S(Sx, Sy).P --- (8) Here S(Sx, Sy) is the 3 by 3 matrix with parameter ‘Sx’ and ‘Sy’. Replacing these parameters1/Sx and 1/Sy, with their multiplicative inverse yields inverse scaling matrix. TRANSFORMATION BETWEEN CO-ORDINATE SYSTEMS: Here, the two Cartesian system with the co-ordinate origins at (0, 0) and (x0, y0) and with an orientation angle ‘θ’ between ‘x’ and xꞌ-axis. To transform object description from ‘xy’ co-ordinate to ‘xꞌyꞌ’ co-ordinates, we need to set up a transformation that super imposes the xꞌyꞌ-axes into xy-axes. This is done in two steps: xꞌ yꞌ 1 cosθ sinθ 0 - sinθ cosθ 0 0 0 1 x y 1 = --- (5) xꞌ yꞌ 1 Sx 0 0 0 Sy 0 0 0 1 x y 1 = --- (7)
  • 92. 91 i. Translate so that the origin (x0, y0) of xꞌyꞌ system is moved to the origin of the xy system. ii. Rotate the xꞌ-axis onto the x-axis. iii. Translation of the co-ordinate origin is expressed with the matrix operation. The orientation of the two systems after the translation operation would appear. To get the axes of the two systems into coincidence, we then perform the clockwise rotation. Concatenating these 2 transformations matrices gives us the complete composite matrix for transforming object descriptions from the xy-system to the xꞌyꞌ-system: Mxy, xꞌyꞌ = R(-θ).T(-x0, - y0) --- (3) x-axis y-axis yꞌ-axis xꞌ-axis θ yv T(-x0, - y0) = 1 0 0 0 1 0 -x0 -y0 1 --- (1) R(-θ) cosθ - sinθ 0 sinθ cosθ 0 0 0 1 = --- (2) θ x-axis y-axis yꞌ-axis xꞌ-axis yꞌ xꞌ Py
  • 93. 92 An alternative method for giving the orientation of the second co-ordinate system is to specify a vector ‘V’ that indicates the direction for the position of yꞌ- axes. Vector ‘V’ is specified as a point in the xy-reference frame relative to the origin of the xy-system. A unit vector in the yꞌ-direction can then obtained as: V = V/|V| = (Vx, Vy) --- (4) The unit vector ‘u’ along xꞌ-axis by rotating ‘V’ as -90 degree clockwise as: u = (Vy, -Vx) = (ux, uy) --- (5) The elements of any rotation matrix could be expressed as elements of a set of orthogonal unit vectors. So the matrix to rotate xꞌyꞌ-system into coincidence with the xy-system can be written as: Suppose we choose the orientation for the yꞌ-axis as v = (-1, 0), then the xꞌ-axis is in the positive y-direction and the rotation transformed matrix is: x-axis y-axis yꞌ-axis xꞌ-axis V y0 x0 R ux vx 0 uy vy 0 0 0 1 = --- (6) 0 -1 0 1 0 0 0 0 1 --- (7)
  • 94. 93 Equivalently, we can obtain this rotation matrix by setting the orientation angle as θ = 90o . In an interactive application, it may be more convenient to choose the direction for ‘V’ relative to position ‘P0’ than it is to specify it relative to the xy-co- ordinate origin. Unit vectors ‘u’ and ‘v’ would then be oriented. COMPOSITE TRANSFORMATION: i. TRANSLATION: If 2 successive translation vectors (tx1, ty1) and (tx2, ty2) are applied to a co-ordinate position ‘P’, the final transformed location ‘Pꞌ’ is calculated as: Pꞌ = T(tx2, ty2). {T(tx1, ty1).P} = {T(tx2, ty2).T(tx1, ty1). P} --- (1) Where, ‘P’ and ‘Pꞌ” are represented as homogeneous co-ordinate column vectors. The composite transformation matrix for this sequence of translation is: Or, T(tx2, ty2).T(tx1, ty1) = T(tx1 + tx2, ty1 + ty2) --- (3) 1 0 0 0 1 0 tx2 ty2 1 = --- (2)0 0 0 1 0 tx1 + tx2 ty1 + ty2 1 11 0 0 0 1 0 tx1 ty1 1 x-axis y-axis yꞌ-axis xꞌ-axis V = P1 – P0 y0 x0 The components of ‘v’ are now calculated as: V = P1 – P0/|P1 – P0| --- (8), and ‘u’ is obtained as the perpendicular ‘v’ that forms a right-handed Cartesian system.
  • 95. 94 This demonstrates that 2 successive translations are additive. ii. ROTATION: Two successive rotations applied to point ‘P’ produce the transformed position: Pꞌ = R(θ2).{R(θ1).P} = {R(θ2).R(θ1)}.P --- (1) By multiplying the 2 rotation matrices, we can verify that 2 successive rotations are additive. That is: R(θ2).R(θ1) = R(θ1 + θ2) --- (2) So, that the final rotated co-ordinates can be calculated with the composite rotation matrix as: Pꞌ = R(θ1 + θ2).P --- (3) iii. SCALING: Concatenating transformation matrix for 2 successive scaling operations produces the following composite scaling matrix: Or, S(Sx2, Sy2).S(Sx1, Sy1) = S(Sx1 + Sx2, Sy1 + Sy2) ---- (2) iv. GENERAL PIVOT POINT ROTATION: We can generate rotations about any selected pivot point (xr, yr) by performing the following sequence, translate-rotate-translate operations. Sx2 0 0 0 Sy2 0 0 0 1 Sx1 0 0 0 Sy1 0 0 0 1 = Sx1.Sx2 0 0 0 Sy1.Sy2 0 0 0 1 --- (1)
  • 96. 95 i. Translate the object, so that the pivot point position is moved to the co-ordinate origin. ii. Rotate the object about the co-ordinate origin. iii. Translate the object, so that the pivot-point is reformed to its original position. That is: T = [Tr][Rθ][Tr]-1 = T(xr, yr).R(θ).T(-xr, -yr) Example: Consider a triangle ABC having co-ordinate a = [4, 1], B = [5, 2] and C = [4, 3]. Rotate it by an angle 90 degree about point ꞌAꞌ in anticlockwise direction. Give the co-ordinates of rotated triangle. = 1 0 0 0 1 0 xr yr 1 1 0 0 0 1 0 -xr -yr 1 cosθ sinθ 0 - sinθ cosθ 0 0 0 1 = 1 0 m 0 1 n 0 0 1 1 0 4 0 1 1 0 0 1 [Tr] = cos90 - sin90 0 sin90 cos90 0 0 0 1 [Rθ] = 0 -1 0 1 0 0 0 0 1 = [Tr]-1 = 1 0 -4 0 1 -1 0 0 1 Xꞌ = [X].[T], [T] = [Tr] [Rθ] [Tr]-1 = 1 0 00 1 0 xr yr 1 1 0 0 0 1 0 -xr -yr 1 cosθ sinθ 0 - sinθ cosθ 0 0 0 1
  • 97. 96 v. GENERAL FIXED POINT SCALING: A transformation sequence to produce scaling with respect to a selected fixed point position (xf, yf) using a scaling function that can only scale relative to the co-ordinate origin. i. Translate object, so that the fixed point coincides with the co-ordinate origin. ii. Scale the object with respect to the co-ordinate origin. iii. Use the inverse translation of step-1 to return the object to its original position. That is: T = [Tr][S][Tr]-1 => T(xf, yf).S(Sx, Sy).T(-xf, -yf) = S(xf, yf, Sx, Sy) --- (2) 1 0 xf 0 1 yf 0 0 1 Sx 0 0 0 Sy 0 0 0 1 1 0 -xf 0 1 -yf 0 0 1 = = Sx 0 xf(1-Sx) 0 Sy yf(1-Sy) 0 0 1 --- (1)= = => [T] = 1 0 4 0 1 1 0 0 1 0 -1 0 1 0 0 0 0 1 1 0 -4 0 1 -1 0 0 1 0 -1 5 5 1 0 -3 0 0 1 = => Xꞌ = 4 5 4 1 2 3 1 1 1 4 3 2 1 2 1 1 1 1 0 -1 5 5 1 0 -3 0 0 1 =
  • 98. 97 Example: Consider an object ABCD with given co-ordinates A(10, 10), B(60, 10), C(60, 60) and D(10, 60). It is desired to double the size of the object, keeping in mind that point ‘A’ remains the same. T = [Tr][S][Tr]-1 and Xꞌ = [X].[T] vi. GENERAL SCALING DIRECTIONS: Parameters ‘Sx’ and ‘Sy’ scale objects along the ‘x’ and ‘y’ directions. We can scale an object in other directions by rotating the object to align the desired scaling directions with the co-ordinate axes before applying the scaling transformations. Suppose we want to apply scaling factors with values by parameters ‘S1’ and ‘S2’ in the directions. To accomplish the scaling without changing the orientation of the object, we first perform a rotation, so that the directions for ‘S1’ and ‘S2’ coincide with ‘x’ and ‘y’-axes respectively. Then, the scaling is applied, followed by an opposite rotation to return points to their original orientations. 1 0 0 0 1 0 10 10 1 2 0 0 0 2 0 0 0 1 1 0 -xf 0 1 -yf -10 -10 1 T = 2 0 0 0 2 0 -10 -10 1 = = Xꞌ = 2 0 0 0 2 0 -10 -10 1 = = 10 10 1 60 10 1 60 60 1 10 60 1 10 10 1 110 10 1 110 110 1 10 110 1
  • 99. 98 The composite matrix resulting from the product of these three transformations is: R-1 (θ).S(S1, S2).R(θ) vii. CONCATENATION PROPERTIES: Matrix multiplication is associative. For any 3 matrices A, B and C, the matrix product A.B.C can be performed by first multiplying ‘A’ and ‘B’ or by first multiplying ‘B’ and ‘C’: A.B.C = (A.B).C = A.(B.C). So, we can evaluate matrix products using either a left-to-right or right-to-left associative grouping. On other hand, transformation products may not be cumulative. The matrix product A.B is not equal to B.A, in general. This means that if we want to translate and rotate an object. viii. GENERAL COMPOSITE TRANSFORMAITON AND COMPUTATIONAL EFFICIENCY: A general 2D transformation, representing a combination of translations, rotations and scaling can be expressed as: S1cos2 θ + S2sin2 θ (S2 – S1)cosθsinθ S1sin2 θ + S2cos2 θ(S2 – S1)cosθsinθ 00 0 0 1 = xꞌ yꞌ 1 rSxx rSyx 0 rSxy rSyy 0 trSx trSy 1 x y 1 = --- (1)
  • 100. 99 The 4 elements ‘rSij’ are the multiplicative rotation scaling terms containing in the transformation that involve only rotation angles and scaling factors. Elements trSx and trSy are the translational terms containing combinations of translation distances pivot point and fixed point co- ordinates and rotation angle and scaling parameters. If an object is to be scaled and rotated about its centroid co-ordinates (xc, yc) and then translated, the values for the elements of the composite transformation matrix are: T(tx, ty).R(xc, yc, θ).S(xc, yc, Sx, Sy) To explicit calculations for the transformed co-ordinates are: xꞌ = x.rSxx + y.rSyy + trSx and yꞌ = x.rSyx + y.rSyy + trSy --- (3) A general rigid body transformation matrix, involving only translations and rotations can be expressed in the form: Where the four elements ‘rij’ are the multiplicative rotation terms and elements ‘trx’ and ‘try’ are the translational terms. A rigid body change in coordinate position is also sometimes referred to as a rigid-motion transformation. All angles and distances between co-ordinate positions are unchanged by the transformation. The matrix 3 has the property that its Sxcosθ – Sysinθ SycosθSxsinθ 00 xc(1 - Sxcosθ) + ycSysinθ + tx yc(1 – Sycosθ) - xcSxsinθ + ty 1 = --- (2) rxx rxy ryyryx 00 trx try 1 --- (4)
  • 101. 100 upper left 2 by 2 sub-matrix is an orthogonal matrix. This means that if we consider each row of the sub-matrix as a vector, then the 2 vectors (rxx, rxy) and (ryx, ryy) from an orthogonal set of unit vectors. Each vector has unit length: rxx 2 + rxy 2 = ryx 2 + ryy 2 = 1 --- (5) and the vectors are perpendicular i.e.: rxxrxy + ryxryy = 0 --- (6) (their dot product is 0). Therefore, if these unit vectors are transferred by the rotation sub-matrix (rxx, rxy) is converted to a unit vector along the x-axis and (ryx, ryy) is transformed into a unit vector along the y-axis of the co-ordinate system. The rigid body transformation first rotates an object through an angle ‘θ’ about a pivot point (xr, yr). The orthogonal unit vectors in the upper left 2 by 2 sub-matrix are (cosθ, -sinθ) and (sinθ, cosθ) and unit vector (sinθ, cosθ) is converted by the transformation matrix into the unit vector (0, 1) in the y-direction. rxx rxy 1 = rxx rxy ryyryx 00 0 0 1 1 0 1 --- (7) ryx ryy 1 = rxx rxy ryyryx 00 0 0 1 1 0 1 --- (8) cosθ – sinθ cosθsinθ 00 xr(1 - cosθ) + yrsinθ + tx yr(1 – cosθ) – xrsinθ + ty 1 T(tx, ty).R(xr, yr, θ) = --- (9)
  • 102. 101 When the rotation angle is small the trigonometric functions can be replaced with approximation values based on the first few terms of their power series expansions. For small enough angles, ‘cosθ’ is approximately 1 and ‘sinθ’ has value close to the value of ‘θ’ in radians. If we are rotating in small angular steps about the origin for instance, we can set cosθ to 1 and reduce transformation calculations at each step to two multiplications and two additions for each set of co-ordinates to be rotated. xꞌ = x – ysinθ and yꞌ = xsinθ – y --- (11) Where ‘sinθ’ is evaluated once for all steps, assuming the rotation angle does not change. AFFINE TRANSFORMATION: A co-ordinate transformation of the form: xꞌ = axxx + axyy + bx and yꞌ = ayxx + ayyy + by --- (1) This is called a 2-dimensional affine transformation. Each of the transformed co-ordinates ‘xꞌ’ and ‘yꞌ’ is a linear function of the original co-ordinates ‘x’ and ‘y’ and parameters ‘aij’ and ‘bk’ are constants determined by the transformation type. Affine transformations have the general properties that parallel lines are transformed into parallel lines and finites points map to finite points. cosθ sinθ 0 - sinθ cosθ 0 0 0 1 cosθ - sinθ 1 = --- (10) 1 0 1
  • 103. 102 Translation, Rotation, Scaling, Reflection and Shear are examples of two- dimensional affine transformation. Any general two-dimensional affine transformation can always be expressed as a composition of these 5 transformations. Another affine transformation is the conversion of co-ordinates descriptions from one reference system to another which can be described as a combination of translation and rotation. An affine transformation involving any rotation, translation and reflection preserves angles and lengths as well as parallel lines. For these 3 transformations the lengths and angle between two transformations, the lengths and angle between two lines remains the same after the transformation.
  • 104. 103 CHAPTER -6 VIEWING PIPELINE: A world co-ordinate area selected for display is called a window, which defines what is to be viewed? An area on a display device to which a window is mapped is called a viewport, which defines where it is to be display. Windows and Viewports are rectangle in standard position, with the rectangle parallel to the co-ordinate axes. In general, the mapping of a part of a world co- ordinate scene to device co-ordinate is referred to a viewing transformation. Sometimes, 2D viewing transformation is simply referred to as the window to viewport transformation or windowing transformation. In computer graphics, the term window originally referred to an area of picture. i.e.: selected for viewing. Some graphics packages that provides window and viewport operation, allow only standard rectangles, but a more general approach to allow the rectangular window to have any orientation. To obtain a particular orientation for the window, we can set up a 2D viewing co-ordinate system in the world co-ordinate plane and define a window in the viewing co-ordinate system. The viewing co-ordinate reference frame is used to provide a method for setting of arbitrary orientation for rectangular windows. Once the viewing reference frame is established, we can transform descriptions in world co-ordinate to viewing co- ordinate. We then define a viewport in normalized co-ordinates (range from 0 to 1) and map the viewing co-ordinate descriptions of the scene to normalize co-ordinates.
  • 105. 104 At the final step, all parts of the picture that lie outside the viewport are clipped and the contains of the viewport are transformed to device co-ordinate. Viewports are typically defined within the unit square (normalized co- ordinates). This provides a means for separating the viewing and other transformations from specific output device requirements. Different output devices can be used by providing the appropriate device drivers. When all co-ordinate transformations are completed, viewport clipping can be performed in normalized co-ordinates. This allows us to reduce computations by concatenating the various transformation matrices. VIEW CO-ORDINATE REFERENCE FRAME: The co-ordinate system provides the reference frame for specifying the world co-ordinates window. First a viewing co-ordinate origin is selected at some world position. i.e.: P0 = (x0, y0), then we need to establish the orientation, rotation of this reference frame. One way to do this is to specify a world vector ‘V’ that defines the viewing ‘yv’ direction. Vector ‘V’ is called the View-up vector. Given ‘V’, we can calculate the components unit vector V = (Vx, Vy) and U = (ux, uy) for the viewing Window XWmaxXWmin YWmax YWmin [WORLD CO-ORDINATE] Viewport XVmaxXVmin YVmax YVmin [VIEWPORT CO-ORDINATE]
  • 106. 105 ‘yv’ and ‘xv’ axes respectively. These unit vectors are used to form the 1st and 2nd rows of the rotation matrix ‘R’, that alive the viewing xvyv axes with the world. In fig-1, translate the viewing origin to the world origin. The fig-2 rotate to a line, the axes of the 2 systems we obtain the matrix for converting world co- ordinate position to viewing co-ordinate as a two- step composite transformation. i. 1st , we rotate to align the 2 co-ordinate reference plane. ii. Then we rotate to align the 2 co-ordinate reference plane. The composite 2D transformation to convert world co-ordinates to viewing co- ordinates is: Mwc, vc = R.T, Where T= translation matrix, that takes the viewing origin point ‘P0’ to the world origin and R = rotation matrix. WINDOW TO VIEWPORT TRANSFORMATION: Once the object description has been transferred to the viewing reference frame, we choose the window extends in viewing co-ordinates and select the view code limits is normalized co-ordinates. Object descriptions are transfer to normalized device co-ordinates. Yview Xview Xworld Yworld Y X X0 Y0 Yview Xview Xworld Yworld R Fig - 1 Fig - 2
  • 107. 106 If a co-ordinate position is at the center of viewing window, it will display at the center of the viewpoint. A point position (xw, yw) in window maps into position (xv, yv) in associated viewport. To maintain the same relative placement in the viewport as in the window, we require that: Solving these expression for the viewpoint position (xv, yv), we have Where, ‘Sx’ and ‘Sy’ are scaling factors. Window XWmaxXWmin YWmax YWmin [WORLD CO-ORDINATE] Viewport XVmaxXVmin YVmax YVmin [VIEWPORT CO-ORDINATE] (xw, yw) XV – XVmin XVmax – XVmin XW – XWmin XWmax – XWmin = YV – YVmin YVmax – YVmin YW – YWmin YWmax – YWmin = --- (1) XV = XVmin + (XW – XWmin)Sx YV = YVmin + (YW – YWmin)Sy --- (2)
  • 108. 107 CLIPPING: It is described as the procedure that identifies the portion of a picture lie inside the region and therefore it should be drawn or outside the specified and hence not to be drawn. The algorithms that perform the job of clipping are called clipping algorithms. The different types of clipping are: i. Point clipping ii. Curve clipping iii. Text clipping iv. Exterior clipping v. Line clipping vi. Polygon clipping In clipping it form an arbitrary view point in the world co-ordinate system. It is a common experience that an object may be seen partially. The following 3 cases may arise. That is: Sx XVmax – XVmin XWmax – XWmin = Sy YVmax – YVmin YWmax – YWmin = --- (3)
  • 109. 108 Case-1: The object is completely outside the viewing area, describe by the viewport or camera. This means that the object is not going to contribute in the final image in the screen co-ordinate. Case-2: The object may be seen partially that is some part of it may lie outside the viewing area. Case-3: The object may be completely seen within the viewing area. The process of clipping eliminates the portion of the object, which does not contribute to the final image. For the above cases, it can be clearly seen that, Case- 1, and Case-2 demand clipping while in Case-3, no clipping is necessary. L1, L2: No Clipping: Case 3. L3: Apply Clipping by Case 2. L4: Apply Clipping by Case 1. I. POINT CLIPPING: Assume that the clip window is a rectangle in standard position, we save a point P = (x, y) for display if the following inequalities are satisfied. That is: XWmin ≤ X ≤ XWmax and YWmin ≤ Y ≤ YWmax Where the edges of the clip window (XWmin, XWmax, YWmin, YWmax) can be either the world co-ordinates window boundaries or viewport boundaries. If any one of these four inequalities is not satisfied, then the point is clipped (not saved for display). L1 L2 L3 L4
  • 110. 109 Point clipping is applied less often than line or polygon clipping; some applications may require a point clipping. II. CURVE CLIPPING: This procedure will involve non-linear equations, however and this requires more processing than for objects with linear boundaries. The boundary rectangle for a circle or other curve object can be used first to test for overlap with a rectangular clip window. If the bounding rectangle for the object is completely inside the window, we save the object. If the rectangle is determined to be completely outside the window, we discard the object. In either case, there is no further computation necessary. III. TEXT CLIPPING: There are several techniques that can be used to provide text clipping in a graphics package. The simplest method for processing character strings relative to a window boundary is to use the all-or-none string clipping strategy. If all of the string is inside a clip window, we keep it, otherwise the string is discarded. This procedure is implemented by considering a bounding rectangle around the text pattern. The boundary positions of the rectangle are then compared to the window boundaries and the string is BEFORE CLIPPING AFTER CLIPPING
  • 111. 110 rejected if there is any overlap. This method produces the fastest text clipping. An alternative to rejecting an entire character string that overlaps a window boundary is to use the all-or-none-character clipping strategy. Here we discard only those characters that are not completely inside the window. Here the boundary limits of individual characters are compared to the window. Any character that either overlaps or is outside a window boundary is clipped. A final method for handling text clipping is to clip the components of individual characters. If an individual character overlaps a clip window boundary, we clip off the parts of the character that are outside the window. STRING2 STRING1 BEFORE CLIPPING STRING2 AFTER CLIPPING STRING3 STRING1 BEFORE CLIPPING STRING4 STRING2 TRING3 RING1 AFTER CLIPPING STRING4 STR
  • 112. 111 IV. EXTERIOR CLIPPING: We have considered only procedures for clipping a picture to the interior of a region by eliminating everything outside the clipping region. What is saved by these procedures is inside the region. In some cases, we want to do the reverse that is; we want to clip a picture to the exterior of a specified region. The picture parts to be saved are those that are outside the region. This is referred to as exterior clipping. It is used in multiple window systems and also in other applications that require overlapping pictures. The technique can also be used for combining graphs, maps or schematics. For this we can use exterior clipping to provide a space for an insert into a larger picture. Procedure for clipping objects to the interior of concave polygon windows can also make use of external clipping. V. LINE CLIPPING: Line is a series of infinite number of points where no two points have space in between them. A variety of lines clipping algorithms are available in computer graphics are: a) Cohen-Sutherland Line Clipping Algorithm b) Liang-Barsky Line Clipping Algorithm c) Nicholl-Lee-Nicholl Line Clipping Algorithm All line segments fall into one of the following clipping. That is: i. Visible: Both endpoints of the line segments lie within the window.
  • 113. 112 ii. Non-Visible: The line segment definitely lies outside the window. This will occur, if the line segment from (x1, y1) to (x2, y2) satisfies any one of the following 4 inequalities. i.e.: a) x1, x2 > Xmax b) x1, x2 < Xmin c) y1, y2 > Ymax d) y1, y2 < Ymin iii. Partially Visible/Clipping Co-ordinate: A line is partially visible when a part of it lies within the window. a) COHEN-SUTHERLAND LINE CLIPPING ALGORITHM: It provides an efficient procedure for determining the category of line segments. It proceeds in 3 steps. That is: Step 1: Assign a 4 bit code to each end point of the line segment and code is determined by the same. The end point is one of the following 9 regions of the plane. The 4 bit code is assigned to UDRL Rule. (UP DOWN RIGHT LEFT). Starting from the left most bit, each bit of the code is said to be true i.e.: 1 or false i.e.: 0, according to the following scheme. That is: i. Bit 1 is said to 1, if point ‘P’ lies above the window. ii. Bit 2 is said to 1, if point ‘P’ lies below the window. iii. Bit 3 is said to 1, if point ‘P’ lies right to the window. iv. Bit 4 is said to 1, if point ‘P’ lies left to the window. 1001 1000 1010 0001 0000 (w) 0010 0101 0100 0110 UDRL RULE
  • 114. 113 v. Point 0000 code is lies inside the window. Step 2: The line segment is visible if both endpoints codes are 0000 not visible if the logical AND of the codes is not 0000 and a candidate for clipping if the logical AND of the endpoint codes is 0000. Step 3: If the line is a candidate for clipping, consider its 2 endpoints to be ‘P1’ and ‘P2’. If ‘P1’ is outside the window, then replace ‘P1’ with the intersection of ‘P1P2’ and window edge. LINE INTERSECTION AND CLIPPING: Here, we determine the intersections points of the line in clipping candidate with the boundaries of the window. Their intersection points then subdivided the line segments into several smaller line segments which can belong only to visible category or not visible category. The segment in visible category will be the clipped line segment. The intersection points are found by solving the equations representing the line segments and the boundary line. i. For left window edge, intersection point will be (xL, y) and y-value can be calculated as: y = m(xL –x1) + y1, m ≠ ∞. ii. For right window edge, intersection point will be (xR, y) and y- value can be calculated as: y = m(xR –x1) + y1, m ≠ ∞. iii.For top window edge, intersection point will be (x, yT) and x-value can be calculated as: x = x1 + 1/m(yT –y1), m ≠ 0. iv. For bottom window edge, intersection point will be (x, yB) and x- value can be calculated as: x = x1 + 1/m(yB –y1), m ≠ 0.
  • 115. 114 Here, ‘xL’ is ‘x’-value of left edge of clipping window. ‘xR’ is ‘x’-value of right edge of clipping window. ‘yT’ is ‘y’-value of top edge of clipping window. ‘yB’ is ‘y’-value of bottom edge of clipping window. Acceptable values of ‘x’ and ‘y’ are: xL ≤ x ≤ xR and yB ≤ y ≤ yT Example: Given a clipping window A(20, 20), B(60, 20), C(60, 40) and D(20, 40) using Cohen-Sutherland line clipping algorithm, find the visible portion of line segment joining the points P(40, 80) and Q(120, 30). Here, xR = 60, xL = 20, yT = 40, yB = 20. (x1, y1) = (40, 80) and (x2, y2) = (120, 30) m = y2 – y1/x2 – x1 = 30 – 80/120 – 40 = -50/80 = - 5/8 Intersection with window edges, Left xL = 20, Ymax Ymin Xmin XmaxP1 P2 P4 P3 P2 P3 ꞌ P2 P2 ꞌ P2 P1 ꞌ P2 A B D C L2 L1
  • 116. 115 y = m(xL – x1) + y1 = -5/8(20 – 40) + 80 = 92 x = x1 + 1/m(yT - y1) = 40 + (-8/5)(40 – 80) = 104 Since, ‘y’ is greater than yT. So, it is rejected. Left xR = 60, y = m(xR – x1) + y1 = -5/8(60 – 40) + 80 = 67.5. Since, ‘y’ is greater than yT. So, it is rejected. Top yT = 40, x = 104. Since ‘x’ is greater than ‘yT’. So it is rejected. Bottom yB = 20, x = 136. Since ‘x’ is greater than ‘yB’. So, it is rejected. The given line has no intersection with clipping window; hence the line is totally invisible. b) LIANG-BARSKY LINE CLIPPING ALGORITHM: Faster line clippers have been developed that are based on analysis of the parametric equation of a line segment, which can write in the form: x = x1 + u∆x and y = y1 + u∆y, where 0 ≤ u ≤ 1 --- (1) Here, ∆x = x2 – x1 and ∆y = y2 – y1. (20, 40) (60, 40) (20, 20) (60, 20) Q(120, 30) P(40, 80) (x, yT) A B D C (xR, y)
  • 117. 116 Using this parametric equation, Cyrus and Beck developed an algorithm which is generally more efficient that the Cohen-Sutherland algorithm. Later Liang and Barsky independently devised an even faster parametric line clipping algorithm. Following the Liang-Barsky approach, we first write the point clipping conditions in the parametric form is: XWmin ≤ x1 + u∆x ≤ XWmax and YWmin ≤ y1 + u∆y ≤ YWmax --- (2) Each of these four inequalities can be expressed as: upk ≤ qk, where k = 1, 2, 3, 4 --- (3) Where parameters ‘p’ and ‘q’ are defined as: Any line that is parallel to one of the clipping boundaries has pk = 0 for the value of ‘k’ corresponding to that boundary (k = 1, 2, 3 and 4 correspond to the left, right, bottom and top boundaries respectively). If, for that value of ‘k’, we also find qk < 0, then the line is completely outside the boundary and can be eliminated from further consideration. If qk ≥ 0, then line is inside the parallel clipping boundary. When pk < 0, the infinite extension of the line proceeds from outside to the inside of the infinite extension of this particular clipping boundary. If p1 = - ∆x, q1 = x1 - XWmin p2 = - ∆x, q2 = XWmax - x1 p3 = - ∆y, q3 = y1 - YWmin p4 = - ∆y, q4 = YWmax - y1 --- (4)
  • 118. 117 pk > 0, the line proceeds from the inside to the outside. For a non-zero value of ‘pk’, we can calculate the value of ‘u’ that corresponds to the point where the infinitely extended line intersects the extension of boundary ‘k’ as: u = qk/pk --- (5) For each line, we can calculate values for parameters u1, u2 that define that part of the line that lies within the rectangle. The value of ‘u1’ is determined looking at the rectangle edges for which the line proceeds from the outside to the inside (p < 0). For these edges, we calculate as: rk = qk/pk --- (6) The value of ‘u1’ is taken as the largest of the set consisting of ‘0’ and the various values of ‘r’. The value of ‘u2’ is determined by examining the boundaries for which the line proceeds from inside to outside (p > 0). A value of ‘rk’ is calculated for each of these boundaries and the value of ‘u2’ is the minimum of the set consisting of ‘1’ and the calculated ‘r’ values. If u1 > u2, the line is completely outside the clip window and it can be rejected, otherwise the endpoints of the clipped line are calculated from the two values of parameter ‘u’. Line intersection parameters are initialized to the value u1 = 0 and u2 = 1. For each clipping boundary, the appropriate values for ‘p’ and ‘q’ are calculated and used by the function ‘clipTest’ to determine whether the line can be rejected or whether the intersection parameters are to be adjusted.
  • 119. 118 When p < 0 the parameter ‘r’ is used to update ‘u1’ and when p > 0 the parameter ‘r’ is used to update ‘u2’. If updating ‘u1’ or ‘u2’ results in u1 > u2, we reject the line, otherwise we update the appropriate ‘u’ parameter only if the new value results in a shortening of the line. When p = 0 and q < 0, we can discard the line, since it is parallel to and outside of this boundary. If the line has not been rejected after all four values of ‘p’ and ‘q’ has been tested, the endpoints of the clipped line are determined from values of ‘u1’ and ‘u2’. c) NICHOLL-LEE-NICHOLL LINE CLIPPING ALGORITHM: This algorithm avoids multiple clipping of an individual line segment. The extra intersection calculations are eliminated in NLN algorithm by carrying out more regions testing before intersection positions are calculated. This algorithm performs fewer comparisons and divisions. The tradeoff is that the NLN algorithm can only be applied to the two-dimensional clipping, whereas, both the Liang-Barsky and Cohen-Sutherland methods are easily extended to 3-dimensional scenes. For a line with endpoints ‘p1’ and ‘p2’, we first determine the position of point ‘p1’ for the nine possible regions relative to the clipping rectangle. Only the 3 regions are shown, need to be considered. That is: (a) p1 in a window p1p1 p1 (b) p1 in edge region (c) p1 in corner region
  • 120. 119 If ‘p1’ lies in any one of the other six regions, we can move it to one of the 3 regions, using a symmetric transformation. E.g.: The region directly above the clip window can be transformed to the region left to the clip window using a reflection about the line y = -x or we could use a 90 degree counter clockwise rotation. We determine the position of ‘p2’, relative to ‘p1’. To do this, we create some regions in the plane, depending on the location of ‘p1’. Boundaries of the new regions are half-infinite line segments that start at the position of ‘p1’ and pass through the window corners. If ‘p1’ is inside the clip window and ‘p2’ is outside, we set up the four regions. The intersection with the appropriate window boundary is then carried out; depending on which one of the four regions (L, T, R or B) contain ‘p2’. Of course, if either ‘p1’ or ‘p2’ are inside the clipping rectangle, we simply save the entire line. If ‘p1’ is in the region to the left of the window, we set up the four regions L, LT, LR and LB as shown as: These 4 regions determine a unique boundary for the line segment. For instance, if ‘p2’ is in region 1, we clip the line at the left boundary and save the line segment from this intersection point to ‘p2’. But if ‘p2’ is in region ‘LT’, we save the line segment from the left window boundary to the top boundary. If ‘p2’ is not in any of the four regions L, LT, LR or LB, the entire line is clipped. T RL B P1 LT LRL LB P1 L L
  • 121. 120 We save the line segment from the left window boundary to the top boundary. If ‘p2’ is not in any of the four regions L, LT, LR or LB, the entire line is clipped. For 3rd case, when ‘p1’ is to the left and above the clip window, we use the clipping regions shown as: Here, we have the 2 possibilities shown, depending on the position of ‘p1’ relative to the top left corner of the window. If ‘p2’ is in one of the regions T, L, TR, TB, LR or LB, this determines a unique clip window edge for the intersection calculations; otherwise the entire line is rejected. To determine the region in which ‘p2’ is located, we compare the slope of the line to the slopes of the boundaries of the clip regions. E.g.: if ‘p1’ is at left of the clipping rectangle, then ‘p2’ is in region LT, if Or, yT – y1/xR – x1 < y2 – y1/x2 – x1 < yT – y1/xL – x1 --- (2) And we clip the entire line if, (yT – y1)(x2 – x1) < (xL – x1)(y2 – y1) --- (3) TB TRT LB P T L Or LR TR L LB P T L slope p1pTR < slope p1p2 < slope p1pTL --- (1)
  • 122. 121 The co-ordinate difference and product calculations used in the slope tests are saved and also used in the intersection calculations from the parametric equations: x = x1 + (x2 – x1)u and y = y1 + (y2 – y1)u --- (4) An x-intersection position on the left window boundary is: x = xL, with: u = (xL – x1)/(x2 – x1), So that the y-intersection position is: y = y1 + y2 – y1/x2 – x1(xL – x1) --- (5) And an intersection position on the top boundary has y = yT and u = (yT – y1)/(y2 – y1), with x = x1 + x2 – x1/y2 – y1(yT – y1) --- (6) VI. POLYGON CLIPPING: Polygon is a surface enclosed by several lines. So, by considering the polygon as a set of line we can divide the problem to line clipping and hence the problem of polygon clipping is simplified, but it is to be noted that each edge separately by using a line clipping algorithm, will certainly not produce a truncated polygon as unconnected line segments. Sutherland-Hodgeman algorithm is one of the standard methods used for clipping arbitrary polygons with a rectangular clipping window, it uses divide and conquer technique for clipping the polygon.
  • 123. 122 i. SUTHERLAND-HODGEMAN POLYGON CLIPPING: Any polygon of any arbitrary shape can be described with the help of some set of vertices associated with it. When we try to clip the polygon, under consideration with any rectangular window, then we observe that the co-ordinates of the polygon vertices satisfies one of the 4 cases and further it is to be noted that this procedure of clipping can be simplified by clipping the polygon edge-wise and not the polygon as a whole. This decomposes the bigger problem into a set of sub-problem which can be handling separately as per the cases. The 4 possible cases are mentioned below. That is: CASE 1: If both input vertices are inside the window boundary then only 2nd vertex is added to output vertex list. CASE 2: If first vertex is inside the window boundary and 2nd vertex is outside then only the intersection edge with boundary is added to the output vertex. CASE 3: If both input vertices are outside the window boundary then nothing is added to the output list. CASE 4: If the first vertex is outside the window and the 2nd vertex is inside the window then both the intersection point of the polygon edge with window boundary, the 2nd vertex is added to the output vertex list. So, we can use the above rules to clip a polygon correctly. The polygon must be tested against each edge of the clip rectangle, new edges must be
  • 124. 123 added and existing edges must be discarded, retained or derived. Actually, this algorithm decompose the problem of polygon clipping against a clip window into identical sub-problems, where a sub-problems is to clip all polygon edges (pair of vertices) in succession against a single infinite clip edge. This output is a set of clip edges or pair of vertices that fall in the visible site with respect to clip edge. These set of clip edges or considered as input for the next sub-problems of clipping against the 2nd window page. This considering the output of the previous sub-problem as the input, each of sub-problems are solved subsequently and finally yielding the vertices that fall in or within the window boundary. These vertices connected in order forms, the shape of the clip polygon. Example: Clip the polygon p1, p2, p3, … , p8 in the given figure against the rectangular clipping window using the Sutherland-Hodgeman Algorithm. P2P1 P4 P3 P6 P5 P8 P7 P4 ꞌ P5 ꞌ P2 ꞌ P7 ꞌ P3 P6 After Clipping P4 ꞌ P5 ꞌ P2 ꞌ P7 ꞌ
  • 125. 124 After clipping, For P1P2, clipping not required as per CASE 3. For P2P3, clipping becomes P2ꞌP3, which is added to output list as per CASE 4. For P3P4, clipping becomes P3P4ꞌ, which is added to output list as per CASE 2. For P5P6, clipping becomes P5ꞌP6, which is added to output list as per CASE 4. For P6P7, clipping becomes P6P7ꞌ, which is added to output list as per CASE 2. For P7P8 and P8P1 clipping not required as per CASE 3. ii. WEILER-ATHERTON POLYGON CLIPPING: Here, the vertex processing procedures for window boundaries are modified, so those concave polygons are displayed correctly. This clipping procedure was developed as a method for identifying visible surfaces and so, it can be applied with arbitrary – polygon clipping regions. The basic idea in this algorithm is that instead of always proceeding around the polygon edges as vertices are processed, we sometimes want to follow the window boundaries, which path we follow depend on the polygon processing direction (clockwise or counter clockwise) and whether the pair of polygon vertices being processed represents an outside-to-inside pair or an inside-to-outside. For clockwise processing of polygon vertices, we use the following rules. That is: i. For an outside-to-inside pair of vertices, follow the polygon boundary. ii. For an inside-to-outside pair of vertices, follow the window boundary in a clockwise direction.
  • 126. 125 This considering the output of the previous sub-problem as the input, each of sub-problems are solved subsequently and finally yielding the vertices that fall in or within the window boundary. These vertices connected in order forms, the shape of the clip polygon. Here, the processing direction in the Weiler-Atherton algorithm and the resulting clipped polygon is shown for rectangular clipping window. An improvement on this algorithm is the Weiler algorithm, which applies constructive solid geometry ideas to clip an arbitrary polygon against any polygon clipping region. V2 V6 V4 V3 V5 V1 V4 ꞌ V1 ꞌ V3 ꞌ After Clipping
  • 127. 126 CHAPTER -7 REPRESENTATION OF POINT IN 3D: A point in 3D is represented by 3 co-ordinates [x, y, z] by introducing the homogeneous concept. A point in 3D i.e.: [x, y, z] is represented by 4D position vector: [xꞌ yꞌ zꞌ h] = [x y z 1][T], where [T] is some transformation matrix. Again the transformation from homogeneous co-ordinate to ordinates is given by: [x* y* z* 1] = [xꞌ/h yꞌ/h zꞌ/h 1]. The generalized 4 x 4 transformation matrix for 3D homogeneous co-ordinate is: The 4 x 4 transformation matrix in equation – (1) can be partitioned into 4 separate sections as: The upper-left 3 x 3 sub-matrix produces a linear transformation in the form of scaling, shearing, reflection and rotation. The 1 x 3 lower-left sub-matrix produces translation and upper-right 3 x 1 sub-matrix produces perspective transformation and the final lower-right hand side 1 x 1 sub-matrix produces overall scaling. g i j r a b c p d e f q l m n s --- (1) 4 x 4 [T] = 3 x 3 3 x 1 1 x 3 1 x 1
  • 128. 127 This transformation matrix [T] will be applied on homogeneous or co-ordinate position vector and will yield shearing, local scaling, rotation, reflection, translation, perspective and overall scaling. 3D TRANSFORMATION: The different types of 3D transformations are: i. 3D translation ii. 3D rotation iii. Rotation about an axis parallel to co-ordinate axis iv. Rotation about an arbitrary axis in space v. 3D scaling vi. 3D reflection vii. 3D shearing i. 3D TRANSLATION: In general 4 x 4 transformation matrix is: The elements of the 4th row of order 1 x 3 i.e.: l, m, n at the translations in the x, y, and z direction. The matrix for translation is: g i j r a b c p d e f q l m n s 4 x 4 [T] =
  • 129. 128 The translation of homogeneous co-ordinates is obtained by writing: The transformed physical co-ordinates are: x* = x + l, y* = y + m and z* = z + n. Example: Consider the effect of a translation in the xyz - direction by -2, -4 and -6 respectively on the homogeneous co-ordinates position vectors [1, 6, 4]. 0 0 1 0 1 0 0 0 0 1 0 0 l m n 1 4 x 4 [T] = 0 0 1 0 1 0 0 0 0 1 0 0 l m n 1 = [(x + l) (y + m) (z + n) 1][xꞌ yꞌ zꞌ h] = [x y z 1] 0 0 1 0 1 0 0 0 0 1 0 0 l m n 1 =[T] = 0 0 1 0 1 0 0 0 0 1 0 0 -2 -4 -6 1 [X][T] = 1 60 4 1 0 0 1 0 1 0 0 0 0 1 0 0 -2 -4 -6 1 = 1 + (- 2) 6 – 4 4 – 6 1 -1 20 -2 1=0
  • 130. 129 ii. 3D ROTATION: This rotation is examined about each of the co-ordinate axis. For rotation about the x-axis, the x co-ordinate of the position vector doesn’t change. In effect, the rotation occurs in places perpendicular to x-axis. Similarly the rotation about the y-axis and z-axis occurs in planes perpendicular to the y-and z-axis respectively. The transformation of the position vector in each of these planes it’s governed by the general 2D rotation matrix. That is: By considering the above matrix and again noting that, for rotation about the x-axis, the x co-ordinate of the transformed position vector doesn’t change. The 4 x 4 homogeneous co-ordinate transformation vectors by angle ‘θ’ can be written as: Rotation is assumed ‘+ ve’ in right hand side. i.e.: clockwise as one looks outwards from the origin in the ‘+ ve’ direction along the rotation cosθ sinθ - sinθ cosθ [T] = (in 2D) 0 0 0 0 1 cosθ sinθ - sinθ cosθ [T] = --- (1) 0 0 0 0 1 0 0 0 0 0 01
  • 131. 130 axis. In similar manners, the transformation matrix for rotation of an angle ‘Φ’ about y-axis is: Again for rotation by an angle ‘Ψ’ about the z-axis is: NOTE: The equation (1), (2) and (3) show that the determinant of each transformation matrix as ‘+ 1’ as required for purse rotation. i.e.: Determinant of pure rotation matrix is always +1. Since 3D rotations are obtained using matrix multiplication they are non-communicative. i.e.: the order of multiplication, affects the final result. In order to show this, consider a rotation about x-axis followed by an equal rotation about y-axis by using the equation (1) and (2) with θ = Φ. Now, we have: 1 - sinΦ sinΦ sinΦ cosΦ [T] = --- (2) 0 0 0 cosθ 0 1 0 00 0 0 0cosΦ 1 - sinΨ sinΨ sinΨ cosΨ [T] = --- (3) 0 0 0 cosθ 0 1 0 0 0 0 0 0cosΨ
  • 132. 131 On the other hand, the reverse operation i.e.: rotation about y-axis followed, by equal rotation about the x-axis with θ = Φ yields. Example: A rectangular parallelepiped is given having length on x-axis, y- axis and z-axis as 3, 2, 1 respectively. Perform a rotation by an angle θ = -90 degree about x-axis and perform a rotation by and angle Φ = 90 degree about y-axis. cosθ sinθ - sinθ cosθ [T] = 0 0 0 0 1 0 0 0 0 0 01 1 - sinθ sinθ cosθ 0 0 0 0 1 0 00 0 0 0cosθ cosθsin2 θ - sinθ cosθsinθ => [T] = --- (4) - sinθ cosθsinθ cos2 θ 0 0 0 0 1 0 0 0cosθ cosθ sinθ - sinθ cosθ 0 0 0 0 1 0 0 0 0 0 01 1 - sinθ sinθ cosθ 0 0 0 0 1 0 00 0 0 0cosθ [T] = cosθ sin2 θ sinθ - cosθsinθ => [T] = --- (5) sinθ - cosθsinθ cos2 θ 0 0 0 0 1 0 0 0cosθ
  • 133. 132 The position vector matrix of rectangular parallelepiped is: The rotation matrix about x-axis by an angle θ = -90o : A B CD E F GH 1 2 3 X Y Z 0 0 1 1 3 0 1 1 3 2 1 1 0 2 1 1 0 0 0 1 3 0 0 1 3 2 0 1 0 2 0 1 [X] = cos(-90) sin(-90) 90) - sin(-90) cos(-90) [T] = 0 0 0 0 1 0 0 0 0 0 01 0 -1 1 0 = 0 0 0 0 1 0 0 0 0 0 01 [X*] = [X] [T] = 0 0 1 1 3 0 1 1 3 2 1 1 0 2 1 1 0 0 0 1 3 0 0 1 3 2 0 1 0 2 0 1 0 -1 1 0 = 0 0 0 0 1 0 0 0 0 0 01 0 1 0 1 3 1 0 1 3 1 -2 1 0 1 -2 1 0 0 0 1 3 0 0 1 3 0 -2 1 0 0 -2 1
  • 134. 133 The rotation matrix about y-axis by an angle Φ = 90o : iii. ROTATION ABOUT AN AXIS PARALLEL TO CO-ORDINATE AXIS: The transformation matrices given by the equation 1, 2, 3 are the rotation transformation matrices about x, y and z co-ordinate axes respectively. Our aim is to rotate the object about axes other than these standard axes. Here, the special case of an axis that is parallel to one of the x, y or z co-ordinate axis is considered. Here, the body with local axis system xꞌyꞌzꞌ parallel to the fixed global axis system xyz. 1 - sin90 sin90 cos90 0 0 0 0 1 0 00 0 0 0cos90 [T] = = 1 -1 0 0 0 0 0 0 1 0 00 1 0 00 [X*] = [X] [T] = 0 0 1 1 3 0 1 1 3 2 1 1 0 2 1 1 0 0 0 1 3 0 0 1 3 2 0 1 0 2 0 1 0 -1 1 0 = 0 0 0 0 1 0 0 0 0 0 0 1 01 0 1 -31 0 1 -31 2 1 01 2 1 00 0 1 -30 0 1 -30 2 1 00 2 1
  • 135. 134 Rotation of the body about any of the individual xꞌ, yꞌ or zꞌ local axis is accomplished using the following 3 steps. That is: i. Translate the body until the local axis is coincident with the co- ordinate axis in the same direction. ii. Rotate about the specified axis is given iii. Translate the body back to its original position. Mathematically, it can be shown as: [X*] = [X] [T], where [T] = [Tr] [Rx] [Tr]-1 Here, [T] = compound transformation matrix, [Tr] = Translation matrix [Rx] = Rotation matrix about x-axis, [Tr]-1 = Inverse translation matrix [X] = Untransformed/Original co-ordinate matrix [X*] = It represents the transformed co-ordinate of the body. Z Y H G F D C B A Xꞌ XZꞌ Yꞌ Z Y H G D C BA Xꞌ X F
  • 136. 135 Example: Perform the rotation of block about x+ - axis by an angle θ = 30o ), which is local to the block. The co-ordinate of the blocks is given relative to the global xyz-axis system. The position vector of the cube relative to the x, y, z axis system is given, i.e.: Let the local xꞌ-axis pass through centroid of the block. The co-ordinate of the centroid of the block is: [xc yc zc 1]. So, [xc yc zc 1] = [3/2 3/2 3/2 1]. Rotation about local axis is accomplished by: [x*] = [x] [Tr] [Rx] [Tr]-1 Where, Z Y H G F D C B A Xꞌ X Zꞌ Yꞌ1 1 2 1 2 1 2 1 2 2 2 1 1 2 2 1 1 1 1 1 2 1 1 1 2 2 1 1 1 2 1 1 [X] = 1 0 0 0 0 1 0 0 0 -yc -zc 1 0 0 1 0 1 0 0 0 0 1 0 0 0 -3/2 -3/2 1 0 0 1 0 [Tr] = =
  • 137. 136 The value of composite transformation matrix [T= [Tr] [Rx] [Tr]-1 After putting the values of yc, zc and θ = 30o , we get 1 0 .866 1 0 0 0 0 0 -.5 .866 .5 -.549.951 0 0 1 0 cosθ 1 0 0 0 0 0 0 0 -sinθ cosθ sinθ 00 0 0 [Rx] = = 1 0 .866 1 0 0 0 0 0 -.5 .866 .5 00 0 0 1 0 cosθ 1 0 0 0 0 0 - sinθ cosθ sinθ zc(1 – cosθ) - ycsinθ yc(1 – cosθ) + zcsinθ 0 0 = 1 1 2 1 2 1 2 1 2 2 2 1 1 2 2 1 1 1 1 1 2 1 1 1 2 2 1 1 1 2 1 1 [X* ] = [X][T] = 1 0 .866 1 0 0 0 0 0 -.5 .866 .5 -.549.951 0 0
  • 138. 137 iv. ROTATION ABOUT AN ARBITRARY AXIS IN SPACE: The rotation about an arbitrary axis in space occurs in robotics animation simulating. This is accomplished using the procedure of translations and simple rotation about a co-ordinate axis. The procedure idea is to make the arbitrary rotation axis coincident with one of the co- ordinate axes. Let’s assume that an arbitrary axis is space passing through the point (x0, y0, z0) with direction cosine (Cx, Cy, Cz). Rotation about this axis by some angle ꞌdꞌ is accomplished using the following procedure. i. Translate the body so that the point (x0, y0, z0) is reached at the origin of co-ordinate system. ii. Do approximate rotations to make the axis of rotation coincident with the z-axis (the selection of z-axis is arbitrary, we can choose any axis). iii. Rotate the body by the angle ꞌdꞌ about z-axis. 1 .817 1.683 1 2 .817 1.683 1 2 1.683 2.183 1 1 1.683 2.183 1 1 1.317 .817 1 2 1.317 .817 1 2 2.183 1.317 1 1 2.813 1.317 1 =
  • 139. 138 iv. Do the inverse of the combined rotation transformation. v. Now, perform the inverse of the translation. vi. Our aim is to make the arbitrary rotation axis coincident with the z-axis. For this first rotate about the x-axis and then about the y-axis. To find the value of rotation angle ꞌαꞌ about x-axis used to place the arbitrary axis in xz-plane, now first project the unit vector along the axis onto the yz-plane. The projected components of the ‘y’ and ‘z’ values are ‘Cy’ and ‘Cz’ and the direction cosine of the unit vector along the arbitrary axis. From the above figure, we note that: Cosα = Cz/d and Sinα = Cy/d --- (2) After completion of rotation about the x-axis into the xz-plane, the z- component of the unit vector ꞌdꞌ and the x-component is ‘Cx’ and the direction cosine in the x-direction is shown in fig-2. [Rotation about x-axis] α d x z yCx Cz Cy [Rotation about y-axis] d x z y Cx β d P(Cx, 0, d) 0 d = Cy 2 + Cz 2 --- (1)
  • 140. 139 We know, the length of a unit vector is 1. The rotation angle ‘β’ about the y-axis required to make the arbitrary axis coincident with z-axis is: Cosβ = d and Sinβ = Cx --- (3) Now, the total transformation or composite transformation is: [T] = [Tr] [Rx] [Ry] [Rδ] [Ry] -1 [Rx] -1 [Tr]-1 --- (4) [Tr] = Translation matrix [Rx] = Rotation matrix about x-axis [Ry] = Rotation matrix about y-axis 1 0 cosθ 1 0 0 0 0 0 0 0 -sinθ cosθ sinθ 00 0 0 [Rx] = --- (6) 1 0 Cx/d 1 0 0 0 0 0 -Cy/d Cz/d Cy/d 00 0 0 1 0 0 0 0 1 0 0 -x0 -y0 -z0 1 0 0 1 0 [Tr] = --- (5) 1 - sin(- β) sin(-β) cos(-β) 0 0 0 0 1 0 00 0 0 0cos(-β) [Ry] = --- (7)1 Cx 0 d 0 0 0 0 1 0 00 -Cx 0 0d
  • 141. 140 [Rδ] = Rotation about the arbitrary axis given by z-axis is: Now, we take a 2nd point on the axis i.e.: (x1, y1, z1) to find the direction cosine is: Example: Derive the transformation matrix for rotating any object about an axis passing through the origin and point (10, 0, 10). Steps to be followed to perform the above task are: i. Translate, so that local axis is coincident with the co-ordinate axis ii. Rotate about specified axis i.e.: by 30 degree anticlockwise. iii. Translate the transformed body back to its original position. In general, making an arbitrary axis pass through origin, coincident with one of the axis, required two successive rotations about other two co- ordinate axis. According to the example, axis passes through the origin and a point P[10, 0, 10]. Hence, the direction cosines of rotation axis will be: 1 - sinδ sinδ sinδ cosδ [Rδ] = --- (8) 0 0 0 cosθ 0 1 0 0 0 0 0 0cosδ [Cx Cy Cz] = [(x1 – x0)2 + (y1 – y0)2 + (z1 – z0)2 ]1/2 [(x1 – x0)(y1 – y0)(z1 – z0)] --- (9) [Cx Cy Cz] = [(x1 – x0)2 + (y1 – y0)2 + (z1 – z0)2 ]1/2 [(x1 – x0)(y1 – y0)(z1 – z0)]
  • 142. 141 x0 = y0 = z0 = 0, x1 = 10, y1 = 0, z1 = 10, then, [Cx Cy Cz] = [(10) (0) (10)] / [(10)2 + (10)2 + (10)2 ]1/2 = [(10) (0) (10)] / √200 = [10/√200 0/√200 10/√200] = [10/14.142 0 10/14.142] Hence, [Cx Cy Cz] = [0.707 0 0.707] We rotate the arbitrary axis by angle ‘α’ about x-axis and about y-axis by angle ‘β’ in order to make it coincident with the z-axis. cosα = Cz/d = 0.707/0.706 = 1.001, sinα = Cy/d = 0 cosβ = d = 0.706, sinβ = Cx = 0.707 To compute transformation is: [T] = [Rx] [Ry] [Rθ] [Ry] -1 [Rx] -1 Where [T] = Transformation matrix [Rx] = Rotation matrix about x-axis by angle ‘α’ [Ry] = Rotation matrix about y-axis by angle ‘β’ [Rθ] = Rotation about z-axis by angle ‘30o ’ [Ry] -1 = Inverse matrix of [Ry] [Rx] -1 = Inverse matrix of [Rx] d = Cy 2 + Cz 2 = 0 + .499 = 0.706
  • 143. 142 Hence, the required transformation matrix is: v. 3D SCALING: The diagonal terms of the general 4 x 4 transformation matrix produce local and overall scaling. To understand this, consider the transformation matrix given below: 0.930 - 0.353 0.93 - 0.068 0.353 00 [T] = - 0.353 0.871 0.431 0 0 0 1 00.355 1 - sin30 sin30 cos30cos30 0 0 0 0 1 0 0 0 0 0 0cos30 1 0 cosα 1 0 0 0 0 0 0 0 -sinα cosα sinα 00 0 0 [T] = 1 - sinβ sinβ cosβ 0 0 0 0 1 0 00 0 0 0cosβ 1 0 0 c o s 3 0 .866 0 0 0 0 1 0 0 0 0 0 0.866 1 0 1.001 1 0 0 0 0 0 0 0 0 1.001 0 00 0 0 = 1 - 0.707 0.707 0.706 0 0 0 0 1 0 00 0 0 00.706 0.930 - 0.353 0.93 - 0.068 0.353 00 = - 0.353 0.871 0.431 0 0 0 1 00.355
  • 144. 143 [x* y* z* 1] = [X][T] = [x y z 1][T] => [x* y* z* 1] = [ax ey jz 1] or [Sxx Syy Szz 1] The overall scaling is obtained by using the 4th diagonal element. That is: the element of 1 x 1, in general transformation matrix shown by the equation: The ordinary or physical co-ordinates are: [x* y* z* 1] = [xꞌ/S yꞌ/S zꞌ/S 1]. 0 0 j 0 a 0 0 0 0 e 0 0 0 0 0 1 [T] = 0 0 Sz 0 Sx 0 0 0 0 Sy 0 0 0 0 0 1 or g i j r a b c p d e f q l m n s 4 x 4 [T] = 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 s = [xꞌ yꞌ zꞌ s][x* y* z* 1] = [x y z 1]
  • 145. 144 If S<1, a uniform expansion of the position vector occurs and if S>1, a uniform compression of the position vector occurs. Example 1: Given a rectangular parallelepiped which is unit distance on z-axis, 2 distances on x-axis and 3 distances on y-axis. What is the effect of scaling factor Sx = 1/2, Sy = 1/3 and Sz = 1? x y z A B CD E F GH 0 0 1 1 3 0 1 1 3 2 1 1 0 2 1 1 0 0 0 1 3 0 0 1 3 2 0 1 0 2 0 1 [X] = [T] = 1/3 0 0 1 0 0 0 0 1 0 0 0 0 0 01/2 0 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 = 1/3 0 0 1 0 0 0 0 1 0 0 0 0 0 01/2 [X*] = [X] [T] = 0 0 1 1 3 0 1 1 3 2 1 1 0 2 1 1 0 0 0 1 3 0 0 1 3 2 0 1 0 2 0 1
  • 146. 145 Example 2: Perform the uniform scaling on the unit cube by a factor of 2 and also draw the figure. The transformation matrix [T] for the uniform (overall) scaling is: Here, the homogeneous co-ordinate factor h = .5, for each of the transformed position vector, ‘q0’ obtain the ordinary or physical co- ordinates each position vector must be divided by ‘h’, therefore the result is: 0 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 [X] = [T] = 1 0 0 1 0 0 0 0 1/2 0 0 0 0 0 01 0 0 1 .5 1 0 1 .5 1 1 1 .5 0 1 1 .5 0 0 0 .5 1 0 0 .5 1 1 0 .5 0 1 0 .5 = [X*] = [X] [T] = 1 0 0 1 0 0 0 0 1/2 0 0 0 0 0 01 0 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1
  • 147. 146 vi. 3D REFLECTION: Some orientations of a 3D object can’t be obtained using pure rotation. They require reflections. In 3D, reflections occur through a plane, but in 2D, reflection occurs through an axis. In 3D, the value of the determinant for pure reflection matrix is always equal to -1. In a reflection through the xy-plane, only the z-co- ordinate values of the object’s position vectors change. i.e.: they are reversed in sign, so the transformation matrix for reflection through the xy-plane is: [X*] = 0 0 2 1 2 0 2 1 2 2 2 1 0 2 2 1 0 0 0 1 2 0 0 1 2 2 0 1 0 2 0 1 A* B* C*D* E* F* G*H* 2 2 2 X Y Z [T]xy = 1 0 0 -1 0 0 0 cosθ 0 1 0 0 0 0 0 01
  • 148. 147 The transformation matrix for reflection through yz-plane is: The transformation matrix for reflection through xz-plane is: Example: Perform reflection of unit cube about the xy-plane. The matrix for position vector of unit cube is: [T]yz = 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0-1 [X] = 0 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 A B CD E F GH X Y Z [T]xz = -1 0 0 1 0 0 0 0 1 0 0 0 0 0 01
  • 149. 148 The transformation matrix for reflection about xy-plane is given by: The value of transformed vector i.e.: after reflection about xy-plane is: vii. 3D SHEARING: The off diagonal terms in the upper-left 3 x 3 sub-matrix of the general 4 x 4 transformation matrix produce shear in 3D. [T] = 1 0 0 -1 0 0 0 0 1 0 0 0 0 0 01 0 0 -1 1 1 0 -1 1 1 1 -1 1 0 1 -1 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 = [X*] = [X] [T] = 1 0 0 -1 0 0 0 0 1 0 0 0 0 0 01 0 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 g i 1 0 1 b c 0 d 1 f 0 0 0 0 1 = [x + yd + gz bx + y + iz cx + fy + z 1] [x* y* z* 1] = [x y z 1]
  • 150. 149 Example: What is the effect of sheared transformation on the unit cube, where the value of shear transformation matrix is as follows: The position vector for unit cube and transformed matrix is given as follows: Applying the effect of the sheared transformation matrix on [X], it give X*. i.e.: [X*] = [X][T]. Here, one thing to be noted is that origin is unaffected by the sheared transformation. 0 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 [X] = [T] = 1 .7 1 1 0 0 0 0 1 -.85 .25 -.75 .5 0 01 .5 1 1 1 1.15 .15 1.25 1 2 1.5 1.95 1 -.25 .75 1.7 1 0 0 0 1 .15 -.85 .25 1 1 1 .95 1 -.75 .25 .7 1 =
  • 151. 150 CHAPTER - 8 3D VIEWING: The 3D viewing process is inherently more complex than 2D viewing process. The extra complexity of 3D viewing is caused in part by the added dimension and in part by the fact that display devices are only 2D. In 3D viewing, we specify a view volume in the world, a projection onto a projection plane and a viewpoint on a view surface. Conceptually, objects in 3D world are clipped against the 3D view volume and are then projected. The contains of the projection of the view volume onto the projection plane called the window, are then transformed into the viewport for display. The complete viewing process consists of the following sequence of transformation. i. Object Transformation: Transformation applied to the object prior to viewing. These transformations improved instance information, scaling, translations and rotations. ii. Image Transformation: 2D Transformations applied to the 2D image in normalized device space to produce the final view. iii. Viewing Transformation: Transformations applied to the desired object produce a 2D view of the object, describe in normalized device co-ordinate.
  • 152. 151 PROJECTION: The important terms related to projections are: i. CENTER OF PROJECTIONS: The point form where projection is taken, it can either be light source or eye position is called center of projections. ii. PROJECTION PLANE: The plane on which projection of the object is formed is called projection plane. iii. PROJECTORS: Lines emerging from center of projection and heating the projection plane after passing through a point in the object to be projected. Mainly these projectors are responsible for obtaining projection of an object. GEOMETRIC PROJECTION: The plane Geometric Projection of the objects is formed by the intersection of lines called Projectors on a plane called Projection Plane. Projectors are lines Plane Geometric Projection Perspective Projection Two Point Three Point Single Point Parallel Projection Orthographic Cavalier Oblique CabinetDi-metric Isometric Trimetric Axanometric
  • 153. 152 from an arbitrary point called the Center of Projection through each point in an object. Plane Geometric Projection is of 2 types. That is: Parallel and Perspective Projection. i. PARALLEL PROJECTION: If the center of projection is at infinity, all the projectors are parallel and the result is called Parallel Projection. It is of 3 types. a. ORTHOGRAPHIC PROJECTION: It is a part of parallel projection in which the center of projection lies at infinity. In this projection, the projectors are perpendicular to the projection plane and true size and shape of a single plane face, of an object is obtained. It is commonly used for engineering drawing. It is the projection on one of the co-ordinate planes. i.e.: x = 0, y = 0 or z = 0. The matrices for projection onto x = 0 plane, y = 0 plane and z = 0 plane are: To visually and partially reconstruct the shape of an object, a single orthographic projection does not provide sufficient information. There are multiple orthographic projections which are necessary. The front, right and [Px] = 1 0 0 1 0 0 0 0 1 0 0 0 0 0 00 [Py] = 0 0 0 1 0 0 0 0 1 0 0 0 0 0 01 [Pz] = 1 0 0 0 0 0 0 0 1 0 0 0 0 0 01
  • 154. 153 top views are obtained by projection onto the z = 0, x = 0, y = 0 planes from centers of projection infinity on the +z, +x, +y axis. The rear, left and bottom view projections are obtained by projection onto the z = 0, x = 0 and y = 0 planes from center of projection at infinity on the – z, -x, -y axes. The front and side view are known as front and side elevation and top view is known as plane view. All the 6 views can be obtained by combinations of reflection translation and rotation followed by projection onto the z = 0 plane from a center of projection at infinity on the +z-axis. The standard orthographic views don’t show the correct or true shape of these planes. It is possible to combine all the 6 views by reflection, rotation and translation followed by projection onto the z = 0 plane from the center of projection at infinity on the z-axis. b. AXANOMETRIC PROJECTION: It is used to overcome the limitation of single orthographic projection which is unable to illustrate the general 3D shape of an object. The construction of an axonometric projection is done by using rotation and translation to manipulate the object such that at least 3 adjacent faces are shown. The result is then projected at infinity onto one of the co-ordinate plane (z = 0 plane) from the center of projection. An axonometric projection shows its true shape only when a face is parallel to the plane of projection. The
  • 155. 154 foreshortening factor is the ratio of projected length of a line to its true length. Axonometric Projection is of 3 types. That is: i) Trimetric ii) Di-metric iii) Isometric i. TRIMETRIC PROJECTION: It is formed by arbitrary rotations in arbitrary order about any or all of the co-ordinate axes, followed by parallel projection onto the z- plane. For each projected principal axis (x, y and z), the foreshortening ratios are disjoint. For any specific trimetric projection, the foreshortening ratios are obtained by applying the concatenated transformation matrix to unit vectors along the principal axes. [U] = Unit vectors matrix along the untransformed x, y, and z axis respectively. [T] = Concatenated trimetric projection matrix. The forecasting or foreshortening factors are: [U][T] = 1 0 0 1 1 1 0 0 0 0 11 0 [T] = 0 0 1 1 0 Xy* Xz* Xx* 1Xx* Yy* Yz* Xx* Yx*
  • 156. 155 ii. DI-METRIC PROJECTION: It is a trimetric projection with two foreshortening factors equal and third arbitrary. It is constructed by a rotation about a y-axis through an angle ‘Φ’ followed by a rotation about the x-axis through an angle ‘θ’ and projection at infinity onto the z = 0 plane. Considering rotations with ‘Φ’ and ‘θ’, the mathematical interpretation is: [T] = [Ry] [Rx] [Pz]. The unit vectors on x, y and z principal axis transform to: 1 - sinΦ sinΦ sinΦ cosΦ [T] = 0 0 0 0 1 0 00 0 0 0cosΦ cosθ sinθ - sinθ cosθ 0 0 0 0 1 0 0 0 0 0 01 1 0 0 0 0 0 0 0 1 0 0 0 0 0 01 cosθ - cosΦsinθ cosΦsinθ sinΦ sinΦsinθ => [T] = 0 0 0 cosθ 0 1 0 00 0 0 0cosΦ fx = (Xx*)2 + (Yx*)2 )2 fy = (Xy*)2 + (Yy*)2 )2 fz = (Xz*)2 + (Yz*)2 )2
  • 157. 156 The forecasting or foreshortening factors are: iii. ISOMETRIC PROJECTION: The problem associated with di-metric projection is eliminated in isometric projection. The problem is that a di-metric projection allows two of the three transformed principal axes to be measured with the same scale factor. Measurements along the 3rd transformed principal axis require a different scale factor. If accurate scaling of the dimensions of the projected object is required, it leads to error. The solution to the above problem is isometric projection is that all 3 forecasting factors are kept equal. The projection plane normal [U*] = [U][T] = 1 0 0 1 1 1 0 0 0 0 11 0 cosθ - cosΦsinθ cosΦsinθ sinΦ sinΦsinθ 0 0 0 0 1 0 00 0 0 0cosΦ cosθ - cosΦsinθ cosΦsinθ sinΦ sinΦsinθ = 1 cosθ 1 0 00 0 1cosΦ fx = cos2 Φ + sin2 Φsin2 θ )2fy = cos2 θ = cosθ )2 fz = sin2 Φ + cos2 Φsin2 θ
  • 158. 157 makes equal angles with each principal axis. If the projection plane normal is (dx, dy, dz), then we require that: |dx| = |dy| = |dz|. The angle that the projected x-axis makes with the horizontal is important in manual construction of isometric projections. Transforming the unit vector along the x-axis using the isometric projection matrix yields: The angle between projected z-axis and horizontal is: Since, sinΦ = cosΦ, for θ = 45o , A plastic right triangle with included angles of 30o and 60o is commonly used tool for manually constructing isometric projection. c. OBLIQUE PROJECTION: It is the part of parallel projection formed by parallel projectors from a center of projection at infinity that intersect the plane of projection at an oblique angle. tanα Yx * /Xx * = sinΦsinθ/cosΦ = sinθ α = tan-1 ( sin35.26439) = 30o [U*] = [U][T] = 0 0 11 0 cosθ - cosΦsinθ cosΦsinθ sinΦ sinΦsinθ 0 0 0 cosθ 0 1 0 00 0 0 0cosΦ sinθsinΦ= 0cosΦ
  • 159. 158 An oblique projection of these faces is equivalent to an orthographic front view. Faces are not parallel to the plane of projection are distorted. It is of 2 types. i.e.: Cavalier Projection and Cabinet Projection. The Cavalier Projection is obtained when the angle between oblique projectors and the plane of projection is 45o and the foreshortening factors of all the three principal directions are equal. The Cabinet Projection is used to correct the distortion that is produced by Cavalier Projection. An oblique projection for which the foreshortening factor for edge perpendicular to the plane of projection is one-half is called a Cabinet Projection. The projection perpendicular to z-axis, the 3 x 3 transformation matrix using translation is: The translation is equivalent to shearing in ‘x’ and ‘y’ directions. The translation matrix is: 1 0 -b 0 0 0 0 0 1 0 0 0 - a a 0 01 [T2] = [T1] = 1 0 -b 1 0 0 0 1 -a
  • 160. 159 Now, projection onto the z = 0 plane gives: cosα = a/f => a = fcosα cosβ = b/f => b = fsinβ cotβ = f/1 => β = cos-1 (f) f = projected length of z-axis unit vector also called as foreshortening factor. α = angle between the horizontal and projected z-axis. The transformation matrix for oblique projection is: If f = 0, b = 90o , it is orthographic projection. If f = 1, β = 45o , the edges perpendicular to the projection plane are not foreshortened and this is the condition for a cavalier projection. ‘α’ is still a free parameter. Generally used value of ‘α’ are 30o and 45o and (180 – α) are also acceptable. 1 b α a P[0 0 1] R Q f -b - a a b x 0 y β β z f 1 0 - fsinα 0 0 0 0 0 1 0 0 0 -fcosα 0 01 [T] = 1 0 -b 0 0 0 0 0 1 0 0 0 - a a 0 01 [T] =
  • 161. 160 ii. PERSPECTIVE PROJECTION: If the center of projection is at a finite distance in 3D-space, the result is a perspective projection. The general 4 x 4 transformation matrix is: It is of 3 types. i.e.: a) single-point b) two-point c) three-point. a. SINGLE-POINT PERSPECTIVE PROJECTION: There are 3 types of single point perspective transformation are: i. When projectors are located at x-axis, it is given by: Converting into the ordinary co-ordinate, i.e.: [x* y* z* 1] = [x/(px + 1) y/(px + 1) z/(px + 1) 1] It has center of projection at [-1/p 0 0 1] and a vanishing point located on x-axis is at [1/p 0 0 1]. g i j r a b c p d e f q l m n s 4 x 4 [T] = 0 0 1 0 1 0 0 p 0 1 0 0 0 0 0 1 = [x y z (px + 1)][x* y* z* 1] = [x y z 1]
  • 162. 161 ii. The single point perspective transformation when projectors are placed on y-axis is given by: The ordinary co-ordinate: [x* y* z* 1] = [x/(qy + 1) y/(qy + 1) z/(qy + 1) 1] It has center of projection at [0 -1/q 0 1] and vanishing point is located at [0 1/q 0 1] on positive y-axis. iii. The single-point perspective transformation when projectors are placed at z-axis is given by: The ordinary co-ordinates are: [x* y* z* 1] = [x/(rz + 1) y/(rz + 1) z/(rz + 1) 1] It has center of projection at [0 0 -1/r 1] and vanishing point is located at [0 0 1/r 1] on +ve z-axis. 0 0 1 0 1 0 0 0 0 1 0 q 0 0 0 0 1 = [x y z (qy + 1)][x* y* z* 1] = [x y z 1] 0 0 1 r 1 0 0 0 0 1 0 0 0 0 0 0 1 = [x y z (rz + 1)][x* y* z* 1] = [x y z 1]
  • 163. 162 b. TWO-POINT PERSPECTIVE PROJECTION: The general 4 x 4 transformation matrix is: If any two elements of the fourth column of the above general matrix are non-zero, the result is a two-point perspective transformation. The single-point perspective transformation unfortunately does not provide an adequate view of the three-dimensional shape of an object. So, our aim is to develop some more complex perspective transformations. i.e.: the two-point perspective transformation as: The ordinary co-ordinates are: [x* y* z* 1] = [x/(px + qy + 1) y/( px + qy + 1) z/( px + qy + 1) 1] It has the two center of projections, one on x-axis at [-1/p 0 0 1] and another on y-axis at [0 -1/q 0 1]. It also has two vanishing points, one on the x-axis at [1/p 0 0 1] and another on y-axis at [0 1/q 0 1]. The two-point g i j r a b c p d e f q l m n s 4 x 4 [T] = 0 0 1 0 1 0 0 p 0 1 0 q 0 0 0 0 1 = [x y z (px + qy + 1)][x* y* z* 1] = [x y z 1]
  • 164. 163 perspective transformation can also be obtained by concatenation of two single-point perspective transformation is: c. THREE-POINT PERSPECTIVE PROJECTION: When all the 3 elements of fourth column are non-zero, the result is a 3- point perspective transformation. It is used to reconstruct the shape of a 3D object, because to draw a cute it is necessary to know the co-ordinate of the three faces, whenever a viewer stands it is possible to see maximum 3 sides of a cube which lies in 3D space. The matrix form representation of 3-point perspective transformation is: When an object has co-ordinates (x, y, z) then, 0 0 1 0 1 0 0 0 0 1 0 q 0 0 0 0 1 0 0 1 0 1 0 0 p 0 1 0 0 0 0 0 0 1 [Ppq] = [Pp][Pq] = 0 0 1 0 1 0 0 p 0 1 0 q 0 0 0 0 1 = 0 0 1 r 1 0 0 p 0 1 0 q 0 0 0 0 1 [T] = 0 0 1 r 1 0 0 p 0 1 0 q 0 0 0 0 1 = [x y z (px + qy + rz +1)][x* y* z* 1] = [x y z 1]
  • 165. 164 It has 3 center of projections, one on x-axis at [-1/p 0 0 1], second on y- axis at [0 -1/q 0 1] and third on z-axis at [0 0 -1/r 1]. It also has 3 vanishing points, one on x-axis at [1/p 0 0 1], one on y-axis at [0 1/q 0 1] and one on z- axis at [0 0 1/r 1]. The 3-point perspective transformation can also be obtained by concatenation of 3 single point perspective transformations, that is: [T] = [Pp] [Pq] [Pr] VIEWING PIPELINE: The steps for computer generation of a view of a 3D scene are somewhat analogous to the processes involved in taking a photograph. To take a snapshot, we first need to position the camera at a particular point in space. Then we need to decide on the camera orientation; which do we point the camera and how should we rotate it around the line of sight to set the up-direction for the picture. Finally, when we snap the shutter, the scene is cropped to the size of the window of the camera and light from the visible surfaces is projected onto the camera film, we need to keep in mind, however that the camera analogy can be carried only so far, since we have more flexibility and many more options for generating views of a scene with a graphics package than we do with a camera. 0 0 1 0 1 0 0 0 0 1 0 q 0 0 0 0 1 0 0 1 0 1 0 0 p 0 1 0 0 0 0 0 0 1 = 0 0 1 r 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 r 1 0 0 p 0 1 0 q 0 0 0 0 1 =
  • 166. 165 It shows the general processing steps for modeling and converting a world co- ordinates description of a scene to device co-ordinates. Once the scene has been modeled, world co-ordinate positions are converted to viewing co-ordinates. The viewing co-ordinate system in used in graphics packages as a reference for specifying the observer viewing position and the position of the projection plane, which we can think of in analogy with the camera film plane. Projection operations are performed to convert the viewing co-ordinate description of the scene to co-ordinate positions on the projection plane, which will then be mapped to the output device. Objects outside the specified viewing limits are clipped from further consideration and the remaining objects are processed through visible surface identification and surface-rendering procedures to produce the display within the device viewport. 3D CLIPPING: The general ideas involved in 3D clipping by considering how clipping planes directly. An algorithm for 3D clipping identifies and saves all surface segments Modeling Co-ordinates Modeling Transformation World Co-ordinates Viewing Transformation Viewing Co-ordinates Projection Transformation Projection Co-ordinates Workstation Transformation Device Co-ordinates
  • 167. 166 within the view volume for display on the output device. All parts of objects that are outside the view volume are discarded. Clipping in 3D can be accomplished using extensions of 2D clipping methods. Instead of clipping against straight line window boundaries, we now clip objects against the boundary planes of the view volume. To clip, a line segment against the view volume, we need to test the relative position of the line using the view volumes boundary plane equations. By substituting the line endpoint co-ordinates into the plane equation of each boundary in turn, we could determine whether the endpoint is inside or outside the boundary. An endpoint (x, y, z) of a line segment is outside the boundary plane, if Ax + By + Cz + D > 0, where A, B, C and D are the plane parameters for that boundary. Similarly, the point is inside the boundary if Ax + By + Cz + D < 0. Lines with both endpoints outside a boundary plane are discarded and those with both endpoints inside all boundary planes are saved. The intersection of a line with a boundary is found using the line equations along with the plane equation. Intersection co-ordinates (x1, y1, z1) are values that are on the line and that satisfy the plane equation Ax1 + By1 + Cz1 + D = 0. To clip a polygon surface, we can clip the individual polygon edges. First, we could test the co-ordinates extents against each boundary of the view volume to determine whether the object is completely inside or completely outside the boundary. If the co-ordinate extents of the object are inside all boundaries, we save it. If the co-ordinate extents are outside all boundaries, we discard it.
  • 168. 167 NORMALIZED VIEW VOLUME: Here, at 1st step, a scene is constructed by transforming object descriptions from modeling co-ordinates. Next, a view mapping converts the world descriptions to viewing co-ordinates. At projection stage, the viewing co-ordinates are transformed to projection co-ordinates, which effectively convert the view volume into a rectangular parallelepiped. Then the parallelepiped mapped into the unit cube, a normalized view volume called the normalized projection co-ordinate system. The normalized view volume is a region defined by the planes x = 0, x = 1, y = 0, y = 1, z = 0, z = 1 --- (1). There are several advantages to clip against the unit cube instead of the original view volume or even the rectangular parallelepiped in projection co-ordinates. i. The normalized view volume provides a standard shape for representing any sized view volume. This separates the viewing transformations from any workstation considerations and the unit cube then can be mapped to a workstation of any size. Modeling Co- ordinates Modeling Transformation World Co-ordinates Viewing Transformation Viewing Co-ordinates Projection Transformation Projection Co-ordinates Normalized Transformation Normalized Projection Co-ordinates Workstation Transformation Device Co-ordinates
  • 169. 168 ii. Clipping procedures are simplified and standardized with unit clipping planes or the viewport planes and additional clipping planes can be specified within the normalized space before transforming to device co- ordinates. iii. Depth Cueing and visible surface determination are simplified, since z-axis always points toward the viewer. Front faces of objects are those with normal vectors having a component along the positive ‘z’ direction and back surfaces are facing in the –ve z-direction. Mapping positions within a rectangular view volume to a 3D rectangular viewport is accomplished with a combination of scaling and translation, similar to the operations needed for a two-dimensional window-to-viewport mapping. We can express the 3D transformation matrix for these operations in the form: Factors Dx, Dy and Dz are the ratio of the dimensions of the viewport and regular parallelepiped view volume in the x, y and z directions. Dx = XVmax – XVmin / XWmax - XWmin Dy = YVmax – YVmin / YWmax - YWmin Dz = ZVmax – ZVmin / Zback – Zfront Where the view-volume boundaries are established by the window limits (XWmin, XWmax, YWmin, YWmax) and the position Zfront and Zback of front and back planes. Viewport boundaries are set with the co-ordinate values XVmin, XVmax, Dx 0 0 Kx 0 Dy 0 Ky 0 0 Dz Kz 0 0 0 1
  • 170. 169 YVmin, YVmax, ZVmin and ZVmax. The additive translation factors Kx, Ky and Kz in transformation are: Kx = XVmin – XWmin Dx Ky = YVmin – YWmin Dy Kz = ZVmin – ZWmin Dz VIEWPORT CLIPPING: For 3D points, we need to expand the region code to 6 bits. Each point in the description of a scene is then assigned a 6 bit region code that identifies the relative position of the point with respect to the viewport. For a line endpoint at position (x, y, z), we assign the bit positions in the region code from right to left as: Example: A region code of 101000 identifies a point as above and behind the viewport and the region code 000000 indicates a point within the volume. A line segment can immediately identified as completely within the viewport if both endpoints have a region code of 000000. If either endpoint of a line segment does not have a region code of 000000, we perform the logical operation on the two --- (1) Bit 1 = 1, if x < XVmin (left) Bit 2 = 1, if x > XVmax (right) Bit 3 = 1, if y < YVmin (below) Bit 4 = 1, if y < YVmax (above) Bit 5 = 1, if z < ZVmin (front) Bit 6 = 1, if z < ZVmax (back)
  • 171. 170 endpoint codes. The result of this ‘and’ operation will be non-zero for any line segment that has both endpoints in one of the 6 outside regions. Equations for 3D line segments are conveniently expressed in parametric form. For a line segment with endpoints P1 = (x1, y1, z1) and P2 = (x2, y2, z2). We can write the parametric line equations as: Co-ordinates (x, y, z) represent any point on the line between the 2 endpoint. At u = 0, we have the point ‘P1’ and at u = 1, puts as at ‘P2’. To find the intersection of a line with a plane of the viewport, we substitute the co-ordinate value for that plane into the appropriate parametric expression of equation – (2) and solve for ‘u’. For instance, suppose we are testing at a line against the ZVmin plane of the viewport. Then, u = ZVmin – z1/z2 – z1 --- (3). When the calculated value for ‘u’ is not in the range from 0 to 1, the line segment does not intersect the plane under consideration at any point between endpoints P1 and P2. If the calculated value for ‘u’ is in the interval from 0 to 1, we calculate the intersections ‘x’ and ‘y’ co- ordinates as: If either ‘x1’ or ‘y1’ is not in the range of the boundaries of the viewport, then this line intersects the front plane beyond the boundaries of the volume. --- (2) x = x1 + (x2 – x1)u, 0 ≤ u ≤ 1 y = y1 + (y2 – y1)u z = z1 + (z2 – z1)u --- (4) x1 = x1 + (x2 – x1)[(ZVmin – z1)/(z2 – z1)] y1 = y1 + (y2 – y1)[(ZVmin – z1)/(z2 – z1)]
  • 172. 171 CLIPPING IN HOMOGENEOUS CO-ORDINATE: At each co-ordinate position enters the transformation pipeline, it is converted to a homogeneous co-ordinate representation: (x, y, z) → (x, y, z, 1). The various transformations are applied and we obtain the final homogeneous point is: Where h = homogeneous parameter, which may not be 1. Infact, ‘h’ can have any real value. Clipping is then performed in homogeneous co-ordinates and clipped homogeneous positions are converted to non- homogeneous co-ordinates in 3D normalized projection co-ordinates: xꞌ = xh/h, yꞌ = yh/h, zꞌ = zh/h --- (2) To determine homogeneous viewpoint clipping boundaries we note that any homogeneous co-ordinate position (xh, yh, zh, h) is inside the viewport, if it satisfies the inequalities: XVmin ≤ xh/h ≤ XVmax, YVmin ≤ xh/h ≤ YVmax, ZVmin ≤ xh/h ≤ ZVmax --- (3) So, the homogeneous clipping limits are: We can simply negate the co-ordinates for any point with h < 0 and use the clipping inequalities for h > 0. a11 a12 a13 a14 a21 a22 a23 a24 a31 a32 a33 a34 a41 a42 a43 a44 x y z 1 xh yh zh = --- (1) hXVmin ≤ xh/h ≤ hXVmax, hYVmin ≤ xh/h ≤ hYVmax, hZVmin ≤ xh/h ≤ hZVmax, if h > 0 hXVmax ≤ xh/h ≤ hXVmin, hYVmax ≤ xh/h ≤ hYVmin, hZVmax ≤ xh/h ≤ hZVmin, if h < 0 --- (4)
  • 173. 172 CHAPTER – 9 CLASSIFICATION OF VISIBLE SURFACE DETECTION ALGORITHM: Visible surface detection algorithms are broadly classified to whether they deal with object definitions directly or with their projected images. These 2 approaches are called object-space methods and image-space methods respectively. An object-space method compares objects and parts of objects to each other within the scene definition to determine which surfaces, as a whole, we should label as visible. In an image-space algorithm, visibility is decided point by point at each pixel position on the projection plane. Most visible surface algorithms use image-space methods although object-space methods can be used effectively to locate visible surfaces in some cases. Line display algorithms, on the other hand generally use object-space methods to identify visible lines in wire frame displays, but many image-space visible-surface algorithms can be adapted easily to visible-line detection. BACK-FACE DETECTION: It is a fast object-space algorithm based upon the inside-outside test for identifying the back-face of polyhedron. Suppose a point (x, y, z) is inside a polygon surface with plane parameters A, B, C and D, if: Ax +By + Cz + D < 0 --- (1) When an inside point is along the line of sight to the surface, the polygon must be a back-face. That is, we are inside so we cannot see the front of it from our viewing position. Now our purpose is to simplify the test. We can consider a
  • 174. 173 normal vector ‘N’ to a polygon surface which has the Cartesian components (A, B, C). Let ‘V’ be the vector in the viewing direction from the eye, we can say a camera position, then the polygon is back-face, if: V.N > 0 --- (2) If object descriptions have been converted to projection co-ordinates and our viewing direction is parallel to the viewing z-axis, then V = (0, 0, Vz) and V.N = Vz.c. So, we only need to consider the sign of ‘c’ and the z-component of the normal vector ‘N’. In a right handed viewing system with viewing direction along the negative z- axis, the polygon is back-face. If c < 0, we cannot see any face whose normal has z-component c = 0. Thus, in general, we can label any polygon as a back-face if its normal vector has a z-component value c ≤ 0. Also, back-face has normal vectors that point away from the viewing position and are identified by c ≥ 0, when the viewing direction is along the positive z-axis. By examining parameters ‘c’ for the different planes defining an object, we can immediately identify all the back-faces. Back-face definition is done differently in different spaces. That is: i. Object Space: In this approach, we compare one surface with all the other surfaces. The comparison is done in world co-ordinates. ii. Image Space: In this approach, we determine the pixels which has illuminated by the visible surface. The visible surface is determined by the direction of normal to the plane.
  • 175. 174 DEPTH-BUFFER METHOD/Z-BUFFER METHOD: This technique is originally developed ‘CATMULL’. A commonly used image- space approach, to detect visible surfaces is the depth buffer method, which compares surface depths at each pixel position on the projection plane. This is also known as z-buffer method, since object depth is usually measured from the view plane along the z-axis of viewing system. This method is usually applied to scenes containing only polygon surfaces, because depth values can be computed very quickly and the method is easy to implement, but the method can be applied to non-planar surfaces. With the object descriptions converted to projections co-ordinates, each (x, y, z) position on a polygon surface corresponds to the orthographic projection point (x, y) on the view plane. So far, each pixel position (x, y) on the view plane, object depths can be compared by comparing z-values. yv xv S1 S3 S2 zv
  • 176. 175 Here, 3 surfaces at varying distances along the orthographic projection line from position (x, y) in a view plane taken as xvyv plane. Surface ‘S1’ is closest at this position, so its surface intensity value at (x, y) is saved. We can implement the depth-buffer algorithm is normalized co-ordinates, so that ‘z’ values range from ‘0’ at the back clipping plane to ‘Zmax’ at the front clipping plane. The value of ‘Zmax’ can be set either to 1 or to the largest value that can be stored on the system. For this method, 2 buffer areas are required. A depth buffer is used to store depth values for each (x, y) position as surfaces are processed and the refresh buffer stores the intensity values for each position. Initially, all positions in depth buffer are set to ‘0’ and the refresh buffer is initialized to the background intensity. Each surface listed in the polygon tables is the processed, one scan line at a time, calculating the depth at each (x, y) pixel position. The calculated depth is compared to the value previously stored in the depth buffer at that position. If the calculated depth is greater than the value stored in the depth buffer, the new depth value is stored and the surface intensity at that position is determined and placed in the same ‘xy’ location in the refresh buffer. DEPTH-BUFFER/Z-BUFFER ALGORITHM: 1. Initialize the depth buffer and refresh buffer, so that for all buffer positions (x, y): depth(x, y) = 0 and refresh(x, y) = Ibackground. 2. For each position on each polygon surface, compare depth values to previously stored values in the depth buffer to determine visibility.
  • 177. 176 a. Calculate the depth ‘z’ for each (x, y) position on the polygon. b. If z > depth(x, y), then set, depth(x, y) = z and refresh(x, y) = Isurface(x, y) Here, Ibackground = value for the background intensity. Isurface(x, y) = projected intensity value for the surface at pixel position (x, y). After all surfaces have been processed, the depth buffer contains depth values for the visible surfaces and the refresh buffer contains the corresponding intensity values for those surfaces. DEPTH CALCULATION: The plane equation of the face currently being scan converted is: Ax + By + Cz + D = 0 The depth values for a surface position (x, y) are calculated from the plane equation for each surface is: z = – (Ax + By + D)/C = – Ax – By – D/C Obviously, this is an excessive amount of computation to carry out at each pixel. However, the computation can be reduced to a single add per pixel by using an incremental method. So, along a scan line ‘y’ stays constant while ‘x’ increases by one. Hence ‘z’ changes by an incremental amount ‘dz’ given by:
  • 178. 177 Similarly, moving from one scan-line to the next the depth increment ‘dz’ in moving down the left most edge is given by: dz = – (B + Adx/C) Here, dx = change in ‘x’ on that edge for a change of ‘1’ in ‘y’. Thus, at each scan-line, the starting ‘z’ value is produced by a single addition of a pre-calculated quantity to the initial value at the previous scan-line. This extension is easily incorporated into the polygon scan-conversion algorithm with the requisite depth increments for a face being stored with the face in the body data structure. Only one extra addition per pixel is required over the requirements for scan conversion. Along a scan-line, when ‘y’ varies and ‘x’ is constant. zꞌ = – {Ax – B(y – 1) – D}/C = – Ax – By – D/C + B/C = z + B/C (in y-axis). Example: We have 2 surfaces. 1st Surface: P1: (10, 5, 10), P2: (10, 25, 10), P3: (25, 25, 10) and P4: (25, 5, 10). dz = – A/C => Zꞌ – Z = – A/C => Zꞌ = Z – A/C This can be calculated once for the polygon. Since, the ratio –A/C is constant for each surface, so succeeding depth values across a scan line are obtained from preceding values with a single addition.
  • 179. 178 2nd Surface: P5: (15, 15, 15), P6: (25, 25, 5), P7: (30, 10, 5) We can imagine the surface overlapping as: P5P6 = [10 10 -10] = P6 – P5 P5P7 = [15 -5 -10] = P7 – P5 P5P6 + P5P7 If we substitute the values in the standard equation: -150x – 50y – 200z + 6000 = 0 => 3x + y + 4z – 120 = 0 => z = - (3x + y – 120)/4 = - (Ax + By + D)/C For the ‘P6’ point i.e.: At 25, z = - (75 + 25 – 120)/4 = 5 At 24, z = - (75 + 24 – 120)/4 = 21/4 = 5.25 ≈ 5 Ax + By + Cz + D = 0 => z = – Ax – By – D/C = i i (-100 -50) – j (-100 + 150) + k (-50 – 150) 10 j k 10 -10 15 -5 -10 = = 150i – 50 j – 200k D = 6000
  • 180. 179 zꞌ = – {A(x + 1) – By – D}/C = – Ax – By – D/C – A/C => zꞌ = z – A/C (travelling along the scan line x-axis) => zꞌ = z – 3/4 => zꞌ = 5 – 3/4 = 4.25 ≈ 4 A-BUFFER METHOD: The A-Buffer Method represents an anti-aliased area average accumulation buffer method, for implementation in the surface rendering system called REYES (Renders Everything You Ever Saw). A drawback of depth-buffer (z-buffer) is that it can only find one visible surface at each pixel position. i.e.: it deals with only opaque surfaces. In A-Buffer, each position in the buffer can reference a linked list of surfaces. So that more than one surface intensity can be taken at each pixel position. If the depth is positive, the number stored at that position is depth of a single surface overlapping the corresponding pixel area. The intensity field then stores RGB components of the surface color at that point and percent of pixel coverage. If depth field is negative this indicates multiple surface contributions to the pixel intensity. d > 0 Depth field Intensity field d > 0 d > 0 Surface Depth Representation of Buffer for opaque surface and Representation of Buffer for Transparent Surfaces.
  • 181. 180 THE SCAN-LINE METHOD: This technique processes the scene one scan-line at a time. For each scan-line in the window, we must determine which polygons the scan-line intersects. Then for each pixel along the scan-line, determine which polygon is nearest to the eye at that point; this then determine the color of that pixel. Because, the scan-line method draws the image scan-line by scan-line, some pre-processing of the polygon mesh is required before rasterization. i. Horizontal edges must be removed; these edges will be drawn when the adjacent edges are processed. ii. The algorithm uses edge crossing to detect entry and exits of polygons. Each edge crossed changes the “inside-outside parity”. When a scan-line passes through the end-point of an edge, it produces two intersections, one for each edge that meets at that vertex. This is correct if the vertex is a local minimum or maximum. If the vertex is not a local extremum, the two intersections will cause the parity to be unchanged. To resolve this problem, when an intersection is not an extremum, simply reduce the Yupper co-ordinates of the lower line segment by 1. This will not affect the accuracy of the method as we will use the slope of the line segment before shortening. The scan-line method takes advantage of edge coherence. That is: i. Many edges that are intersected by scan-line ‘y’ are also intersected by scan-line ‘y + 1’. ii. The x-value of the point of scan-line intersection migrates predictably from scan-line to scan-line. The ‘x’ co-ordinates of the intersection of
  • 182. 181 an edge with a scan-line increase by 1/m for each scan-line, where ‘m’ is the slope of the edge. An important component in the data structure needed for this algorithm is the edge node. Each edge in the scene (after clipping) is represented by an edge node. An edge node contains the following information. That is: i. Yupper, the ‘y’ co-ordinate of the upper end point of the edge (after possibly being shortened). ii. Xint, the ‘x’ co-ordinate of the lower end point of the edge. As the algorithm progresses, this field will store the x-coordinate of the point of intersection of the scan-line. iii. ym, the reciprocal of the slope of the line (1/m). To keep track of which polygons we are currently drawing we need to build an edge table, which contains an entry for each scan-line, this entry is a list of all edges first intersected by a given scan-line. Each edge contains some information about the edge and a list of associated faces or polygons. m Scan-line y + 1 Scan-line y 1 [Incrementing the Xint using 1/m]
  • 183. 182 We also need an Active Edge List (AEL), which contains a list of edge nodes. The AEL represents edges intersected by the current scan-line. The AEL needs to be maintained as we move from one scan-line(y) to the next scan-line(y + 1). i. Some of the edges in the AEL will no longer be intersected by y + 1. Remove all edges from the AEL, where Yupper is less than y + 1. ii. The intersection point of the scan-line with the remaining edges will change for the new scan-line Xint is updated to Xint + ym. Note that Xint must be stored as a real number to avoid round-off errors. iii. New edges may need to be added to the AEL. If y + 1 is equal to Ylower of any edges in the edge table, then those edges must be added to AEL. iv. The node in the AEL must be stored (for parity checking) in ascending order of Xint. So, after adding new edges and updating the Xint values of edges, the AEL must be sorted. For each polygon in the scene, we maintain a flag which is set IN or OUT depending on whether we are inside or outside that polygon. As we process a scan- line, we will cross edges, as we cross an edge we must ‘reset’ the flag for each polygon which shares the edges. If we are IN a polygon and we pass an edge of that polygon we must reset the flag to OUT. As we process a scan-line, pixel by pixel, we need to color the pixels as follows: i. If no flags are set to IN, then the pixel gets background color. ii. If only ONE flag is set to IN, then the pixel gets the color face we are in. iii. If more than one flag is IN, we need to determine which face is closest at that point by calculating the depth of each face as in the Depth-Buffer method. The pixel gets the color of closest face.
  • 184. 183 When we are IN two or more polygons, we can calculate the closest face for each pixel or we can assume that the closest face at the first pixel of the overlap will remain the closest face until we meet another edge. This way we need only calculate depths at the beginning of an overlap area and need not do the calculations for every pixel. This will allow us to implement a very efficient algorithm. DEPTH SORTING METHOD: Depth Sorting Method is also known as Painter’s Algorithm. This method uses both image-space and object-space operations, the depth-sorting method perform the following basic functions. That is: i. Surfaces are sorted in order of decreasing depth ii. Surfaces are scan converted in order, starting with the surfaces of greatest depth. Sorting operations are carried out in both image and object space and the scan conversion of the polygon surfaces is performed in image space. This method for solving the hidden surface problem is often referred to as the painter’s algorithm, where a property of frame buffer used by Newell. The algorithm gets its name from the manner in which an oil painting is created. IMPLEMENTATION: 1. First of all, we can process each polygon independently as we did in back- face check of full screen z-buffer. 2. We must compare each polygon with all of the rest to see which is in front of which.
  • 185. 184 3. Sort the polygon to determine a property of their display. 4. The sorting will determine the order in which they will be entered into the display file. 5. For efficiency we try to limit the number of comparison process fast. The depth sort algorithm is a hybrid algorithm in that it sorts in object space and does the final rendering in image space. Hence the basic algorithm is: i. Sort all polygons in descending order of maximum z-values. ii. Resolve any ambiguities in this ordering. iii. Scan converts each polygon in the order generated by steps 1 and 2. The necessity of step-2 can be seen in the simple case: ‘A’ precedes ‘B’ in order of maximum ‘z’ but ‘B’ should precede ‘A’ in writing order. At step-2, the ordering produced by ‘1’ must be confirmed. This is done by making more precise comparison between polygons whose z-extends overlap. Assume that polygon ‘P’ is currently at the head of the sorted list, before scan converting it to the frame buffer; it is tested against each polygon ‘Q’, whose z- extent overlaps that of ‘P’. The following tests of increasing complexity are then carried out: sorts in object space and does the final rendering in image space. Hence the basic algorithm is: A Bz x
  • 186. 185 i. If the x-extents of ‘P’ and ‘Q’ don’t overlap then the polygons don’t overlap, hence their ordering is immaterial. ii. If the y-extents of ‘P’ and ‘Q’ do not overlap then the polygons do not overlap, hence their ordering is immaterial. iii. If ‘P’ is wholly on the far away side of ‘Q’ then ‘P’ is written before ‘Q’. iv. If the projection of ‘P’ and ‘Q’ do not overlap then the order ‘P’ and ‘Q’ in the list is immaterial. If any of these tests are satisfied then the ordering of ‘P’ and ‘Q’ need not be changed. However, if all five tests fails then it is assumed that ‘P’ obscures ‘Q’ and they are interchanged in the list. To avoid looping in the case where ‘P’ and ‘Q’ interpenetrate ‘Q’ must be marked as having been moved in the list. When polygon ‘Q’ which has been marked fails all tests again when tested against ‘P’, then it must be split into two polygons and each of these polygons must be treated separately, ‘Q’ is split in the plane of ‘P’ as illustrated below along AB. Often the test-5, will not be done. It can be very complex for general polygons. The Depth Sort method also has the same disadvantage as the z- buffer algorithm, namely that all the polygons are scan converted but many of them might not appear at all on the final picture. Q P z x Q P z x A B Q P
  • 187. 186 RAY TRACING ALGORITHMS: The design of hidden surface algorithms to deal with non-polynomial, non- planner surface patches is an area of active research. One algorithm, in particular, called ray-tracing algorithm, provides realistic shading, if required. This algorithm is based on the principles of light and optics. Currently, let us consider this algorithm only for hidden surface removal purpose. We shall assume opaque surfaces of given colors and deal directly with perspective projection transformation without applying perspective to parallel transformation. The basic idea is to trace light rays and determine which ones arrive back at the eye or view-point. Since this involves an infinite number of light rays, we work backward. i.e.: we trace a ray from the view point through a pixel until it reaches a surface. Since this represents the first surface seen at the given pixel, we set the pixel to the color of the surface at the point where the light ray strikes it. If resolution of screen is x1 * y1, there are ‘x1y1’ pixels and so ‘x1y1’ light rays are traced. Each ray is tested for intersections with each object in the picture, including the non-clipping plane. Since, each ray can intersect several objects; we find the x z p Ray Eye Pixel(x, y) y p1 p2 [Ray Tracing Algorithm]
  • 188. 187 intersection point ‘I’, which is closest to the viewpoint. We set the pixel belonging to the given ray to the color of the surface on which this point ‘I’ lies. This represents the first surface intersected by the ray. We repeat this process for each pixel. The computational expense can be reduced by use of the extent or bounding box of an object or surface. If a ray does not intersect a bounding box, there is no need to check for intersections with enclosed surface. The most important reason for using ray-tracing method is to create extremely realistic renderings of pictures by incorporating laws of optics for reflecting and transmitting light rays. BASIC RAY-TRACING ALGORITHM: We first set up a co-ordinate system with the pixel positions designated in the xy-plane. The scene description is given in this reference frame. From the center of projection, we then determine a ray path that passes through the center of each screen pixel position. Illumination effects accumulated along this ray path are then assigned to the pixel. This rendering approach is based on the principles of geometric optics. Light rays from the surfaces in a scene emanate in all directions, and some will pass through the pixel positions in the projection plane. Since there are infinite x z y Projection reference point - Pixel Screen area centered on viewing co-ordinate origin.
  • 189. 188 numbers of ray paths, we determine the contributions to a particular pixel by tracing a light path backward from the pixel to the scene. For each pixel ray we test surface in the scene to determine if it intersected by ray. If a surface is intersected, we calculate the distance from the pixel to the surface intersection point. The smallest calculated intersection distance identifies the visible surface for that pixel. We then reflect the ray off the visible surface along a specular path. If the surface is transparent, we also send a ray through the surface in the refraction direction. Refraction and Reflection rays are referred to as Secondary rays This procedure is repeated for each secondary ray-object is tested for intersection and the nearest surface along a secondary ray path is used to recursively produce the next generation of reflection and refraction paths. As the rays from pixel ricochet (skip off) through the scene, each successively intersected surface is added to a binary ray-tracing tree. Here, the left most branches in the tree represent reflection paths and right branches represent transmission paths. Minimum depth of the ray-tracing trees can T3 S4 S3 S1 R1 S2 R3 T1 R2 R4 a) Reflection and Refraction ray paths through screen pixel Projection Reference Point S3 S2 S4 S3 R3 T1 T3 R1 R2 R4 b) Binary ray tracing tree for the paths shown in (a)
  • 190. 189 be set as a user option or it can be determined by the amount of storage available. A path in the tree is then terminated of it reaches the preset maximum or if the ray strikes a light source. The intensity assigned to a pixel is then determined by accumulating the intensity contributions, starting at the bottom of its ray-tracing tree. Surface intensity from each node in the tree is attenuated by the distance from the “parent” surface and added to the intensity of the parent surface. Pixel intensity is then the sum of the attenuated intensities at the root node of the ray tree. If no surfaces are intersected by a pixel ray, the ray-tracing tree is empty and the pixel is assigned the intensity value of the background. If a pixel ray intersects a non-reflecting light source, although light sources are usually placed beyond the path of the initial rays. Here, a surface intersected by a ray and the unit vectors needed for the reflected light intensity calculations. Unit vector ‘u’ is in the direction of the ray path The path along ‘L’ is referred as the shadow ray. If any object intersects the shadow ray between the surface and the point light source, the surface is in shadow is in window with respect to that surface. N Refracted ray R Incoming ray H L u [Unit Vector at ace of an object intersected by an incoming ray along direction ‘u’] N = unit surface normal R = unit reflection vector L = unit vector pointing to the light source H = unit vector halfway between V (opposite to u) and L
  • 191. 190 Ambient Light at the surface is calculated as KaIa, diffuse reflection due to the source is proportional to Kd(N.L) and the specular reflection component is proportional to Ks(H.N)ns . The specular reflection direction for the secondary ray path ‘R’ depends on the surface normal and the incoming ray direction is: R = u – (2u.N)N --- (1) For a transparent surface, we also need to obtain intensity contributions from light transmitted through the material. We can locate the source of this contribution by tracing a secondary ray along the transmission direction ‘T’. The unit transmission vector can be obtained from vectors ‘u’ and ‘N’ as: T = ηi/ηr u – (cosθr – ηi/ηrcosθi) --- (2) Parameters ‘ηi’ and ‘ηr’ are the indices of refraction in the incident indices of refraction in the incident material and the refracting material respectively. Angle of refraction ‘θr’ can be calculated from Snell’s law: RAY SURFACE INTERSECTION CALCULATIONS: A ray can be described with an initial position ‘P0’ and unit direction vector ‘u’. The co-ordinate of any point ‘P’ along the ray at a distance ‘S’ from ‘P0’ is computed from the ray equation: P = P0 + Su --- (1) cosθr = 1 – (ηi/ηr)2 (1 – cos2 θi) --- (3) N Refracted ray path θr Incoming ray θi T u
  • 192. 191 Initially, P0 can be set to the position of the pixel on the projection plane or it could be chosen to be the projection reference point. Unit Vector ‘u’ is initially obtained from the position of the pixel through which the ray passes and the projection reference point. Unit vector ‘u’ is initially obtained from the position of the pixel through which the ray passes and the projection reference point: u = |Ppix – Pprp/Ppix – Pprp| --- (2) At each intersected surface, vectors ‘P0’ and ‘u’ are updated for the secondary rays at the ray-surface intersection point. For the secondary rays, reflection direction of ‘u’ is ‘R’ and the transmission direction is ‘T’. The simplest objects to ray trace are spheres. If we have a sphere of radius ‘r’ and center position ‘Pc’, then any point ‘P’ on the surface must satisfy the sphere equation: |P – Pc|2 – r2 = 0 --- (3) Substituting the ray equation i.e.: equation – (1), we have: |P0 + Su – Pc|2 – r2 = 0 --- (4) If we let ∆P = Pc – P0 and expand the dot product, we obtain the quadratic equation: S2 – 2(u.∆P)S + (|∆P| – r2 ) = 0 --- (5) x z y ray path [Describing a ray with an initial position vector ‘P0’ and unit direction vector ‘u’] u P0
  • 193. 192 Whose solution is: If the discriminant is negative, the ray does not intersect the sphere. Otherwise, the surface-intersection co-ordinates are obtained from the ray equation – (1) using the4 smaller of the two values from equation – (6). For small spheres that are far from the initial ray position, equation – (6) is susceptible to round off errors. That is, if: r2 << |∆P|2 We could lose the ‘r2 ’ term in the precision error of |∆P|2 . We can avoid this for most cases by re-arranging the calculating for distance ‘S’ as: If a ray does not intersect the sphere, we do not need to do any further testing on the polyhedron. But if the ray does intersect the sphere, we first locate front faces with the test: u.N < 0 --- (8), where N = Surface Normal For each face of the polyhedron that satisfies inequality equation – (8), we solve the plane equation: N.P = - D --- (9) S = u.∆P (u.∆P) 2 – (∆P) 2 + r2 --- (6) x z y [A ray intersecting a sphere with radius ‘r’ centered on position Pc] P0 Pc u P r S = u.∆P r2 - |∆P - (u. ∆P)u|2 --- (7)
  • 194. 193 For surface position ‘P’ that also satisfies the ray equation – (1). Here, N = (A, B, C) and ‘D’ is the fourth plane parameter. Position ‘P’ is both on the plane and on the ray path if: N.(P0 + Su) = - D --- (10) And the distance from the initial ray position to the plane is: S = - D + N.P0/N.u --- (11) This gives us position on the infinite plane that contains the polygon face but this position may not be inside the polygon boundaries. So we need to perform inside-outside test for polygon to determine whether the ray intersected this face of the polyhedron. AREA SUB-DIVISION METHOD: It is essentially an image-space method, but object-space operations can be used to accomplish depth ordering of surfaces. The area sub-division method takes advantage of area coherence in a scene by locating those view areas that represent part of a single surface. This method is applied successively dividing the total viewing area into smaller and smaller rectangles until each small area is the projection of part of a single visible surface or no surface at all. To implement this method, we need to establish tests that can quickly identify the area as part of a single surface or tell us that the area is too complex to analyze easily. Starting with the total view, we apply the tests to determine whether we [Polyhedron enclosed by a boundary sphere.]
  • 195. 194 should subdivide the total area into smaller rectangles. If the tests indicate that the view is sufficiently complex, we subdivide it. We apply the tests to each of the smaller areas subdividing these if the tests indicate the visibility of a single surface is still uncertain. We continue this process until the subdivisions area easily analyzed as belonging to the size of a single pixel. An easy way to do this is to successively divide the area into number of equal parts. Tests to determine the visibility of a single surface within a specified area are made by comparing surfaces to the boundary of the area. There are four possible relationships that a surface can have with a specified area boundary. i. Surrounding Surface: One that completely encloses the area. ii. Overlapping Surface: One that is partly inside and partly outside the area. iii. Inside Surface: One that is completely inside the area. iv. Outside Surface: One that is completely outside the area. The tests for determining surface visibility within an area can be stated in terms of these four classifications. No further sub-divisions of a specified area are needed if one of the following conditions is true: i. All Surfaces are outside surfaces with respect to the area. ii. Only one inside, overlapping or surrounding surface is in the area. iii. A surrounding surface obscures all other surfaces within the area boundaries. Test 1 can be carried out by checking the bounding rectangles of all surfaces against the area boundaries. Test 2 can also use the bounding rectangles in the xy- plane to identify an inside surface. For other types of surfaces, the bounding
  • 196. 195 rectangles can be used as an initial check. If a single bounding rectangle intersects the area in some-way, additional checks are used to determine whether the surface is surrounding, overlapping or outside. Once a single inside, overlapping or surrounding surface has been identified, its pixel intensities are transferred to the appropriate area within the frame. One method for implementing test 3 is to order surface according to their minimum depth from the view plane. For each surrounding surface, we then compute the maximum depth within the area under consideration. If the maximum depth of one of these surrounding surfaces is closer to the view plane than the minimum depth of all other surfaces within the area, test 3 is satisfied. Another method for carrying out test 3 that does not require depth sorting is to use plane equations to calculate depth values at the four vertices of the area for all surrounding, overlapping and inside surfaces. If the calculated depth for one of the surrounding surfaces is less than the calculated depths for all other surfaces, test 3 is true. Then the area can filled with the intensity values of the surrounding surface. For some situations, both methods of implementing test 3 will fail to identify correctly a surrounding surface that obscures all the other surfaces. Further testing xv zv - Zmax (Surrounding Surface) [Within a specified area, a surrounding surface with a maximum depth beyond Zmax.] Area
  • 197. 196 could be carried out to identify the single surface that covers the area but it is faster to subdivide the area than to continue with more complex testing. Once outside and surrounding surfaces have been identified for an area, they will remain outside and surrounding surfaces for all subdivisions of the area. Some inside and overlapping surfaces can be expected to be eliminated as the subdivision process continues, so that the areas become easier to analyze. RAY CASTING METHOD: If we consider the line of sight from a pixel position on view plane through a scene, we can determine which objects in the scene intersect the line. After calculating all ray-surface intersection we identify the visible surface as the one whose intersection point is closest to the pixel. The visibility detection scheme uses ray-casting procedures. Ray Casting, as a visibility-detection tool is bases on geometric, optics methods, which trace the paths of light rays. Since there are an infinite number of light rays in a scene and we are interested only in those rays that pass through pixel positions, we can trace the light ray paths backward from the pixels through the scene. The ray-casting approach is an effective visibility-detection method for scenes with curved surfaces, particularly spheres. pixel
  • 198. 197 In ray casting, we process pixels one at a time and calculate depths for all surfaces along the projection path to that pixel. Ray casting is a special case of ray tracing algorithms that trace multiple ray paths to pick up global reflection and refraction contributions from multiple objects in a scene. With ray casting, we only follow a ray out from each pixel to the nearest object.
  • 199. 198 CHAPTER – 10 CURVED LINES AND SURFACES: Display of 3D curved lines and surfaces can be generated from an input set mathematical function defining the objects or from a set of user specified data points. When a set of discrete co-ordinate points is used to specify an object shape, a functional description is obtained that best fits the designated points according to the constraints of the application. Spline Representations are examples of this class of curves and surfaces. These methods are commonly used to design new object shapes, to digitize drawings and to describe animation paths. Curve and Surface equations can be expressed in either a parametric or a non-parametric form. QUADRATIC SURFACES: Frequently used classes of objects are the Quadratic surfaces, which are described with second-degree equations. They include sphere, ellipse, tori, parabola and hyperbola. Quadratic Surfaces particularly sphere and ellipses are common elements of graphics and they are often available in graphics packages as primitives from which more complex objects can be constructed. i. SPHERE: In Cartesian co-ordinates, a spherical surface with radius ‘r’ centered on the co-ordinate origin is defined as the set of points (x, y, z) that satisfy the equation: x2 + y2 + z2 = r2 --- (1)
  • 200. 199 The spherical surface in parametric form using latitude and longitude angles as: This parametric representation provides a symmetric range for the angular parameters ‘θ’ and ‘Φ’. We could write the parametric equations using standard spherical co-ordinates where angle ‘Φ’ is specified as the colatitude. Then ‘Φ’ is defined over the range 0 ≤ Φ ≤ π and ‘θ’ is often taken in the range 0 ≤ θ ≤ 2π. We could also set up the representation using parameters ‘u’ and ‘v’ defined over the range from 0 to 1 by substituting Φ = πu and θ = 2πv. ii. ELLIPSE: An ellipsoidal surface can be described as an extension of a spherical surface, where the radii in 3 mutually perpendicular directions can have different values. --- (2) x = rcosΦcosθ, -π/2 ≤ Φ ≤ π/2 y = rcosΦsinθ, -π ≤ θ ≤ π z = rsinΦ P = (x, y, z) z-axis x-axis y-axis Φ θ P z-axis x-axis y-axis Φ Spherical co-ordinate parameters (r, θ, Φ) using colatitude for angle ‘Φ’
  • 201. 200 The Cartesian representation for points over the surface of an ellipsoid centered on the origin is: (x/rx)2 + (y/ry)2 + (z/rz)2 = 1 --- (3) And a parametric representation for the ellipsoid in terms of the latitude angle ‘Φ’ and the longitude angle ‘θ’ is: iii. TORUS: It is a doughnut-shaped object. It can be generated by rotating a circle or other conic about a specified axis. The Cartesian representation for points over the surface of a torus can be written in the form: Where r = any given offset value. Parametric representations for a torus are similar to those for an ellipse, except that angle ‘Φ’ extends over 360o. Using latitude and longitude angle ‘Φ’ and ‘θ’, we can describe the torus surface as the set of points that satisfy: [r - (x/rx)2 + (y/ry)2 ]2 + (z/rz)2 = 1 --- (5) --- (4) x = rxcosΦcosθ, -π/2 ≤ Φ ≤ π/2 y = rycosΦsinθ, -π ≤ θ ≤ π z = rzsinΦ z y x rz rx ry An ellipsoid with radii ‘rx’, ‘ry’ and ‘rz’ centered on the co-ordinate origin.
  • 202. 201 BSP TREES: It is a representation scheme is similar to octree encoding, except we now divide space into two partitions instead of eight at each step. With a binary space partitioning (BSP) tree, we sub-divide a scene into two sections at each step with a plane that can be at any positions and orientation. For adaptive subdivision of space, BSP trees can provide a more efficient partitioning since we can position and orient the cutting planes to suit the spatial distribution of the objects. This can reduce the depth of the tree representation for a scene, compared to an octree and thus reduce the time to search the tree. In addition, BSP trees are useful for identifying visible surfaces and for space partitioning in ray-tracing algorithm. --- (6) x = rx(r + cosΦ)cosθ, -π ≤ Φ ≤ π y = ry(r + cosΦ)sinθ, -π ≤ θ ≤ π y = rzsinθ z-axis rz xy-plane 0 Φ (x, y, z) rx = ry 0 (x, y, z) θ y-axis
  • 203. 202 OCTREES: Hierarchical tree structures called octree are used to represent solid objects in graphics systems. Medical image and other applications that require displays of object cross sections commonly use octree representations. The octree encoding procedure for a 3D space is an extension of an encoding scheme for a 2D space, called quad-tree encoding. Quad-tree is generated by successively dividing a 2D region into quadrants. Each node in the quad-tree has 4 data elements, one for each of the quadrants in the region. If all pixels within a quadrant tree have the same color, the corresponding data element in the node stores that color. A flag is set in the data element to indicate that the quadrant is homogeneous. If all pixels in quadrant 2 are found to be red, the color code for red is then placed in data element 2 of the node. Otherwise the quadrant is said to be heterogeneous and that quadrant is itself divided into quadrants. The corresponding data element in the node now flags the quadrant as heterogeneous and stores the pointer to the next node in quad-tree. Quadrant 4 Quadrant 1 Quadrant 3 Quadrant 2 REGION OF A 2D SPACE 3210 DATA ELEMENTS IN THE REPRESENTIVE QUAD-TREE NODE 3 2 10 REGION OF 2D SPACE 10 32 10 32 QUAD-TREE REPRESENTATION
  • 204. 203 SPLINE REPRESENTATION: In drafting terminology, a spline is a flexible strip used to produce a smooth curve through a designated set of points. Several small weights are distributed along the length of the strip to hold it in position on the drafting table as the curve is drawn. The term spline curve, originally referred to a curve drawn this manner. In computer graphics, the term spline curve now refers to any composite curve formed with polynomial sections satisfying specified continuity conditions at the boundary of the pieces. A spline surface can be described with two sets of orthogonal spline curves. Splines are used in graphics applications to design curve and surface shapes to digitize drawings for computer storage and to specify animation paths for the objects or the camera in a scene. INTERPOLATION AND APPROXIMATION SPLINES: We specify a spline curve by giving a set of co-ordinate positions, called control points, which indicates the general shape of the curve. The control points are then fitted with piecewise continuous parametric polynomial functions in one of two ways. When polynomial sections are fitted so that the curve passes through each control point, the resulting curve is said to interpolate the set of control points. When the polynomials are fitted to the general control point path without necessarily passing through any control point, the resulting curve is said to approximate the set of control points.
  • 205. 204 Interpolation curves are commonly used to digitize drawings to specify animation paths. Approximation curves are primarily used as design tools to structure object surfaces. A spline curve is defined, modified and manipulated with operations on the control points. The convex polygon boundary that encloses a set of control points is called the convex hull. One way to envision the shape of a convex hull is to imagine a rubber band stretched around the positions of the control points, so that each control point is either on the perimeter of the hull or inside it. P0 P1 P2 P3 P0 P1 P2 P3 2 Convex hull shapes (dashed lines) for 2 sets of control points P0 P1 P2 2 P3 2 P0 P1 P2 2 P3 Control graphs shapes for 2 different sets of control point. → A set of 6 control points interpolated with piecewise continuous polynomial sections. [A set of 6 control points approximated with piecewise continuous polynomial sections.]
  • 206. 205 Convex hulls provide a measure for the deviation of a curve or surface from the region bounding the control points. Some splines are bounded by the convex hull, thus ensuring that the polynomials smoothly follow the control points without erratic oscillations. A polyline connecting the sequence of control points for an approximation spline is usually displayed to remind a designer of the control-point ordering. This set of connected line segments is often referred to as the control graph of the curve. Other names for the series of straight line sections connecting the control points in the order specified are control polygon and characteristic polygon. PARAMETRIC CONTINUITY CONDITIONS: To ensure a smooth transition from one section of a piecewise parametric curve to the next, we can impose various continuity conditions at the connection points. If each section of a spline is described with a set of parametric co-ordinate function of the form: x = x(u), y = y(u), z = z(u), u1 ≤ u ≤ u2 --- (1) We set parametric continuity by matching the parametric derivations of adjoining curve sections at their common boundary. a) Zero-Order Parametric Continuity, desired as Co -Continuity, means simply that the curve meet. That is the value of x, y and z evaluated at ‘u2’, for the first curve section are equal respectively to the values of x, y and z evaluated at ‘u1’ for the next curve section. b) First-Order Parametric Continuity, referred to as C1 -Continuity, means that the first parametric derivatives of the co-ordinate function in derivatives
  • 207. 206 of the co-ordinate function in equation-(1) for two successive curve sections are equal at their joining point. c) Second-Order Parametric Continuity, referred as C2 -Continuity, means that both the first and second parametric derivatives of the two curve sections are the same at the intersection. Higher-order parametric continuity conditions are defined similarly. GEOMETRIC CONTINUITY CONDITIONS: An alternate method for joining two successive curve sections is to specify conditions for geometric continuity. In this case, we only require parametric derivatives of the two sections to be proportional to each other at their common boundary instead of equal to each other. Zero-Order Geometric Continuity described as Go -Continuity is the same as zero-order parametric continuity. i.e.: the 2 curves sections must have the same co- ordinate position at the boundary point. First-Order Geometric Continuity or G1 -Continuity means that the parametric 1st derivatives are proportional at the intersection of two successive sections. If we donate the parametric position on the curve as P(u), the direction of the tangent vector Pꞌ(u), but not necessarily its magnitude, will be the same for two successive curve sections at their joining point under G1 -Continuity. C O N T I N U I T Y C O N D I T I O N S : Zero-Order Continuity C O N T I N U I T Y C O N D I T I O N S : First-Order Continuity Second-Order Continuity
  • 208. 207 Second-Order Geometric Continuity or G2 -Continuity means that both the first and second parametric derivatives of the two curve sections are proportional at their boundary. Under G2 -Continuity, curvatures of two curve sections will match at the joining position. SPLINE SPECIFICATIONS: There are 3 equivalent methods for specifying a particular spline representation: i. We can state the set of boundary conditions that are imposed on the spline. ii. We can state the matrix that characterizes the spline. iii. We can state the set of blending functions or basis functions that determine how specified geometric constraints on the curve are combined to calculate positions along the curve path. To illustrate these 3 equivalent specifications, suppose we have the following parametric cubic polynomial representation for the x-co-ordinate along the path of a spline section: x(u) = axu3 + bxu2 + cxu + dx, 0 ≤ u ≤ 1 --- (1) Boundary condition for this curve might be set. E.g.: On the end point co-ordinates x(0) and x(1) and on the parametric 1st derivatives at the endpoints xꞌ(0) and xꞌ(1). These four boundary conditions are sufficient to determine the values of the four coefficients ax, bx, cx and dx. From the boundary conditions, we can obtain the matrix that characterizes this spline curve by first rewriting equation (1) as the matrix product:
  • 209. 208 Where U = row matrix of powers of parameter ‘u’, C = coefficient column matrix. Using equation-(2), we can write the boundary conditions in matrix form and solve for the coefficient matrix ‘C’ as: C = Mspline . Mgeom --- (3) Where, Mgeom = four element column matrix containing the geometric constraint values on the spline and Mspline = 4 by 4 matrix, which transforms the geometric constraint values to the polynomial coefficients and provides a characterization for the spline curve. Matrix ‘Mgeom’ contains control point co-ordinate values and other geometric constraints that have been specified. So, we can substitute the matrix representation for ‘C’ in equation-(2) to obtain: x(u) = U . Mspline . Mgeom --- (4) The matrix ‘Mspline’ characterizing a spline representation, sometimes called the basis matrix, is particularly useful for transforming from one spline representation to another. Finally, we can expand equation-(4) to obtain a polynomial representation for co-ordinate ‘x’ in terms of the geometric constraint parameters: x(u) = Σ gk . BFk(u) --- (5) k = 0 3 = U . C --- (2) ax bx cx dx x(u) = u3 u2 u 1
  • 210. 209 Where, ‘gk’ are the constraint parameters, such as the control-point co-ordinates and slope of the curve at the control points and BFk(u) are the polynomial blending functions. B-SPLINE CURVES AND SURFACES: B-Splines have two advantages over Bezier Splines. That is: i. The degree of a B-Spline polynomial can be set independently of the number of control points. ii. B-Splines allow local control over the shape of a spline-curve of surface. The trade-off is that B-Splines are more complex than Bezier Splines. B-SPLINE CURVES: A general expression for the calculation of co-ordinate positions along a B- Spline curve in a blending function formulation as: Where, Pk = input set of ‘n + 1’ control points. There are several differences between this B-Spline formulation and that for Bezier Splines. The range of parameter ‘u’ now depends on how we choose the B- Splines Parameters and the B-Spline blending functions Bk, d are polynomials of degree d – 1, where parameter ‘d’ can be chosen to be any integer value in the range from 2 upto the number of control points n + 1. P(u) = Σ Pk . Bk, d(u), umin ≤ u ≤ umax and 2 ≤ d ≤ n + 1 --- (1) k = 0 n 3
  • 211. 210 Local control for B-Splines is achieved by defining the blending functions over sub-intervals of the total range ‘u’. Blending functions for B-Spline curves are defined by the Cox-deBoor recursion formulas: Here, each blending function is defined over ꞌdꞌ sub-intervals of the total range of ‘u’. The selected set of sub-interval endpoints ‘uj’ is referred to as a knot vector. We can choose any values for the sub-interval endpoints satisfying the relation that is: uj ≤ uj + 1. Values for umin and umax then depend on the number of control points we select. The value we choose for parameter ꞌdꞌ and how we set up the sub- intervals. B-Spline Curves have the following properties: i. The polynomial curve has degree d – 1 and Cd – 2 continuity over the range of ‘u’. ii. For n + 1 control points, the curve is described with n + 1 blending functions. iii. Each blending function Bk, d is defined over ꞌdꞌ sub-intervals of total range of ‘u’, starting at knot value ‘uk’. iv. The range of parameter ‘u’ is divided into n + d subintervals by n + d + 1 values specified in the knot vector. Bk, 1(u) = 1, if uk ≤ u ≤ uk + 1 Bk, d(u) = 0, otherwise u – uk uk + d - 1 – uk Bk, d - 1(u) + uk + d – u uk + d – uk + 1 Bk + 1, d + 1(u) + --- (2)
  • 212. 211 v. With knot values labeled as {u0, u1, … , un + d}, the resulting B-Spline curve is defined only in the interval from knot value ud – 1 upto knot value un + 1. vi. Each section of the spline curve is influenced by ꞌdꞌ control points. vii. Any one control point can affect the shape of at most ꞌdꞌ curve sections. A B-Spline curve lies within the convex hull of at most ꞌd + 1ꞌ control points, so that B-Splines are tightly bound to the input positions. For any value of ‘u’ in the interval from knot value ud – 1 to un + 1, the sum over all basis functions is 1. a) UNIFORM, PERIODIC B-SPLINES: When the spacing between knot values is constant, the resulting curve is called a uniform B-Spline. Example: We can set up a uniform knot vector as: {-1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0}. Often knot values are normalized to the range between ‘0’ and ‘1’ as in: {0.0, 0.2, 0.4, 0.6, 0.8, 1.0}. Σ Bk, d(u) = 1 --- (3) k = 0 n 3 Local Modification of a B-Spline Curve changing one of the control points in (a) produces curve, (b) which is modified only in the neighborhood of the altered control point. (a) (b)
  • 213. 212 It is convenient in many applications to set up uniform knot values with a separation of ‘1’ and a starting value of ‘0’. The following knot vector is an example of this scheme. B0, 3(u) = {0, 1, 2, 3, 4, 5, 6, 7} Uniform B-Splines have periodic blending functions. That is: for given value of ꞌnꞌ and ꞌdꞌ, all blending functions have the same shape. Each 0 54321 6 1 0.2 0.4 0.6 0.8 (u) B0, 3(u) 0 54321 6 1 0.2 0.4 0.6 0.8 (u) B1, 3(u) 0 54321 6 1 0.2 0.4 0.6 0.8 (u) B2, 3(u) 0 54321 6 1 0.2 0.4 0.6 0.8 (u) B3, 3(u) [Periodic B-Splines blending functions n = d = 3 and a uniform, integer knot vector]
  • 214. 213 successive blending function is simply a shifted version of the previous function: Bk, d(u) = Bk + 1, d(u + ∆u) = Bk + 2, d(u + ∆u) --- (4) Where ∆u = interval between adjacent knot values. b) UNIFORM, QUADRATIC B-SPLINES: Example: illustrate the calculation of B-Spline blending functions for a uniform integer knot vector, we select parameter values d = n = 3. The knot values:- {0, 1, 2, 3, 4, 5, 6} and the range of parameter ‘u’ is from 0 to 6, with n + d = 6 subintervals. Each of the 4 blending functions spans d = 3 subintervals of the total range of ‘u’. Using the recurrence relations equation - (2), we obtain the first blending function as: We obtain the next periodic blending function using relationship - (4), substituting u – 1 for ‘u’ in B0, 3 and shifting the staring positions up by 1: B0, 3(u) = 1/2u2 , for 0 ≤ u < 1 1/2u(2 – u) + 1/2(u – 1)(3 – u), for 1 ≤ u < 2 1/2(3 – u)2 , for 2 ≤ u < 3 B1, 3(u) = 1/2(u – 1)2 , for 1 ≤ u < 2 1/2(u – 1)(3 – u) + 1/2(u – 2)(4 – u), for 2 ≤ u < 3 1/2(4 – u)2 , for 3 ≤ u < 4
  • 215. 214 Similarly, the remaining two periodic functions are obtained by successively shifting B1, 3 to the right: A plot of the four periodic, quadratic blending functions is given in the figure, which demonstrates the local features of B-Splines. The first control point is multiplied by blending function B0, 3(u). So, changing the position of the first control point only affects the shape of the curve upto u = 3. Similarly, the last control point influences the shape of the spline curve in the interval where B3, 3 is defined. The range of the resulting polynomial curve is from 2 to 4, we can determine the starting and ending positions of the curve by evaluating the blending functions at these points to obtain: Pstart = 1/2(P0 + P1), Pend = 1/2(P2 + P3) Thus, the curve starts at the mid position between the first two control points and ends at the mid position between the last control points. B2, 3(u) = 1/2(u – 2)2 , for 2 ≤ u < 3 1/2(u – 2)(4 – u) + 1/2(u – 3)(5 – u), for 3 ≤ u < 4 1/2(5 – u)2 , for 4 ≤ u < 5 B3, 3(u) = 1/2(u – 3)2 , for 3 ≤ u < 4 1/2(u – 3)(5 – u) + 1/2(u – 4)(6 – u), for 4 ≤ u < 5 1/2(6 – u)2 , for 5 ≤ u < 6
  • 216. 215 We can also determine the parametric derivatives at the starting and ending positions of the curve. Taking the derivatives of the blending functions and substituting the endpoints values for parameter u, we find that: Pꞌstart = P1 – P0, Pꞌend = P3 – P2 The parametric slope of the curve at the start position is parallel to the line joining the last two control points. General expressions for the boundary conditions for periodic B-Splines can be obtained by re-parameterizing the blending functions. So that parameter ‘u’ is mapped onto the unit interval from 0 to 1. Beginning and ending conditions are then obtained at u = 0 and u = 1. c) CUBIC, PERIODIC B-SPLINES: Since cubic, periodic B-Splines are commonly used in graphics packages, we consider the formulation for this class of splines. Periodic Splines are particularly useful for generating certain closed curves. E.g.: The closed curve can be generated in sections by cyclically specifying four of the six control points shown at each step. If any three consecutive control points are identical, the curve passes through that co- ordinate position. For cubic, d = 4 and each blending function spans four subintervals of the total range of ‘u’. If we are to fit the cubic to four control points, then we could use the integer knot vector: {0, 1, 2, 3, 4, 5, 6, 7} and the recurrence relations – equation – (2) to obtain the periodic blending functions, as we did in the last section for quadratic periodic B-Splines.
  • 217. 216 This is an alternate formulation for periodic cubic B-Splines. We start with the boundary conditions and obtain the blending functions normalized to the internal 0 ≤ u ≤ 1. Using this formulation, we can also easily obtain the characteristic matrix. The boundary conditions for periodic cubic B-Splines with four consecutive control points, labeled P0, P1, P2 and P3 are: The B-Splines curve section starts at a position near P1 and ends at a position near P2. A matrix formulation for cubic periodic B-Splines with four control points can then be written as: Where, the B-Spline matrix for periodic cubic polynomials i.e.: P(0) = 1/6(P0 +4P1 + P2), Pꞌ(0) = 1/2(P2 - P0) P(1) = 1/6(P1 +4P2 + P3), Pꞌ(1) = 1/2(P3 – P1) --- (1) P0 P1 P3 P2 P5 P4 P2 P(u) = u3 MB P0 P1 P3 u2 u 1 --- (2) 1 0 0 0 MB = -1 3 -3 1 -3 3 3 1 3 -6 0 4 --- (3)1/6
  • 218. 217 This matrix can be obtained by solving for the coefficients in a general cubic polynomial expression using the specified four boundary condition. We can also modify the B-Spline equations to include tension parameter 't'. The periodic, cubic B-Spline with tension matrix then has the form: Which reduces to MB, when t = 1. We obtain the periodic, cubic B-Spline blending functions over the parameter range from 0 to 1 by expanding the matrix representation into polynomial form. E.g.: For the tension value t = 1, we have: d) OPEN UNIFORM B-SPLINES: This class of B-Splines is a cross between uniform B-Splines is a cross between uniform B-Splines and non-uniform B-Splines. Sometimes, it is treated as a special type of uniform B-Spline and sometimes it is considered to be in the non-uniform B-Spline classification. 1 0 0 0 MBt = - t 3t - 3t t 9t - 12 18 – 15t 3t t 12 – 9t 12t - 18 0 6 – 2t --- (4)1/6 B0, 3(u) = 1/6(1 – u)3 , 0 ≤ u ≤ 1, B1, 3(u) = 1/6(3u3 – 6u2 + u) B2, 3(u) = 1/6(– 3u3 + 3u2 + 3u + 1) and B3, 3(u) = 1/6u3 --- (1)
  • 219. 218 For the open uniform B-Splines or open B-Splines, the knot spacing is uniform except at the ends where knot values are repeated ꞌdꞌ times. Following are two examples of open uniform, integer knot vectors, each with a starting value of 0: {0, 0, 1, 2, 3, 3}, for d = 2 and n = 3 and {0, 0, 0, 0, 1, 2, 2, 2, 2}, for d = 4 and n = 4. We can normalize these knot vectors to the unit interval from 0 to 1: {0, 0, 0.33, 0.67, 1, 1} for d = 2 and n = 3. {0, 0, 0, 0, 0.5, 1, 1, 1, 1}, for d = 4 and n = 4. For any values of parameter ꞌdꞌ and ‘n’, we can generate an open uniform knot vector with integer values using the calculations: For values of ‘j’ ranging from 0 to n + d. With this assignment, the first ꞌdꞌ knots are assigned the value o and the last ꞌdꞌ knots have the value n – d + 2. Open uniform B-Splines have characteristics that are very similar to Bezier Splines. In fact, when d = n + 1, open B-Splines reduce to Bezier Splines and all knot values are either 0 or 1. Example: With a cubic, open B-Spline (d = 4) and 4 control points, the knot vector is: {0, 0, 0, 0, 1, 1, 1, 1, the polynomial curve for an open B-Spline passes through the first and last control points. The slope of the parametric uj = 0, for 0 ≤ j < d j – d + 1, for, d ≤ j ≤ n --- (1) n – d + 2, for j > n
  • 220. 219 curves at the 1st control point is parallel to the line connecting the 1st two control points and the parametric slope at the last control point is parallel to the line connecting the last 2 control points. e) OPEN UNIFORM, QUADRATIC B-SPLINES: From the conditions – (1) with d = 3 and n = 4 (five control points), we obtain the following 8 values for the knot vector: {u1, u2, u3, u4, u5, u6, u7} = {0, 0, 0, 1, 2, 3, 3, 3}. The total range of ‘u’ is divided into seven subintervals, and each of the five blending functions Bk, 3 is defined over 3 subintervals, starting at knot position ‘uk’. So, B0, 3 is defined from u0 = 0 to u3 = 1. B1, 3 is defined from u1 = 0 to u4 =3 and B4, 3 is defined from u4 = 2 and u7 = 3. Explicit polynomial expressions are obtained for the blending functions from recurrence relation – (2) as: B0, 3(u) = (1 – u)2 , 0 ≤ u ≤ 1 B1, 3(u) = 1/2u(u – 3u), for 0 ≤ u < 1 1/2(2 – u)2 , for 1 ≤ u < 2 B2, 3(u) = 1/2u2 , for 0 ≤ u < 1 1/2u(2 – u) + 1/2(u – 1)(3 – u), for 1 ≤ u < 2 1/2(3 – u)2 , for 2 ≤ u < 3 B3, 3(u) = 1/2(u – 1)2 , for 1 ≤ u < 2 1/2(3 – u)(3u – 5), for 2 ≤ u < 3 B4, 3(u) = (u – 2)2 , 2 ≤ u < 3
  • 221. 220 Here, the shapes of these five blending functions are given. The local features of B-Splines are again demonstrated Blending function B0, 3 is non-zero only in the sub-internal from 0 to 1. So, the first control point influences the curve only in this interval. Similarly, function B4, 3 is zero outside the interval from 2 to 3 and the position of the last control point does not affect the shape of the beginning and middle parts of the curve. 0 2.50 21.510.5 3 1 0.2 0.4 0.6 0.8 (u) B0, 3(u) 0 2.50 21.510.5 3 1 0.2 0.4 0.6 0.8 (u) B1, 3(u) 0 2.50 21.510.5 3 1 0.2 0.4 0.6 0.8 (u) B2, 3(u) 0 2.50 21.510.5 3 1 0.2 0.4 0.6 0.8 (u) B3, 3(u)
  • 222. 221 f) NON-UNIFORM B-SPLINES: For this class of splines, we can specify any values and intervals for the knot vector. With non-uniform B-Splines, we can choose multiple interval knot values and unequal spacing between the knot values. E.g.: {0, 1, 2, 3, 3, 4}, {0, 2, 2, 3, 3, 6}, {0, 0, 0, 1, 1, 3, 3, 3} and {0, 0.2, 0.6, 0.9, 1.0}. Non-uniform B-Splines provide increased flexibility in controlling a curve shape. With unequally spaced intervals in the knot vector, we obtain different shapes for the blending functions in different intervals, which can be used to adjust spline shapes. By increasing knot multiplicity, we produce subtle variations in curve shape and even introduce discontinues. Multiple knot values also reduce the continuity by 1 for each repeat of a particular value. We obtain the blending functions for non-uniform B-Spline using methods similar to those discussed for uniform and open B-Splines. Given, a 0 2.50 21.510.5 3 1 0.2 0.4 0.6 0.8 (u) B4, 3(u)
  • 223. 222 set of n + 1 control points, we set the degree of the polynomial and select the knot values. Then using the recurrence relations, we could either obtain the set of blending functions or evaluate curve positions directly for the display of the curve. B-SPLINE SURFACES: Formulation of a B-Spline surface is similar to that of Bezier Splines. We can obtain a vector point function over a B-Spline blending functions in the form: Here the vector values for Pk1.k2 specify positions of (n1 + 1) by (n2 + 1) control points. B-Splines surfaces exhibit the same properties are those of their component B- Spline curves. A surface can be constructed from selected values for parameters ‘d1’ and d2 and from the specified knot vectors. BEZIER CURVES: The concept of Bezier Curve was given by Pierre Bezier. A Bezier Curve is determined by a defining polygon known as convex hull. PARAMETRIC REPRESENTATION OF BEZIER CURVE: A Bezier Curve is represented parametrically by: P(u, v) = Σ Σ Pk1.k2 . Bk1.d1(u) Bk2.d2(v) --- (1) k1 = 0 n1 n2 k2 = 0 P(u) = Σ Pk . BEZk, n(u), 0 ≤ u ≤ 1 --- (1) k = 0 n
  • 224. 223 The Bezier blending function BEZk, n(u) are the Bernstein Polynomials, written as: BEZk, n(u) = C(n, k)uk (1 – u)n – k --- (2) Here C(n, k) = binomial coefficients, expressed as: C(n, k) = n!/k!(n – k)!. Equivalently, we can define Bezier blending functions with the recursive calculation: BEZk, n(u) = (1 – u)BEZk, n - 1(u) + uBEZk - 1, n - 1(u), n > k ≥ 1 --- (3) With BEZk, k = uk and BEZ0, k= (1 – u)k Vector equation – (1), represents a set of three parametric equations for the individual curve co-ordinates: As a rule, a Bezier Curve is a polynomial of degree one less than the number of control points used: i) 3 points generate a parabola and ii) 4 points generate a cubic curve and so on. x(u) = Σ xk . BEZk, n(u) k = 0 n y(u) = Σ yk . BEZk, n(u) k = 0 n z(u) = Σ zk . BEZk, n(u) k = 0 n --- (4) (a) p1 p0 p2 (b) p1 p0 p2 p3 (c) p1 p0 p2 p3
  • 225. 224 Efficient methods for determining co-ordinate positions along a Bezier Curve can be set up using recursive calculation. Example: Successive binomial coefficients can be calculated as: C(n, k) = n – k + 1/k C(n, k – 1) for n ≥ k PROPERTIES OF BEZEIR CURVES: i) It always passes through the first and last control points that is, the boundary conditions at the 2 ends of the curve are: P(0) = P0 and P(1) = Pn --- (1) ii) Values of the parametric first derivatives of a Bezier Curve at the endpoints can be calculated from control point co-ordinate as: Pꞌ(0) = – nP0 + nP1 and Pꞌ(1) = – Pn – 1 + nPn --- (2) Thus, the slope at the beginning of the curve is along the line joining the first two control points and the slope at the end of the curve is along the line joining the last 2 endpoints. iii) The Parametric second derivatives of a Bezier Curve at the endpoints are calculated as: (d) p1 p0 p2 p3 (e) p1 p0 p2 p3 p4
  • 226. 225 Another important property of any Bezier Curve is that it lies within the convex hull of the control points. This follows from the properties of Bezier blending functions. They are all positive and their sum is always 1. That is: So, that any curve position is simply the weighted sum of the control point positions. The convex-hull property for a Bezier Curve ensures that the polynomial smoothly follows the control points without erratic oscillations. CUBIC BEZIER CURVES: Cubic Bezier curves are generated with four control points. The 4 blending functions for cubic Bezier curves obtained by substituting n = 3 into the Bezier blending functions are: The form of the blending functions determine how the control points influence the shape of the curve for values of parameter ‘u’ over the range from 0 to 1. At u = 0, the only non-zero blending function is BEZ0, 3 which at the value 1. At u = 1, Σ BEZk, n(u) = 1 --- (4) k = 0 n BEZ0, 3(u) = (1 – u)3 BEZ1, 3(u) = 3u(1 – u)2 BEZ2, 3(u) = 3u2 (1 – u) BEZ3, 3(u) = u3 --- (1) Pꞌꞌ(0) = n(n – 1)[(P2 – P1) – (P1 – P0)] Pꞌꞌ(1) = n (n – 1) [(Pn – 2 – Pn – 1) – (Pn - 1 – Pn)] --- (3)
  • 227. 226 the only non-zero blending function is BEZ3, 3 with a value of 1 at that point. Thus the cubic Bezier curve will always pass through control points ‘P0’ and ‘P3’. The other functions BEZ1, 3 and BEZ2, 3 influence the shape of the curve at intermediate values of parameter ‘u’, so that the resulting curve tends toward points P1 and P2. Blending function BEZ1, 3 is maximum at u = 1/3 and BEZ2, 3 is maximum at u = 2/3. Each of the four blending functions is non-zero over the entire range of parameter ‘u’. So the Bezier curves don’t allow for local control of the curve shape. If we decide to reposition any one of the control points, the entire curve will be affected. At the end positions of the cubic Bezier curve, the parametric first derivatives are: Pꞌ(0) = 3(P1 – P0), Pꞌ(1) = 3(P3 – P2) and the parametric second derivatives are: Pꞌꞌ(0) = 6(P0 – 2P1 + P2), Pꞌꞌ(1) = 6(P1 – 2P2 + P3). We can use these expressions for the parametric derivatives to construct piecewise curves with C1 or C2 continuity between sections. By expanding the polynomial expressions for the blending functions, we can write the cubic Bezier point function in the matrix form: --- (2) P0 P1 P2 P3 u3 u2 u 1P(u) = MBEZ
  • 228. 227 Where Bezier Matrix is: We could also introduce additional parameters, to allow adjustment of curve “tension” and “bias”, as we did with the interpolating splines. But the more useful B-Splines, as well as B-Splines, provide this capability. BEZIER SURFACES: Two sets of orthogonal Bezier Curves can be used to design an object surface by specifying by an input mesh of control points. The parametric vector function for the Bezier Surface is formed as the Cartesian product of Bezier blending functions: With Pj, k specifying the location of the (m + 1) by (n + 1) control points. Bezier Surfaces have the same properties as Bezier Curves and they provide a convenient method for interactive design applications. For each surface patch, we can select a mesh of control points in the xy “ground” plane then we choose elevations above the ground plane for the z- coordinates values of the control points. Patches can then be pieced together using the boundary constraints. P(u, v) = Σ Σ Pj, k BEZj, m(v)BEZk, n(u) --- (1) j = 0 m n k = 0 MBEZ = -1 3 -3 1 3 -6 3 0 -3 3 0 0 1 0 0 0 --- (3)
  • 229. 228 Example 1: Derive the parametric equation for a cubic Bezier Curve. For a cubic Bezier curve, n = 3, => P(u) = P0BEZ0, 3(u) + P1BEZ1, 3(u) + P2BEZ2, 3(u) + P3BEZ3, 3(u) BEZk, n(u) = C(n, k)uk (1 – u)n – k BEZ0, 3(u) = [3!/0!(3 – 0)!]u0 (1 – u)3 (since, C(n, k) = n!/k!(n – k)!) = [3 * 2 * 1/1 * (3 * 2 * 1)] * 1 * (1 – u)3 = (1 – u)3 BEZ1, 3(u) = C(3, 1)u1 (1 - u)3 – 1 = [3!/1!(3 – 1)!]u1 (1 – u)2 = [3!/1!(2!)] u1 (1 – u)2 = [3 * 2 * 1/1 * (2 * 1)] * u(1 – u)2 = 3u(1 – u)2 BEZ2, 3(u) = C(3, 2)u2 (1 - u)3 – 2 = [3!/2!(3 – 2)!]u2 (1 – u) = [3!/2!(1!)] u2 (1 – u) = [3 * 2 * 1/2 * 1 *(1)] * u2 (1 – u) = 3u2 (1 – u) BEZ3, 3(u) = C(3, 2)u3 (1 - u)3 – 3 = [3!/3!(3 – 3)!]u3 (1 – u )0 = [3!/3!(0!)] u3 (1 – u) 0 = [3 * 2 * 1/3 * 2 * 1 * 1] * u3 * 1 = u3 . P(u) = Σ Pk BEZk, n(u), 0 ≤ u ≤ 1 => P(u) = Σ Pk BEZk, 3(u), 0 ≤ u ≤ 1 n k = 0 3 k = 0
  • 230. 229 Hence, P(u) = P0(1 – u)3 + P13u(1 – u)2 + P23u2 (1 – u) + P3u3 . The form of the blending functions determines how the control points influence the shape of the curve for the values of parameter ꞌtꞌ over the range 0 to 1. i. At t = 0, the only non-zero blending function is BEZ3, 0 which has the value 1. ii. The cubic Bezier curve will always pass through the points P0 and P3. iii. The other functions BEZ3, 1 and BEZ3, 2 influence the shape of curve which passes through the intermediate point P1 and P2. We can write the cubic Bezier point function in matrix form as follows: BEZ3, 0(u) = (1 – u)3 = -u3 + 3u2 – 3u + 1 BEZ3, 1(u) = 3u(1 – u)2 = 3u(1 + u2 – 2u) = 3u3 - 6u2 + 3u + 0 BEZ3, 2(u) = 3u2 (1 – u) = -3u3 + 3u2 + 0u + 0 BEZ3, 3(u) = u3 = u3 + 0u2 + 0u + 0 P0 P1 P2 P3 u3 u2 u 1P(u) = MBEZ So, MBEZ = -1 3 -3 1 3 -6 3 0 -3 3 0 0 1 0 0 0 --- (3)
  • 231. 230 Example 2: Derive all the blending functions for a Bezier Curve with 6 control points. Given, n = 6 – 1 = 5, order = 6. Blending function is given as: BEZn, k(u) = C(n, k)uk (1 – u)n – k => BEZ5, 0(u) = C(5, 0)u0 (1 – u)5 – 0 = [5!/0!(5 – 0)!]u0 (1 – u)5 = (1 – u)5 (since, C(n, k) = n!/k!(n – k)!) => BEZ5, 1(u) = C(5, 1)u1 (1 – u)5 – 1 = [5!/1!(5 – 1)!]u1 (1 – u)4 = [5!/1!(4)!]u1 (1 – u)4 = 5u(1 – u)4 => BEZ5, 2(u) = C(5, 2)u2 (1 – u)5 – 2 = [5!/2!(5 – 2)!]u2 (1 – u)3 = [5!/2!(3)!]u2 (1 – u)3 = 10u2 (1 – u)3 => BEZ5, 3(u) = C(5, 3)u3 (1 – u)5 – 3 = [5!/3!(5 – 3)!]u3 (1 – u)2 = [5!/3!(2)!]u3 (1 – u)2 = 10u3 (1 – u)2 => BEZ5, 4(u) = C(5, 4)u4 (1 – u)5 – 4 = [5!/4!(5 – 4)!]u4 (1 – u) = [5!/4!(1)!]u4 (1 – u)1 = 5u4 (1 – u) => BEZ5, 5(u) = C(5, 5)u5 (1 – u)5 – 5 = [5!/5!(5 – 5)!]u5 (1 – u)0 = [5!/5!(0)!]u5 (1 – u)0 = u5
  • 232. 231 Example 3: Given a Bezier Curve with 4 control points P0[1 0], P1[3 3], P2[6 3] and P4[8 1]. Determine the points lying on the curve for u = 0, 0.2, 0.4, 0.5, 0.7 and 1 and also draw the rough sketch of the curve. P(u) = P0(1 – u)3 + P1(3u(1 – u)2 ) + P2(3u2 (1 – u)) + P3u3 = [1 0](1 – u)3 + [3 3](3u(1 – u)2 ) + [6 3](3u2 (1 – u)) + [8 1]u3 . In order to determine any 6 points lying on the curve, any 6 values of ‘u’ have to be assumed. It has to be in the range 0 ≤ u ≤ 1 and u = 0, 0.2, 0.4, 0.5, 0.7 and 1. P(0) = P0(1 – 0)3 + P1(3(0)(1 – 0)2 ) + P2(3(0)2 (1 – 0)) + P3(0)3 => P0 = [1 0]. P(0.2) = P0(1 – 0.2)3 + P1(3(0.2)(1 – 0.2)2 ) + P2(3(0.2)2 (1 – 0.2)) + P3(0.2)3 = [1 0](0.8)3 + [3 3]( 0.384) + [6 3] (0.096) + [8 1](0.008) = [1 0](0.512) + [3 3]( 0.384) + [6 3] (0.096) + [8 1](0.008) = [0.512 0] + [1.512 1.512] + [0.576 0.288] + [0.064 0.008] = [2.304 1.448] P(0.4) = P0(1 – 0.4)3 + P1(3(0.4)(0.6)2 ) + P2(3(0.4)2 (0.6)) + P3(0.4)3 = [1 0](0.216) + [3 3]( 0.432) + [6 3] (0.288) + [8 1](0.064) = [0.216 0] + [1.296 1.296] + [1.728 0.864] + [0.512 0.064] = [3.752 2.224] P(0.5) = P0(1 – 0.5)3 + P1(3(0.5)(0.5)2 ) + P2(3(0.5)2 (0.5)) + P3(0.5)3 = [1 0](0.125) + [3 3]( 0.375) + [6 3] (0.375) + [8 1](0.125) = [0.125 0] + [1.125 1.125] + [2.25 1.125] + [1 0.125] = [4.5 2.375]
  • 233. 232 P(0.7) = P0(1 – 0.7)3 + P1(3(0.7)(0.3)2 ) + P2(3(0.7)2 (0.3)) + P3(0.3)3 = [1 0](0.027) + [3 3]( 0.189) + [6 3] (0.441) + [8 1](0.343) = [0.027 0] + [0.567 0.567] + [2.646 1.323] + [2.744 0.343] = [5.984 2.233] P(1) = P0(1 – 1)3 + P1(3(1)(1 - 1)2 ) + P2(3(1)2 (1 - 1)) + P3(1)3 => P3 = [8 1]
  • 234. 233 CHAPTER – 11 BASIC ILLUMINATION MODELS: For calculating light intensities, simplified methods are used. The empirical models described in this section provide simple and fast methods for calculating surface intensity at a given point and they produce reasonably good result for most scenes. Lighting calculations are based on the optical properties of surfaces, the background lighting conditions and the light source specifications. Optical parameters are used to set surface properties, such as glossy, matte, opaque and transparent. This controls the amount of reflection and absorption of incident light. All light sources are considered to be point sources, specified with a co-ordinate position and an intensity value (color). 1. AMBIENT LIGHT: A surface that is not exposed directly to a light source still will be visible if nearby objects are illuminated. In our basic illumination model, we can set a general level of brightness for a scene. This is a simple way to model the combination of light reflections from various surfaces to produce a uniform illumination called the ambient light or background light. Ambient light has no spatial or directional characteristics. The amount of ambient light incident on each object is a constant for all surfaces and over all directions.
  • 235. 234 We can set the level for the ambient light in a scene with parameter ‘Ia’ and each surface is then illuminated with this constant value. The resulting reflected light is a constant for each surface, independent of the viewing direction and the spatial orientation of the surface. 2. DIFFUSE REFELCTION: Ambient light reflection is an approximation of global diffuse lighting effects. Diffuse Reflections are constant over each surface in a scene independent of the viewing direction. The ratio of light reflected from the surface to the total incoming light is called the coefficient reflection or reflexivity. Reflexivity of white surfaces is near 1 and that back surface near 0. We can model the diffuse reflections of illumination from a point source in a similar way. That is: we assume that the diffuse reflections from the surface are scattered with equal intensity in all directions, independent of the viewing direction. Such surfaces are sometimes referred to as ideal diffuse reflectors. They are also called Lambertian Reflectors, since radiated light energy from any point on the surface is governed by Lambert’s cosine law. This law states that the radiant energy from any small surface area ‘dA’ in any direction ‘ΦN’ relative to the surface normal is proportional to cosΦN. The light intensity though depends on the radiant energy per projected area perpendicular to direction ‘ΦN’ which is dAcosΦN. So, for Lambertian Reflection the intensity of light is the same over all viewing directions.
  • 236. 235 If ‘IL’ is the intensity of the point light source, then the diffuse reflection equation for a point on the surface can be written as: IL, diff = KdILcosθ --- (1) If ‘N’ is the unit normal vector to a surface and ‘L’ is the unit direction vector to the point light source from a position on the surface, then cosθ = N.L and the diffuse reflection equation for single-point source illumination is: IL, diff = KdIL (N.L) --- (2) The total diffuse reflection equation, using parameter ‘Ka’ is: Idiff = KaIa + KdIL (N.L) --- (3) Here both ‘Ka’ and ‘Kd’ depend on surface material properties and are assigned values in the range from 0 to 1. 3. SPECULAR REFLECTION: Specular Reflection occurs at the surface of a mirror. The light is reflected in nearly single direction plastics and many metals have a specular reflection, which is independent of colors, as all colors are equally reflected. For specular reflection, light comes in strikes the surface and bounces right back off. The angle that the reflection beam makes with the surface normal is called the angle of reflection 0 and equal in magnitude to the angle of incidence. Radiant Energy Direction dA ΦN ΦN N
  • 237. 236 4. PHONG ILLUMINATION MODEL: The Phong illumination model is also known as Phong Model. It is used to set the intensity of specular reflection proportional to cosn sΦ. Angle ‘Φ’ can be assigned values in the range 0o to 90o , so that ‘– cosΦ’ varies from 0 to 1. The value assigned to specular reflection parameter ‘ns’ is determined by the type of surface that the user wants to display. A very shiny surface is modeled with a large value for ‘ns’ (say 100 or more) and smaller values (down to 1) are used for duller surfaces. For perfect reflection ‘ns’ is infinite. For rough surfaces, such as chalk/cinder block, ‘ns’ would be assigned value near to 1. The intensity of specular reflection depends on the material properties of the surfaces and the angle of incidence as well as other factors such as polarization and color of incident light. Users can approximately mode monochromatic specular intensity variations using a specular reflection coefficient w(θ), for each surface. In general w(θ) tends to increase as the angle of incidence increases. At θ = 90o, w(θ) = 1 and the entire incident light is reflected. The variation of specular intensity with angle of incidence is described by Fresnel’s Law of Reflection. Using the spectral reflection function w(θ), user can write the Phong specular reflection model as: Ispec = w(θ)I1cosn sΦ Here, I1 is the intensity of light source and Φ is the viewing angle relative to the specular reflection direction ‘R’.
  • 238. 237 5. COMBINED DIFFUSE AND SPECULAR REFLECTION WITH MULTIPLE LIGHT SOURCES: For a single point light source, we can model the combined diffuse and specular reflection form paint on an illuminated surface as: I = Idiff + Ispec = KaIa + KdIL(N.L) + KsIL(N.H)ns --- (1) If we place more than one point source in a scene, we obtain the light reflection at any surface point by summing the contributions from the individual sources: 6. WARN MODEL: The Warn Model provides a method for simulating studio lighting effects by controlling light intensity in different directions. Light sources are modeled as points on a reflecting surface, using the Phong model for the surface points. Then the intensity in different directions is controlled by selecting values for the Phong exponent. In addition, light controls such as “barn doors” and spot lighting used by studio photographers can be simulated in the Warn Models. Flaps are used to control the amount of light emitted by a surface in various directions. Two flaps are provided for each of the x, y and z directions. Spotlights are used to control the amount of light emitted within a cone with apex at a point source position. I = KaIa + Σ ILi[Kd(N.Li) + Ks(N.Hi)ns --- (2) n i = 1
  • 239. 238 7. INTENSITY ATTENUATION: As radiant energy from a point light source travels through space, its amplitude is attenuated by the factor 1/d2 , where ꞌdꞌ is the distance that the light has travelled. Our simple point source illumination model however does not always produce realistic pictures, if we use the factor 1/d2 to attenuate intensities. The factor 1/d2 produces too much intensity variations, when ꞌdꞌ is small and it produces very little variation when ꞌdꞌ is large. Graphics packages have compensated for these problems by using inverse linear or quadratic functions of ꞌdꞌ to attenuate intensities. E.g.: a general inverse quadratic attenuation function can be set up as: f(d) = 1/a0 + a1d + a2d2 --- (1) A user can fiddle with the coefficients a0, a1 and a2 to obtain a variety of lighting effects for a scene. The value of the constant term ‘a0’ can be adjusted to prevent f(d) from beginning too large when ꞌdꞌ is very small. With a given set of attenuation coefficients, we can limit the magnitude of the attenuation function to 1 with the calculation: f(d) = min(1, 1/a0 + a1d + a2d2 ) --- (2) Using this function, we can then write our basic illumination model as: di = distance light travelled from light source ‘i’. I = KaIa + Σ f(di)ILi[Kd(N.Li) + Ks(N.Hi)ns --- (2) n i = 1
  • 240. 239 8. COLOR CONSIDERATION: Most graphics displays of realistic scenes are in color. One way to set surface colors is by specifying the reflectivity coefficients as 3-element vectors. The diffuse reflection coefficient vector would have RGB components (KdR, KdG, KdB). If we want an object to have a blue surface, we select a non-zero value in the range from 0 to 1, for the blue reflectivity component, KdB, while the red and green reflectivity components are set to zero (KdR = KdG = 0). Any non-zero red or green components in the incident light are absorbed, and only the blue component is reflected. The intensity calculation for this example reduces to the single expression: Another method for setting surface color is to specify the components of diffuse and specular color vectors for each surface, while retaining the reflectivity coefficients as single-valued constants. For an RGB color representation, for instance, the components of these two surface-color vectors can be denoted as: (SdR, SdG, SdB) and (SSR, SSG, SSB). The blue component of the reflected light is then calculated as: This approach provides somewhat greater flexibility, since surface-color parameters can be set independently from reflectivity values. IB = KaBIaB + Σ fi(d)ILBi[KdB(N.Li) + KsB(N.Hi)ns --- (1) n i = 1 IB = KdSdIaB + Σ fi(d)ILBi[KdSdB(N.Li) + KsSs'B(N.Hi)ns --- (2) n i = 1
  • 241. 240 We can simply represent any component of a color specification with its spectral wavelength ‘λ’. Intensity calculations can then be expressed as: 9. TRANSPARENCY: A transparent surface produces both reflected and transmitted light. The relative contribution of the transmitted light depends on the degree of transparency of the surface and whether any light sources or illuminated surfaces are behind the transparent surface. When a transparent surface is to be modeled, the intensity equations must be modified to include contributions from light passing through the surface. Realistic transparency effects are modeled by considering light refraction. When light is incident upon a transparent surface, part of it is reflected and part is refracted. Because the speed of light is different in different materials, the path of the refracted light is different from that of incident light. The direction of the refracted light specified by the angle of refraction is a function of the index of refraction of each material and the direction of the incident light. Intensity light Transparent object Light Emission from a transparent surface is in general a combination of reflected and transmitted light. Iλ = KdSdλIaλ + Σ fi(d)ILλi[KdSdλ(N.Li) + KsSsλ(N.Hi)ns --- (3) n i = 1
  • 242. 241 Angle of refraction ‘θr’ is calculated from the angle of incidence ‘θi’, the index of refraction ‘ηi’ of the incidence material and the index of refraction ‘ηr’ of the refracting material according to Snell’s law: sinθr = (ηi/ηr) sinθi --- (1) From Snell’s law, we can obtain the unit transmission vector ‘T’, in refraction direction ‘θr’ as: T = ηi/ηr (cosθi - cosθr) N – ηi/ηr L --- (2) Here, N = unit surface normal, L = unit vector in the direction of light source and T = transmission vector can be used to locate intersections of the refraction path with objects behind the transparent surface. We can combine the transmitted intensity ‘Itrans’ through a surface form a background object, with the reflected intensity ‘Irefl’ from the transparent surface using transparency coefficient ‘Kt’. We assign the parameter ‘Kt’, a value between 0 and 1; specify how much of the background light is to be transmitted. Total surface intensity is then calculated as: I = (1 – Kt) Irefl + Kt Itrans --- (3) The term (1 – Kt) is the opacity factor. 10. SHADOWS: Hidden surface methods can be used to locate areas where light sources produce shadows. By applying a hidden-surface method with a light source
  • 243. 242 at the view position, we can determine which surface sections can’t be “seen” from the light source. These are the shadow areas. Shadow patterns generated by a hidden-surface method are valid for any selected viewing position, as long as the light source positions are not changed. HALFTONING TECHNIQUES: Halftoning is a process of breaking up an area of gray into lots of individual black dots. It is well established function of printing which uses regularly spaced patterns of small dots. The intensity of dot varies at different levels according to the picture information. These dots vary in size for the representation of the intensities where image is light, the dots are small and where the image is dark, the dots are large. For better resolution, a single cell is divided into sub-cells constructing patterns of threshold values called a dither matrix does it. By the above method, a single dot is capable of representing 5 intensity levels with better resolution. By this technique pixel can have one of 256 possible intensity values. [Division of single cell into sub-cells] [2 x 2 Dither Pattern Representing 5 levels of intensity]
  • 244. 243 HALFTONE APPROXIMATIONS: In computer graphics, halftone reproductions are approximated using rectangular pixel regions, called halftone patterns/pixel patterns. The number of intensity levels that we can display with this method depends on how many pixels we include in the rectangular grids and how many levels a system can display with ‘n’ by ‘n’ pixels for each grid on a bi-level system, we can represent n2 + 1 intensity levels. It shows one way to set up pixel patterns to represent five intensity levels that could be used with a bi-level system. In pattern 0, all pixels are turned off. In pattern 1, one pixel is turned on and in pattern 4, all pixels are turned on and an intensity value ‘I’, in a scene is mapped to a particular pattern according to the range listed below. Pattern 0 is used for 0 ≤ I < 0.2. Pattern 1 is used for 0.2 ≤ I < 0.4 and Pattern 4 is used for 0.8 ≤ I < 1.0. Similarly, 3 by 3 pixels grids on a bi- level system, we can display 10 intensity levels. 0 0 ≤ I < 0.2 1 0.2 ≤ I < 0.4 2 0.4 ≤ I < 0.6 3 0.6 ≤ I < 0.8 4 0.8 ≤ I ≤ 1.0 0 0 ≤ I < 0.1 1 0.1 ≤ I < 0.2 2 0.2 ≤ I < 0.3 3 0.3 ≤ I < 0.4 4 0.4 ≤ I < 0.5 5 0.5 ≤ I < 0.6 6 8 0.6 ≤ I < 0.7 0.8 ≤ I < 0.9 9 0.9 ≤ I ≤ 1.0 7 0.7 ≤ I < 0.8
  • 245. 244 For any pixel grid-size, we can represent the pixel patterns for the various possible intensities with a “mask” of pixel position numbers. E.g.: The following mask can be used to generate the nine 3 by 3 grid parameters for intensity levels above 0. To display a particular intensity with level number ‘k’, we turn on each pixel whose position number is less than or equal to ‘k’. Although the use of ‘n’ by ‘n’ pixel patterns increases the number of intensities that can be displayed, they reduce the resolution of displayed picture by a factor of 1/n along each of the ‘x’ and ‘y’ axes. Halftone approximations also can be used to increase the number of intensity options on systems that are capable of displaying more than 2 intensities per pixel. DITHERING TECHNIQUES: The term ‘Dithering’ is used in various contexts. It refers to techniques for approximating halftones without reducing resolution, as pixel-grid patterns, do. But the term is also applied to halftone approximation methods using pixel grids and sometimes it is used to refer to color halftone approximations only. Random values added to pixel intensities to break up contours are often referred to as dither noise. Ordered-dither methods generate intensity variations with a one- to-one mapping of points in a scene to the display pixels. To obtain, n2 intensity levels, we set up an ‘n’ by ‘n’ dither matrix ‘Dn’, whose elements are distinct positive integers in the range 0 to n2 - 1. 8 3 5 1 7 2 4 9 6
  • 246. 245 E.g.: we can generate ‘4’ intensity levels and ‘9’ intensity levels with following matrix: For a bi-level system, we then determine display intensity values by comparing input intensities to the matrix elements. Each input intensity is first scaled to the range 0 ≤ I ≤ n2 . If the intensity ‘I’ is to be applied to screen position (x, y), we calculate row and column numbers for the dither matrix as: i = (x mod n) + 1, j = ( y mod n) + 1 if I > Dn(i, j), we turn on the pixel at position (x, y) otherwise the pixel is not turned on. Typically, the number of intensity levels is taken to be a multiple of 2 higher- order dither matrices are then obtained from lower-order matrices with the recurrence relation: Assuming n ≥ 4, parameter un/2 is the unity matrix. E.g.: if ‘D2’ is specified in equation – (1), then recurrence relation yields: 4Dn/2 + D2(1, 1)un/2 4Dn/2 + D2(2, 1)un/2 4Dn/2 + D2(1, 2)un/2 4Dn/2 + D2(2, 2)un/2 --- (3) 7 2 4 0 6 1 3 8 5 D3 = --- (2) 3 1 0 2 D2 = --- (1) 15 7 3 11 13 1 12 4 14 D3 = 5 9 6 0 8 2 10
  • 247. 246 Another method for mapping a picture with ‘m’ by ‘n’ points to display area with ‘m’ by ‘n’ pixels is error diffusion. Here, the error between an input intensity value and the displayed pixel intensity level at a given position is dispersed or diffused to pixel positions to the right and below the current pixel position. POLYGON RENDERING METHODS/SHADING MODELS FOR POLYGONS: We can shade any surface by calculating the surface normal at each visible point and applying the desired illumination pattern at that point. But this is expensive, so we would consider more efficient shading models for surfaces defined by polygons. 1. CONSTANT INTENSITY SHADING: It is the simplest shading model for a polygon and is also known as flat shading. This approach applies to single intensity value that is then used to shade an entire polygon. This approach is valid if several assumptions are true. i. The light source is at infinity. So it is constant across the polygon face. ii. The viewer is at infinity. So it is constant across the polygon face. iii. The polygon represents the actual surface being modeled and is not an approximation to a curved surface. Even if all these assumptions are not true, we can still reasonably approximate the surface lighting effects using small polygon faults with flat shading and calculate the intensity for each fact, say at the center of polygon.
  • 248. 247 2. POLYGON MESH SHADING: Many objects are curved, rather than polyhedral, yet representing them as a polygon mesh allows the use of efficient polygon visible surface algorithms. If each polygonal face is in the mesh is shaded individually, it is easily distinguished from its neighbors whose orientation is different, producing a “faceted” appearance. This is true if the polygons are rendered using constant shading, interpolated shading or even per-pixel illumination calculations, because two adjacent polygons of different orientation have different intensities along their borders. At the border between facets, the dark facet looks darker and the light facet looks lighter. Macsh banding is caused by later inhibition of the receptors in the eye. The more light a receptor received the more that receptor inhibits the response of the receptors adjacent to it. The response of the receptor to light is inhibited by its adjacent receptors in inverse relation to the distance to the adjacent receptor. Two basic models for polygon meshes take advantage of the information provided by adjacent to simulate a smooth surface. That is: a) Gouraud Shading and b) Phong Shading. a. GOURAUD SHADING: It is also called as intensity interpolation shading or color interpolation shading. It eliminates intensity discontinues. It extends the concept of interpolated shading applied to individual polygons by interpolating polygon vertex illuminated values that take into account the surface being approximated.
  • 249. 248 This process requires that the normal be known for each vertex of the polygonal mesh. Alternatively, if the vertex normal are not stored with the mesh and can’t be determined directly from the actual surface, the Gouraud suggested. We can approximate them by averaging the surface normal of all polygonal facets sharing each vertex. Normalized polygon surface normal can be averaged to obtain vertex normal. i. If an edge is meant to be visible, then we find 2 vertex normals, one for each side of the edge, by averaging the normals of polygon on each side of the edge separately. ii. The next step in Gouraud shading is to find vertex intensities by using vertex normals with any desired illumination model. iii. Finally, each polygon is shaded by linear interpolation of vertex intensities along each edge and then between edges along each scan-line. The term Gouraud Shading is often generalized to refer to intensity interpolation shading of even a single polygon, in isolation or to the interpolation of arbitrary colors, associated with polygon vertices. The interpolation along edges can easily be integrated with the scan-line visible surface algorithm. With each color component, the starting intensity and the N1 N2 N3 N4 The normal vector is calculated as the Average of the surface Normals for each polygon sharing that vertex.
  • 250. 249 change of intensity for each unit change is ‘y’. A visible span on a scan–line is filled in by interpolation the intensity values of the two edges bounding the span. b. PHONG SHADING: It is also known as normal-vector interpolating shading, which interpolates the surface normal vector ‘N’, rather than the intensity. Interpolation occurs across a polygon span on a scan-line, between starting and ending normals for the span. These normals are themselves interpolated along polygon edges from vertex normals that are completed, if necessary just as in Gouraud shading. The interpolation along edges can again be done by means of incremental calculations, with all three components of the normal vector being incremented for scan-line to scan-line. At each pixel along a scan-line, the interpolated normal is normalized and is back mapped into the world co-ordinates system or one isometric to it and a new intensity calculation is performed using any illumination model. Normal vector is calculated as: [Incremental Interpolation of Intensity values along a polygon edge] La = L1 – (L1 – L2) [y1 – y3/y1 – y2] Scan-line Y2 Y1 Y3 LbLpLa L3L2 L1 Lb = L1 – (L2 – L3) [y1 – y3/y1 – y3] Lp = Lb – (Lb – La) [yb – yp/yb – ya] Nv = ΣNk/|ΣNk|, (normal unit vector) k = 1 n k = 1 n
  • 251. 250 N = (y – y2/y1– y2)N1 + (y1 – y/y1 – y2)N2 --- (1) It shows two edge normals and the normals interpolated from them, before and after normalization. Phong shading yields substantial improvements over Gouraud shading when such illumination models are used, because highlights are reproduced more faithfully. Phong Shading also requires highlights to be located in a polygon’s interior whereas Gouraud Shading may miss it entirely. Even with an illumination model that does not take into account specular reflection, the results of normal vector interpolation are in general superior to intensity interpolation, because an approximation to the normal is used at each point. A polygon surface is rendered using Phong shading by the following steps: i. Determine the average unit normal vector at each polygon vertex. ii. Linearly interpolate the vertex normals over the surface of the polygon. iii. Apply an illumination model along each scan-line to calculate projected pixel intensities for the surface points. ANIMATION: It is a technique of building progressive images and running it in a sequence to create an effect of motion. In animation, for a moving sequence, different Pa P2 P1P0 [Normal Vector Implementation] 10 N~ Pb N~ N~ N~ N~
  • 252. 251 stationary images are drawn and each of them shows some advancement of motion form the previous one. These images are called frames. These progressively build frames are rapidly moved in front of human eye and this is perceived as the motion TV/Video plays 30 frames every second. It is the speed with which each frame is replaced by the next one that makes the image appear to blend smoothly into movement. ANIMATION TECHNIQUES: 1. CEL ANIMATION: This is the animation technique which uses a series of different graphics on each frame of a movie film. The term ‘cel’ is derived from the clear celluloid sheets that were used for drawing each frame. Cel Animation artwork begins with key frames i.e.: the 1st and last frame of an action. E.g.: When an animated figure of a child walks across the screen, he balances the weight of his entire body on one foot and then other in a series of falls and recoveries, with opposite foot and leg catching upto balance the body. Thus, the 1st key frame to portray a single step might be child pitching his body weight forward off the left foot leg, while his center of gravity shifts forward; the feet close together and the appears to be falling. The last key frame might be the right foot and leg catching the body’s fall, with the center of gravity now centered, between the outstretched stride and the left and right feet positioned for apart.
  • 253. 252 The series of frames in between the key-frames are drawn in a process called Tweening. Tweening is the process of calculating the number of frames between key-frame and the patch the action takes and then actually sketching into a cel with pencil the series of progressively different outlines. As tweening advances, the action sequence is checked by flipping through the frames. The penciled frames are brought together and then actually filmed as a pencil test to check smoothness, continuity and timing. When the pencil frames are satisfactory they are permanently inked and acrylic colors are painted on the same. 2. COMPUTER ANIMATION: Computer Animation programs implement the same logic and concept as cel animation, using layer key-frame and tweening techniques. The developer can set his own frame rates on the computer but it will depend on the speed and power of display platform and hardware. MORPHING: It is an effect in which one image changes into another. Morphing applications and modeling tools offering the morphing effect can transition not only between still images but often between moving images as well. Morphing is applied as follows: i. First of all, 2 images are supplied to the morphing application ii. The morphing application selects key points on both the images. Setting of key points is crucial for smooth transition between two images.
  • 254. 253 iii. Transformations are applied on the key points of first image to change it to the corresponding key point of second image. Morphed images are built at a rate of 8 frames per second, with each transition taking a total of 4 seconds and the numbers of key points are held to a minimum to shorten the rendering time. Some product offering morphing features are: i. Avoid’s Elastic Reality ii. Gryphon Software’s morph. iii. Image Ware’s Morph Wizard iv. North Coast’s photo-morph. v. Black Belt’s Win Images. vi. Human Software’s squizz. vii. Meta Tool’s Digital Morph. INTRODUCTION TO HIERARCHICAL MODELING WITH STRUCTURES: A hierarchical model of a system can be created with structures by nesting the structures into one another to form a tree organization. Each structure is placed into the hierarchy properly into the overall model. The various graphical symbols to be used in an application are each defined in an independent co-ordinate reference called the modeling co-ordinate system. Modeling co-ordinates are also referred to as local co-ordinates or master co- ordinates.
  • 255. 254 Transformations applied to the modeling co-ordinate definitions of symbols are referred to as modeling transformations, which involve translation, rotation and scaling to position a symbol in world co-ordinates, but other transformations might also be used in some applications. The modeling package co-ordinates individually do transformations to construct a homogeneous co-ordinate modeling transformation matrix ‘MT’. An instance of a symbol in world co-ordinates is then produced by applying MT’ to modeling co- ordinate positions (Pmc) to generate corresponding world co-ordinate positions (Pwc). That is: Pwc = MT . Pmc DISPLAYING LIGHT INTENSITIES: Values of intensity calculated by illumination model must be converted to one of the allowable intensity levels for the particular graphics system in use. Some systems are capable of displaying several intensity levels while others are capable of only two levels for each pixel (on or off). In 1st case, we convert intensities from the lighting model into one of the available levels for storage in the frame buffer. For bi-level systems, we can convert intensities into halftone patterns. ASSIGNING INTENSITY LEVELS: If the ratio of two intensities is the same as the ratio of two other intensities, we perceive the difference between each pair of intensities to be the same. E.g.: We perceive the difference between intensities 0.20 and 0.22 to be the same as the difference between 0.80 and 0.88. So, to display n + 1 successive
  • 256. 255 intensity levels with equal perceived brightness, the intensity levels in the monitor should be spaced so that the ratio of successive intensities is constant: I1/I0 = I2/I1 = … = In/In – 1 = r --- (1) Here, we denote the lowest level that can be displayed on the monitor as ‘I0’ and the highest as ‘In’. Any intermediate intensity can then be expressed in terms of I0 as: IK = rK I0 --- (2) We can calculate the value of ‘r’ given the values of ‘I0’ and ‘n’ for a particular system by substituting K = n in the proceeding expression. Since In = 1, we have: r = (1/I0)1/n --- (3) So, the calculation for ‘IK’ can be rewritten as: IK = I0(n – K)/n --- (4) E.g.: if I0 = 1/8 for a system with n = 3, we have r = 2 and the 4 intensity values are 1/8, 1/4, 1/2 and 1. With a color system, we set up intensity levels for each component of the color model. Using the RGB model, we can related the blue component of intensity at level ‘K’ to the lowest attainable blue value, as equation – (2). So, IB = rB K IBO --- (5), where rB = (1/IBO)1/n --- (6)
  • 257. 256 GAMMA CORRECTION AND VIDEO LOOKUP TABLES: Another problem associated with the display of calculated intensities is the non- linearity of display device. A video monitor is a non-linear device. If we set the voltages for the electron gun proportional to the linear pixel values, the displayed intensities will be shifted according to the monitor response curve. To correct for monitor, non-linearity, graphics systems use a video looking table that adjusts the linear pixel values. The monitor response curve is described by the exponential function: I = aVγ --- (7) Here, I = displayed intensity, V = input voltage. ꞌaꞌ, ꞌγꞌ depend on the characteristics of the monitor used in graphics system. If we want to display a particular intensity value ‘I’, the correct voltage value to produce this intensity is: V = (I/a)1/γ --- (8) This calculation referred to as Gamma correction of intensity. Monitor gamma values are typically between 2.0 and 3.0. The National Television System Committee (NTSC) signal standard is γ = 2.2. 1.0 [Normalized electron gun voltage] 1.00.5 Intensity 0.5
  • 258. 257 We can combine gamma correction with logarithmic intensity mapping to produce a lookup table that contains both conversions. If ‘I’ is an input intensity value from an illumination model. We first locate the nearest intensity ‘IK’ from a table of values created with equation - (1) or equation - (4). Alternatively we could determine the level number for this intensity value with the calculation: K = round[logr(I/I0)] --- (9) Then we compute the intensity value at this level using equation – (4). Once we have the intensity value ‘IK’, we can calculate the electron-gun voltage: VK = (IK/a)Vγ --- (10) Values ‘VK’ can then be placed in the lookup tables and values for ‘K’ would be stored in the frame buffer pixel positions. If a particular system has no lookup table, computed values for ‘VK’ can be stored directly in the frame buffer. The combined conversion to a logarithmic intensity scale followed by calculation of the ‘VK’ using equation – (10) is also sometimes referred to as Gamma correction. 1.0 Norma lized electro n gun voltag e 1.00.5 0 0.5 γ = 2.2
  • 259. 258 DISPLAYING CONTINUOUS – TONE IMAGES: High quality computer graphics systems generally provide 256 – intensity levels for each color component, but acceptable displays can be obtained for many applications with fewer levels. A 4-level system provides minimum shading capability for continuous – tone images, while photo realistic images can be generated on system that are capable of from 32 to 256 intensity levels per pixel. When a small number of intensity levels are used to reproduce a continuous – tone image, the borders between the different intensity regions called counters are clearly visible. Using four intensity levels, we begin to identify the original shading patterns, but the contouring effects are glaring. With 8 intensity levels, contouring effects are still obvious, but we begin to have a better indication of the original shading.