Im - SC CG
Im - SC CG
Unit I
Introduction
Computer-aided design – Graphics, charts and models – computer art – computer Animation–
Graphical user interfaces – Graphics for home use – Image Processing – Display Devices –
Interactive Input devices – Display processors – Graphic software – output primitives –
Points and lines – Line drawing algorithms – Circle Generation algorithms – Character
Generation – Instruction set for display processor.
Unit II
Line Styles – Color and Intensity – Area filling – Character Attributes – Bundled Attributes –
Two Dimensional Transformation – Basic Transformations – Matrix Representation and
homogeneous co-ordinates – composite transformations – other transformations –
Transformation commands, raster methods for transformations.
Unit III
Unit IV
1
Unit V
Text Book
1. Donald Hearn, M. Pauline Baker, Computer Graphics , 2nd Edition McGraw Hill 1995
Reference Books
♣♣♣♣♣♣♣♣♣♣
2
UNIT1
COMPUTER GRAPHICS
1.1 INTRODUCTION
Computers have become a powerful tool for the rapid and economical production of pictures. There
is virtually no area in which graphical displays cannot be used to some advantage, and so it is not
surprising to find the use of computer graphics so widespread. Although early applications in
engineering and science had to rely on expensive and cumbersome equipment, advances in
computer technology have made interactive computer graphics a practical tool. Today, we find
computer graphics used routinely in such diverse areas as science, engineering, medicine, business,
industry, government, art, entertainment, advertising, education, and training.
CAD is the intersection of Computer Graphics, Geometric modelling and Design tools
(Fig.1.4.). The concepts of computer graphics and geometric modelling and must be used
innovatively to serve the design process.
CAD is the function of computer systems to support in the creation, modification, analysis, or
optimization of a design.
CAD software for design uses either vector-based graphics to explain the objects of
traditional drafting, or may also develop raster graphics showing the overall look of designed
objects. During the manual drafting of engineering drawings, the output of CAD must convey
information, like dimensions, materials, processes, and tolerances.
CAD is a significant industrial art used in many purposes, including industrial and
architectural design, shipbuilding, automotive, and aerospace industries, and many more.
CAD is also extensively used to create computer animation for special effects in movies, and
technical manuals, frequently called as Digital Content Creation.
CAD software packages provide the designer with a multi window environment with
animation which is regularly used in Digital Content Creation. The animations using wire
frame modeling helps the designer to see into the interior of object and to observe the
behaviors of the inner components of the assembly during the motion.
3
CAD Technology
Initially software for CAD systems was developed with computer languages
suchas FORTRAN but with the development of object-oriented programming methods this
has completely changed. Classic modern parametric attribute based modeller and freeform
surface systems are developing around a number of key ‘C’modules.
A CAD system can be seen as develop from the interaction of a Graphical User
Interface (GUI) with NURBS geometry and Boundary representation data through a kernel
for geometric modeling. A geometry constraint engine may also be employed to organize the
associative relationships betweencomponents in an assembly.
Unexpected facilities of these relationships have led to a new form
of prototyping called digital prototyping. In difference to physical prototypes, which
involve manufacturing time in the design. CAD models can be created by a computer after
the physical prototype has been scanned using an CT scanning device. Based on the nature
of the business, digital or physical prototypes can be primarilyselected according to specific
requirements.
Currently, no special hardware is required for CAD software. However, some special
CAD systems can do graphically and computationally intensive tasks, so a higher
end graphics card, high speed CPUs may be suggested. CAD systems exist for all the major
platforms and some packages evenperform multiple platforms.
The human-machine interface is generally through a mouse
but can also be using adigitizing graphics tablet. Handling of the view of the part on the
screen is also sometimes done with the help of a Space mouse or Space Ball. Special CAD
systems also support stereoscopic glasses for viewing the 3D objects.
CAD Tools
The CAD tools are mainly using for graphics applications and modeling. Aids such a color,
grids, geometric modifiers and group facilitate structural geometric models. Visualization is
achieved through shaded components and animation which focus design conceptualization,
communication and interference detection. FEM packages provide optimization in shape and
structure. Adding tolerances, tolerance analysis and investigating the effect of manufacturing
on the design can perform by utilizing CAD tools (Table 1.2).
4
Uses of CAD
CAD is one of the tools used by designers and engineers and is used in different ways
depending on the profession of the customer and the type of software.
CAD is one of the Digital Product Development activities within the Product
Lifecycle Management practices with other tools, which are either integrated modules or
individual, such as:
· Computer Aided engineering (CAE) and Finite Element Analysis (FEA)
· Computer Aided Manufacturing (CAM)
· Realistic Rendering and Simulation.
Product Data Management (PDM).
CAD is also used for the development of photo simulations that are frequently
necessary in the preparation of Environmental Impact Reports, in which proposed CAD
buildings are superimposed into photographs of existing situation to represent what that
conditions will be like, where the proposed services are allowed to be built.
Parameters and constraints can be used to get the size, shape, and other properties of
the modeling elements. The features of the CAD system can be used for the several tools for
measurement such as yield strength, tensile strength and electrical or electro-magnetic
properties.
5
1.3 PRESENTATION GRAPHICS
Another major application is presentation graphics, used to produce illustrations for reports or to
generate 35-mm slides or transparencies for use with projectors. Presentation graphics is commonly
used to summarize financial, statistical, mathematical, scientific, and economic data for research
reports, managerial reports, consumer information bulletins, and other types of reports. Workstation
devices and service bureaus exist for converting screen displays into 35-mm slides or overhead
transparencies for use in presentations. Typical examples of presentation graphics are bar charts,
line graphs, surface graphs, pie charts, and other displays showing relationships between multiple
parameter.
1.4COMPUTER ART
Computer graphics methods are widely used in both fine art and commercial art applications.
Artists use a variety of computer methods, including special-purp&e hardware, artist's paintbrush
(such as Lumens), other paint packages (such as Pixelpaint and Superpaint), specially developed
software, symbolic mathematics packages (such as Mathematics), CAD paclpges, desktop
publishing software, and animation packages that provide facileness for designing object shapes and
specifying object motions.
Animation means giving life to any object in computer graphics. It has the power of
injecting energy and emotions into the most seemingly inanimate objects. Computer-assisted
animation and computer-generated animation are two categories of computer animation. It
can be presented via film or video.
The basic idea behind animation is to play back the recorded images at the rates fast enough
to fool the human eye into interpreting them as continuous motion. Animation can make a
series of dead images come alive. Animation can be used in many areas like entertainment,
computer aided-design, scientific visualization, training, education, e-commerce, and
computer art.
Animation Techniques
Animators have invented and used a variety of different animation techniques. Basically
there are six animation technique which we would discuss one by one in this section.
6
Traditional Animation (frame by frame)
Traditionally most of the animation was done by hand. All the frames in an animation had to
be drawn by hand. Since each second of animation requires 24 frames (film), the amount of
efforts required to create even the shortest of movies can be tremendous.
Keyframing
In this technique, a storyboard is laid out and then the artists draw the major frames of the
animation. Major frames are the ones in which prominent changes take place. They are the
key points of animation. Keyframing requires that the animator specifies critical or key
positions for the objects. The computer then automatically fills in the missing frames by
smoothly interpolating between those positions.
Procedural
In a procedural animation, the objects are animated by a procedure − a set of rules − not by
keyframing. The animator specifies rules and initial conditions and runs simulation. Rules
are often based on physical rules of the real world expressed by mathematical equations.
Behavioral
In behavioral animation, an autonomous character determines its own actions, at least to a
certain extent. This gives the character some ability to improvise, and frees the animator
from the need to specify each detail of every character's motion.
This technology has enabled a number of famous athletes to supply the actions for characters
in sports video games. Motion capture is pretty popular with the animators mainly because
some of the commonplace human actions can be captured with relative ease. However, there
can be serious discrepancies between the shapes or dimensions of the subject and the
graphical character and this may lead to problems of exact execution.
7
allow a higher degree of interactivity where the real person can maneuver the actions of the
simulated character.
In contrast the applications based on key-framing and motion select and modify motions
form a pre-computed library of motions. One drawback that simulation suffers from is the
expertise and time required to handcraft the appropriate controls systems.
Key Framing
A keyframe is a frame where we define changes in animation. Every frame is a keyframe
when we create frame by frame animation. When someone creates a 3D animation on a
computer, they usually don’t specify the exact position of any given object on every single
frame. They create keyframes.
Keyframes are important frames during which an object changes its size, direction, shape or
other properties. The computer then figures out all the in-between frames and saves an
extreme amount of time for theanimator. The following illustrations depict the frames
drawn by user and the frames generated by computer.
Morphing
The transformation of object shapes from one form to another form is called morphing. It is
one of the most complicated transformations.
8
A morph looks as if two images melt into each other with a very fluid motion. In technical
terms, two images are distorted and a fade occurs between them.
A graphical user interfaceis fondly called "GUI" pronounced "gooey." The word "graphical"
means pictures; "user" means the person who uses it; "interface" means what you see on the screen
and how you work with it. So a graphical user interface, then, means that you (the user) get to work
with little pictures on the screen to boss the computer around, rather than type in lines of codes and
commands.
9
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 or nongraphical displays. To
make a particular window active, we simply click in that window using an interactive pointing
device.
Interfaces also display menus and icons for fast selection of processing options or parameter values.
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 descriptions
and they can be understood more quickly if well designed.
Menus contain lists of textual descriptions and icons. Figure 1-73 illustrates a typical graphical
interface, containing a window manager, menu displays, and icons. In this example, the menus
allow selection of processing options, color values, and graphics parameters. The icons represent
options for painting, drawing, zooming, typing text strings, and other operations connected with
picture construction.
Although methods used in computer graphics and Image processing overlap, concerned with
fundamentally different operations. In computer graphics, a computer is used to create a picture.
Image processing, on the other hand.applies techniques to modify or interpret existing figures, such
as photographs and TV scans. Two principal applications of image processing are
To apply imageprocessing 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.
These techniques are used extensively in commercial art applications that involve the retouching
and rearranging of sections of photographs and other artwork. Similar methods are used to analyze
satellite photos of the earth and photos of galaxies. Medical applications also make extensive use of
imageprocessing techniques for picture enhancements, in tomography and in simulations of
operations. Tomography is a technique of X-ray photography that allows cross-sectional views of
physiological systems to be displayed. Both computed X-rav tomography (CT) and position
emission tomography (PET) use proper methods to reconstruct cross sections from digital data.
10
These techniques are also used to monitor internal functions and show cross sections during
surgery. imaging techniques include ultrasonics and under medicine scanners. With Image
Pm&ngultrasonics, high-frequency sound waves, instead of X-rays, are used to generate digital
data. Nuclear medicine scanners celled data from radiation emitted from ingested radionuclides and
plot colorcoded images.
● The electron beam passes through focusing and deflection systems that direct it
towards specified positions on the phosphor-coated screen.
● When the beam hits the screen, the phosphor emits a small spot of light at each
position contacted by the electron beam.
● It redraws the picture by directing the electron beam back over the same screen
points quickly.
11
There are two ways (Random scan and Raster scan) by which we can display an object on
the screen.
Raster Scan
In a raster scan system, the electron beam is swept across the screen, one row at a time from
top to bottom. As the electron beam moves across each row, the beam intensity is turned on
and off to create a pattern of illuminated spots.
Picture definition is stored in memory area called the Refresh Buffer or Frame Buffer.
This memory area holds the set of intensity values for all the screen points. Stored intensity
values are then retrieved from the refresh buffer and “painted” on the screen one row (scan
line) at a time as shown in the following illustration.
Each screen point is referred to as a pixel (picture element) or pel. At the end of each scan
line, the electron beam returns to the left side of the screen to begin displaying the next scan
line.
12
set of commands in the display file, drawing each component line in turn. After all the line-
drawing commands are processed, the system cycles back to the first line command in the
list.
Random-scan displays are designed to draw all the component lines of a picture 30 to 60
times each second.
13
● Medical imaging − MRIs, CAT scans, etc. - Non-invasive internal examination.
● Typography − The use of character images in publishing - replacing the hard type of
the past.
Various devices are available for data input on graphics workstations. Most systems have a
keyboard and one or more additional devices specially designed for integrative input. These include
a mouse, trackball, spaceball, joystick, digitizers, dials, and button boxes. Some other input
devicesuses in particular applications data gloves, touch panels, image scanners, and voice systems.
Input Devices Keyboards An alphanumeric keyboard on a graphics system is used primarily as a
device for entering text strings.
keyboard
The keyboardis an efficient device for inputting such nongraphic data as picture labels associated
with a graphics display. Keyboards can also be provided with features to facilitate entry of screen
coordinates, menu selections, or graphics functions. Cursor-control keys and function keys are
common features on generalpurpose keyboards. Function keys allow users to enter frequently used
operations in a single keystroke, and cursor-control keys can be used to select displayed objects or
coordinate positions by positioning the screen cursor. Other types of cursor-positioning devices,
14
such as a trackball or joystick, are included on some keyboards. Additionally, a numeric keypad is
often included on the keyboard for fast entry of numeric data.
Mouse
A mouse is 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 and direction of movement. Another method for
detecting mouse motion is with an opticOverview of Graphics Systemscal sensor. For these
systems, the mouse is moved over a special mouse pad that has a grid of horizontal and vertical
lines. The optical sensor deters movement acrossthe lines in the grid.
As the name implies, a trackball is a ball that can be rotated with the fingers or palm of the hand
While a trackball is a two-dimensional positioning device, a spaceball provides six degrees of
freedom. Unlike the trackball, a spaceball does not actually move. Strain gauges measure the
amount of pressure applied to the spaceball to provide input for spatial positioning and orientation
as the ball is pushed or pulled in various directions. Spaceballs are used for three-dimensional
positioning and selection operations in virtual-reality systems, modelling, animation, CAD, and
other applications.
Joysticks
A joystick consists of a small, vertical lever (called the stick) mounted on a base that is used to
steer the screen cursor around. Most by sticks select screen positions with actual stick movement;
others respond to insure on the stick.
Some joysticks are mounted on a keyboard; others location as stand-alone units. The distance that
the stick is moved in any direction from its centre position corresponds to screen-cursor movement
in that direction. Potentiometers mounted at the base of the joystick measure the amount of
movement, and springs return the stick to the centre position when it is released. One or more
buttons can be programmed to act as input switches to signal certain actions once a screen position
has been selected.
15
Point plotting is accomplished by converting a single coordinate position furnished by an
application program into appropriate operations for [he output device in use. With a CRT monitor,
for example, the electron beam is turned on to illuminate the screen phosphor at the selected
location. How the electron beam is positioned depends on the display technology.
Line drawing is accomplished by calculating intermediate positions along the line path between
two specified endpoint positions. An output device is then directed to fill in these positions between
the endpoints. For analog devices, such as a vector pen plotter or a random-scan display, a straight
line can be drawn smoothly from one endpoint to the other. Linearly varying horizontal and vertical
deflection voltages are generated that are proportional to the required changes in the x and y
directions to produce the smooth line.
• A line connects two points. It is a basic element in graphics. To draw a line, you need
two points between which you can draw a line.
• DDA Algorithm
Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm
a) Step 1 − Get the input of two end points (X0,Y0)(X0,Y0) and (X1,Y1)(X1,Y1).
c) Step 3 − Based on the calculated difference in step-2, you need to identify the number
of steps to put pixel. If dx >dy, then you need more steps in x coordinate; otherwise in
y coordinate.
• The Bresenham algorithm is another incremental scan conversion algorithm. The big
advantage of this algorithm is that, it uses only integer calculations. Moving across
the x axis in unit intervals and at each step choose between two different y
coordinates.
16
• For example, as shown in the following illustration, from position (2, 3) you need to
choose between (3, 3) and (3, 4). You would like the point that is closer to the original
line.
Bresenham’s Algorithm
We cannot display a continuous arc on the raster display. Instead, we have to choose the
nearest pixel position to complete the arc.
17
From the following illustration, you can see that we have put the pixel at (X, Y) location and
now need to decide where to put the next pixel − at N (X+1, Y) or at S (X+1, Y-1).
Algorithm
Step 1 − Get the coordinates of the center of the circle and radius, and store them in x, y,
and R respectively. Set P=0 and Q=R.
18
Mid Point Algorithm
Step 1 − Input radius r and circle center (xc,yc)(xc,yc) and obtain the first point on the
circumference of the circle centered on the origin as
P0 = 5/4 – r
Step 5 − Move each calculate pixel position (X, Y) onto the circular path centered on (Xc,
Yc)and plot the coordinate values.
X = X + XC, Y = Y + YC
Letters, numbers, and other characters can be displayed in a variety of sizes and styles. The overall
design style for a set (or family) of characters is called a type. Mapping an array into a rectangular
19
coordinate region. face. Today, there are hundreds of typefaces available for computer applications.
Examples of a few common typefaces are Courier, Helvetica, New York, Palatino, and Zapf
Chancery. Originally, the term font referred to a set of cast metal character forms in a particular size
and format, such as 10-point Courier Italic or 12- point Palatino Bold.
Now, the terms font and typeface are often used interchangeably, since printing is no longer done
with cast metal forms. Typefaces (or fonts) can be divided into two broad groups: and sans serif.
Serif type has small lines or accents at the ends of the main character strokes, while sans-serif type
does not have accents.
For example, the text in this book is set in a serif font (Palatino). But this sentence is printed in a
sans-serif font (Optima). Serif type is generally more readable; that is, it is easier to read in longer
blocks of text. On the other hand, the individual characters in sans-serif type are easier to recognize.
For this reason, sans-serif type is said to be more legible. Since sans-serif characters can be quickly
recognized, this typeface is good for labelling and short headings. Two different representations are
used for storing computer fonts. A simple method for representing the character shapes in a
particular typeface is to use rectangular grid patterns. The set of characters are then referred to as a
bitmap font (or bitmapped font). Another, more flexible, scheme IS to describe character shapes
using straight-line and curve sections, as in PostScript, for example. In this case, the set of
characters is called an outline fonts.
20
UNIT II
Basic attributes of a straight line segment are its type, its width, and its color. In some graphics packages,
lines can also be displayed using selected pen or brush options. In the following sections, we consider
how line drawing routines can be modified to accommodate various attribute specifications.
Line Type
Possible selections for the line-type attribute include solid lines, dashed lines, and dotted lines. We
modify a linedrawing algorithm to generate such lines by setting the length and spacing of displayed solid
sections along the line path. A dashed line could be displayed by generating an interact spacing that is
equal to the length of the solid sections. Both the length of the dashes and the interdash spacing are often
specified as user options.
Line Width
Implementation of line- width options depends on the abilities of the output device. A heavy line
monitor could be displayed as adjacent parallel while a pen plotter might require pen changes. As with
other PHIGS Unequal-length dashes, a line-width is used to set the current line-width value in the at-
displayed with the attribute list. This value 15 then used by line-drawing algorithms to controls the
number of pixels. Thicknessof lines generated with subsequent output primitive commands We set the
line-width attribute with the command:
Generating thick polylines requires some additional considerations. In general, the methods we have
considered for displaying a single line segment will not produce a smoothly connected series of line
segments. Displaying thick lines using horizontal and vertical pixel spans, for example, leaves pixel gaps
at the boundaries between lines of different slopes where there is a shift from horizontal spans to vertical
spans.
We can generate thick polylines that are smoothly joined at the cost of additional processing at the
segment endpoints.. A monitor 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
21
With some packages, lines can be displayed with pen or brush selections. Op- tions in this category
include shape, size, and pattern. Some possible pen or brush shapes are given in Fig. 4-7. These shapes
can be stored in a pixel mask that identifies the array of pixel positions that are to be set along the line
path. To avoid setting pixels more than once in the frame buffer, we can simply accumulate the
horizontal spans generated at each position of the mask and keep track of the beginning and ending x
positions for the spans across each scan line. Lines generated with pen (or brush) shapes can be
displayed in various widths by changing the size of the mask. Also, lines can be displayed with selected
patterns by superimposing the pattern values onto the pen or brush mask. An additional pattern option
that can be provided in a paint package is the display of simulated brush strokes.
lineColor
When a system provides color (or intensity) options, a parameter giving the cur- rent color index is
included in the list of system-attribute values. 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 setpixel
procedure. The number of color choices depends on the number of bits available per pixel in the frame
buffer. We set the line color value in PHlGS with the function.
Various color and intensity-level options can be made available to a user, depending on the capabilities
and design objectives of a particular system. General- purpose raster-scan systems, for example, usually
provide a wide range of colors, while random-scan monitors typically offer only a few color choices, if
any. Color options are numerically 'coded with values ranging from 0 through the positive integers. For
CRT monitors, these color codes are then converted to intensity- level settings for the electron beams.
With color plotters, the codes could control ink-jet deposits or pen selections.
In a color raster system, the number of color choices available depends on the amount of storage
provided per pixel in the frame buffer Also, color information can be stored in the frame buffer in two
ways: We can store color codes directly in the frame buffer, or we can put the color codes in a separate
table and use pixel values as an index into this table. With the direct storage scheme, when- ever a
particular color code is specified in an application program, the corresponding binary value is placed in
the frame buffer for each-component pixel in the output primitives to be displayed in that color.
Color Tables
A possible scheme for storing color values in a color lookup table (or video lookup table), where
frame-buffer values art- now used as indices into the color table. In this example, each pixel can
22
reference any one of the 256 table positions, and each entry in the table uses 24 bits to spec* an
RGB color. For the color code 2081, a combination green-blue color is displayed for pixel location
(x, y). Systems employing this particular lookup table would allow.
A user can set color-table entries in a PHIGS applications program with the function.
Parameter identifies the workstation output device; parameter speeches the color index, which is
the color-table position number (0 to 255 ); and parameter color points to a hio of RGB color values
(r, g, b) each specified in the range from 0 and 1.
Gray scale
With monitors that have no color capability, colorcan be used in an ap- plication program to set the
shades of gray, or grayscale, for displayed primitives. Numeric values over the range from 0 to 1
can be used to specify grayscale levels, which are then converted to appropriate binary codes for
storage in the raster. This allows the intensity settings to be easily adapted to systems with differing
grayscale capabilities.
In this example, any intensity input value near 0.33 would be stored as the binary value 01 in the
frame buffer, and pixels with this value would be displayed as dark gray. If additional bits per pixel
are available in the frame buffer, the value of 0.33 would be mapped to the nearest level. With 3 bits
per pixel, we can accommodate 8 gray levels; while 8 bits per pixel wbuld give us 256 shades of
gray. An alternative scheme for storing the intensity information is to convert each intensity code
directly to the voltage value that produces this gray- scale level on the output device in use.
Options for filling a defined region include a choice between a solid coloror a patterned fill and
choices for the particular colors and patterns. l3ese fill options can be applied to polygon regions or
to areas defined with curved boundaries, depending on the capabilities of the available package. In
addition, areas can be painted using various brush styles, colors, and transparency parameters.
Fill Styles
Areas are displayed with three basic fill styles: hollow with a color border, filled with a solid color,
or Wed with a specified pattern or design. A basic fill style is selected in a PHIGS program with the
function
Values for the fill-style parameter f s include hollow, solid, and pattern. Another value for fill style
is hatch, which is used to fill an area with selected hatching patterns-parallel lines or crossed lines.
23
As with line at- tributes, a selected fillstyle value is recorded in the list of system attributes and
applied to fill the interiors of subsequently specified areas. Fill selections for 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 inte- riorcolor the
same as the background color. A solid fill is displayed in a single color up to and including the
borders of the region. The color for a solid interior or for a hollow area outline is chosen with
where fillcolor parameter fc is set to the desired color code.
Soft Fill
Modified boundary-fill and flood-~III procedures that are applied to repaint areas so that the fill
color is combined with the background colors are referred to as soft-till or tint4 algorithms. One use
for these fill methods is to soften the fill colors at object borders that have been blurred to
antialiasing the edges. Another is to allow repainting of a color area that was originally filled with a
semi I transparent brush, where the current color is then a mixture of the brush color and the
background colors "behind" there.
In either case, we want the new fill color to have the same variations over the area as the current fill
color. As an example of this type of fill, the linear soft-fill algorithm repaints an area that was
originally painted by merging a foreground color F with a single background color 8, where F + B.
Assuming we know the values for F and 8, we can determine how these colors were originally
combined by checking the cur- rent 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:
The appearance of displayed characters is controlled by attributes such as font, size, color, and
orientation. Attributes can be set to the for entire character strings (text) and for individual
characters defined as marker symbols.
There are a great many text options that can be made available to graphics pro- grammers. First of
all, there is the choice of font (or typeface), which is a set of characters with a particular design
style such as New York, Courier, Helvetica, London, 'Times Roman, and various special symbol
groups. The characters in a selected font can also be displayed with assorted underlining styles (sox,
dotted, double), in boldface, in italics. and in outline or shadow styles.
24
Each function references a single attribute that specifies exactly how a primitive is to be displayed
with that attribute setting. The qualifications are called individual or unbundled attributes, and they
are meant to be used with an output device that is capable of dis- playing primitives in that way
specified. If an application program, employing individual attributes, is interfaced to several output
devise, some of the devices may not have the capability to display the intended attributes. A
program using individual color attribute,or example, may have to be modified to produce ac-
ceptable output on a monochromatic monitor.
Individual attribute commands provide a simple and direct method for specifying attributes while ,
single output device is used When several kinds of output devices are available at a graphics
installation, it is convenient for a user to be able to say how attributes are to be interpreted on the
different de- vices. This is accomplis1ic.d by setting up tables for each output device that lists sets
of attribute values that are to be used on that device, to display each primitivetvpe. A particulars of
attribute values tor a primitive on each output is then chosen bv the appropriate table index.
Attributes in this manner called bundled attributes. The table for each primitive that de- fines
groups of attribute lo be used when at primitive on a particular output called a bundle table.
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:
which defines the attribute list corresponding to fill index f i on workstation ws. Parameters f s, 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
Subsequently defined fill areas are then displayed on each active workstation ac- cording to the
table entry specified by the fill index parameter fi. Other fill-area attributes, such as pattern
reference point and pattern size, are independent of the workstation designation and are set with the
functions previously described.
25
Bundled Text Attributes
The function
bundles values 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
Each text function that is then invoked is displayed on each workstation with the set of attributes by
this table position.
This defines the marker type, marker scale factor, and marker color for index mi on workstation ws.
Bundle table selections are then made with the function
Translation
A translation moves an object to a different position on the screen. You can translate a point
in 2D by adding translation coordinate (t x, ty) to the original coordinate (X, Y) to get the new
coordinate (X’, Y’).
26
From the above figure, you can write that −
X’ = X + tx
Y’ = Y + ty
The pair (tx, ty) is called the translation vector or shift vector. The above equations can also
be represented using the column vectors.
Rotation
In rotation, we rotate the object at particular angle θ (theta) from its origin. From the
following figure, we can see that the point P(X, Y) is located at angle φ from the horizontal
X coordinate with distance r from the origin.
Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you
will get a new point P’ (X’, Y’).
Using standard trigonometric the original coordinate of point P(X, Y) can be represented as
−
27
X= rcosϕ......(1)
Y = rsinϕ......(2)
Scaling
To change the size of an object, scaling transformation is used. In the scaling process, you
either expand or compress the dimensions of the object. Scaling can be achieved by
multiplying the original coordinates of the object with the scaling factor to get the desired
result.
Let us assume that the original coordinates are (X, Y), the scaling factors are (S X, SY), and
the produced coordinates are (X’, Y’). This can be mathematically represented as shown
below −
Where S is the scaling matrix. The scaling process is shown in the following figure.
28
If we provide values less than 1 to the scaling factor S, then we can reduce the size of the
object. If we provide values greater than 1, then we can increase the size of the object.
We have seen that basic transformations can be expressed in matrix form. But many graphic
application involve sequences of geometric transformations. Hence we need a general form
of matrix to represent such transformations. This can be expressed as:
We can combine multiplicative and translational terms for 2D geometric transformations into
a single matrix representation by expanding the 2 by 2 matrix representations to 3 by 3
matrices. This allows us to express all transformation equations as matrix multiplications,
providing that we also expand the matrix representations for coordinate positions. To express
any 2D transformations as a matrix multiplication, we represent each Cartesian coordinate
position (x,y) with the homogeneous coordinate triple (xh,yh,h),
such that
29
Thus, a general homogeneous coordinate representation can also be written as (h.x, h.y,
h). For 2D geometric transformations, we can choose the homogeneous parameter h to any
non-zero value. Thus, there is an infinite number of equivalent homogeneous representations
for each coordinate point (x,y). A convenient choice is simply to h=1. Each 2D position is
then represented with homogeneous coordinates (x,y,1). Other values for parameter h are
needed, for eg, in matrix formulations of 3D viewing transformations.
or
or
or
30
To perform a sequence of transformation such as translation followed by rotation and
scaling, we need to follow a sequential process −
To shorten this process, we have to use 3×3 transformation matrix instead of 2×2
transformation matrix. To convert a 2×2 matrix to 3×3 matrix, we have to add an extra
dummy coordinate W.
In this way, we can represent the point by 3 numbers instead of 2 numbers, which is
called Homogenous Coordinate system. In this system, we can represent all the
transformation equations in matrix multiplication. Any Cartesian point P(X, Y) can be
converted to homogenous coordinates by P’ (Xh, Yh, h).
Two Dimensional coordinates are represented using three-element column vectors, and
Transformation operation is represented by 3 x 3 matrices.
31
On the basis of the matrix product of the individual transformations we can set up a matrix
for any sequence of transformation known as composite transformation matrix. For row-
matrix representation we form composite transformations by multiplying matrices in order
from left to right whereas in column-matrix representation we form composite
transformations by multiplying matrices in order from right to left.
In the above example the point at infinity is presented in the form of homogeneous
coordinates. This is often needed when we want to represent a point at infinity in a certain
direction. For instance, for finding the vanishing point in perspective projections we can
transform the point at infinity in the given direction.
Composite Transformation
With the matrix representations of the previous sei:tion, we can set up a matrix for any
sequence of transformations as a composite transformation matrix by calculating the matrix
product of the individual transformations. products of transformation matrices is often
referred to as a concatenation, or composition, of matrices. For column-matrix
representation of coordinate positions, we form composite transformations by multiplying
matrices in order from right to left. That is, each successive transformation matrix pre
multiplies the product of the preceding transformation matrices.
Translations
If two successive translation vectors (t, tyl) and (I, ty2) are applied to a coordinate position
P, the final transformed location P' is calculated as
32
where P and P’ are represented as homogeneous-coordinate column vectors. We can verify
this result by calculating the matrix product for the two associative groupings Also, the
composite transformation matrix for this sequence of transaction.
Rotation
By multiplying the two rotation matrices, we can verify that two successive rota- tions are
additive:
so that the final rotated coordinates can be calculated with the composite rotation matrix
Scaling
The resulting matrix in this case indicates that successive scaling operations are
multiplicative. That is, if we were to triple the size of an object twice in success on, the final
size would be nine times that of the original.
With a graphics package that only provides a rotate function for revolving objects about the
coordinate origin, we can generate rotations about any selected pivot point (x, y,) by
performing the following sequence of translate-rotate translate operations:
1. Translate the object so that the pivot-point position is moved to the coordinate origin.
3. Translate the object so that the pivot point is returned to its original position
Figure 5-10 illustrates a transformation sequence tcs produce scaling with respect tu a
selected fixed position (x!, y,) using a scaling hmction that can only scale rela- lve to the
coordinate origin.
1. Translate object so that the fixed point coincichrs with the coordinate origin.
3. Use the inverse translation of step 1 to return the object to its original position.
33
General Scaling Directions
Composite Transformations
Parameters s, and s, 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
coordinate axes before applying the scaling transformation. out changing the orientation of
the object, we first perform a rotation so that the directions for s, and s2 coincide with the x
and y axes, respectively. Then the scaling transformation is applied, followed by an opposite
rotation to return points to their original orientations.
Reflection
Reflection is the mirror image of original object. In other words, we can say that it is a
rotation operation with 180°. In reflection transformation, the size of the object does not
change.
The following figures show reflections with respect to X and Y axes, and about the origin
respectively.
34
Shear
A transformation that slants the shape of an object is called the shear transformation. There
are two shear transformations X-Shear and Y-Shear. One shifts X coordinates values and
other shifts Y coordinate values. However; in both the cases only one coordinate changes its
coordinates and other preserves its values. Shearing is also termed as Skewing.
X-Shear
The X-Shear preserves the Y coordinate and changes are made to X coordinates, which
causes the vertical lines to tilt right or left as shown in below figure.
Y-Shear
35
The Y-Shear preserves the X coordinates and changes the Y coordinates which causes the
horizontal lines to transform into lines which slopes up or down as shown in the following
figure.
Translating an object from screen position (a) to position (b) by moving a rectangular block of
pixel values. Coordinate positions P, and P specify the limits of the rectangular block to be moved, and P,
is the destination reference position.
The particular capabilities of raster systems suggest an alternate method for transforming objects.
Raster systems store picture information as pixel patterns in the frame buffer. Therefore, some simple
transformations can be carried out rapidly by simply moving rectangular arrays of stored pixel values
from one location to another within the frame buffer. Few arithmetic operations are needed, so the pixel
transformations are particularly efficient. Raster functions that manipulate rectangular pixel arrays are
generally referred to as raster ops. Moving a block of pixels from one location to another is also called a
36
block transfer of pixel values, this operation is called (bit-block transfer), particularly when the function
is hardware implemented. The term Bix bit is sometimes used for block transfers on multi- level systems
(multiple bits per pixel). Figure 5-30 illustrates translation performed as a block transfer of a raster area.
All bit settings in the rectangular area shown are copied as a block into an- other part of the raster. We
accomplish this translation by first reading pixel intensities a specified rectangular area of a raster into an
array, then we copv the array back into the raster at the new location. The original object could be erased
by filling its rectangular area with the background intensity( assuming the object does not overlap other
objects in the scene).
UNIT III
A window defines a rectangular area in world coordinates. You define a window with a
GWINDOW statement. You can define the window to be larger than, the same size as, or
37
smaller than the actual range of data values, depending on whether you want to show all of
the data or only part of the data.
A viewport defines in normalized coordinates a rectangular area on the display device where
the image of the data appears. You define a viewport with the GPORT command. You can
have your graph take up the entire display device or show it in only a portion, say the upper
right part.
A window and a viewport are related by the linear transformation that maps the window onto
the viewport. A line segment in the window is mapped to a line segment in the viewport such
that the relative positions are preserved.
You don't have to display all of your data in a graph. In Figure 3.1, the graph on the left
displays all of the ACME stock data, and the graph on the right displays only a part of the
data. Suppose that you wanted to graph only the last ten years of the stock data, say from
1977 to 1986. You would want to define a window where the YEAR axis ranges from 77 to
86, while the PRICE axis could range from 120 to 160. Figure3.1shows stock prices in a
window defined for data from 1977 to 1986 along the horizontal direction and from 120 to
160 along the vertical direction. The window is mapped to a viewport defined by the points
(20,20) and (70,60). The appropriate GPORT and GWINDOW specifications are as follows:
38
Figure 3.1 : Window to Viewport Mapping
Understanding Windows
Because the default world coordinate system ranges from (0,0) to (100,100), you usually need
to define a window in order to set the world coordinates corresponding to your data. A
window specifies which part of the data in world coordinate space is to be shown. Sometimes
you want all of the data shown; other times, you want to show only part of the data.
A window is defined by an array of four numbers, which define a rectangular area. You
define this area by specifying the world coordinates of the lower left and upper right corners
in the GWINDOW statement, which has the general form
The argument can be either a matrix or a literal. The order of the elements is important. The
array of coordinates can be a 2 ×2, 1 ×4, or 4 ×1 matrix. These coordinates can be specified
as matrix literals or as the name of a numeric matrix containing the coordinates. If you do not
39
define a window, the default is to assume both x and y range between 0 and 100.
In summary, a window
● is a rectangular area
Point Clipping
Clipping a point from a given window is very easy. Consider the following figure, where the
rectangle indicates the window. Point clipping tells us whether the given point (X, Y) is
within the given window or not; and decides whether we will use the minimum and
maximum coordinates of the window.
The X-coordinate of the given point is inside the window, if X lies in between Wx1 ≤ X ≤
Wx2. Same way, Y coordinate of the given point is inside the window, if Y lies in between
Wy1 ≤ Y ≤ Wy2.
40
Line Clipping
The concept of line clipping is same as point clipping. In line clipping, we will cut the
portion of line which is outside of window and keep only the portion that is inside the
window.
We will use 4-bits to divide the entire region. These 4 bits represent the Top, Bottom, Right,
and Left of the region as shown in the following figure. Here, the TOP and LEFT bit is set
to 1 because it is the TOP-LEFT corner.
41
There are 3 possibilities for the line −
● Line can be completely inside the window (This line should be accepted).
● Line can be completely outside of the window (This line will be completely removed
from the region).
● Line can be partially inside the window (We will find intersection point and draw
only that portion of line that is inside region).
Algorithm
Step 1 − Assign a region code for each endpoints.
Step 2 − If both endpoints have a region code 0000 then accept this line.
Step 3 − Else, perform the logical ANDoperation for both region codes.
Step 3.1 − If the result is not 0000, then reject the line.
Step 3.2.1 − Choose an endpoint of the line that is outside the window.
Step 3.2.2 − Find the intersection point at the window boundary (base on region code).
Step 3.2.3 − Replace endpoint with the intersection point and update the region code.
42
Step 3.2.4 − Repeat step 2 until we find a clipped line either trivially accepted or trivially
rejected.
First the polygon is clipped against the left edge of the polygon window to get new vertices
of the polygon. These new vertices are used to clip the polygon against right edge, top edge,
bottom edge, of the clipping window as shown in the following figure.
43
While processing an edge of a polygon with clipping window, an intersection point is found
if edge is not completely inside clipping window and the a partial edge from the intersection
point to the outside edge is clipped. The following figures show left, right, top and bottom
edge clippings −
44
Text Clipping
Various techniques are used to provide text clipping in a computer graphics. It depends on
the methods used to generate characters and the requirements of a particular application.
There are three methods for text clipping which are listed below −
● Text clipping
45
In all or none string clipping method, either we keep the entire string or we reject entire
string based on the clipping window. As shown in the above figure, STRING2 is entirely
inside the clipping window so we keep it and STRING1 being only partially inside the
window, we reject.
This clipping method is based on characters rather than entire string. In this method if the
string is entirely inside the clipping window, then we keep it. If it is partially outside the
window, then −
● If the character is on the boundary of the clipping window, then we discard that
entire character and keep the rest string.
46
This clipping method is based on characters rather than the entire string. In this method if
the string is entirely inside the clipping window, then we keep it. If it is partially outside the
window, then
● If the character is on the boundary of the clipping window, then we discard only that
portion of character that is outside of the clipping window
Definitions
● World Coordinate System - This is object space or the space in which the
application model is defined.
● World Window (or clipping) - This is the rectangle in the world defining the region
that is to be displayed.
● Interface Window - The window opened on the raster graphics screen in which the
image will be displayed.
● Viewport - The rectangular portion of the interface window that defines where the
image will actually appear (usually the entire interface window but in some cases
modified to be a portion of the interface window).
47
● Viewing Transformation - The process of mapping a world window in World
Coordinates to the Viewport.
Description
example
48
Development of the Window-To-Viewport Mapping
This mapping or transformation involves developing formulas that start with a point in the
world window, say (xw, yw). The formula is used to produce a corresponding point in
viewport coordinates, say (xv, yv). We would like for this mapping to be "proportional" in
the sense that if xw is 30% of the way from the left edge of the world window, then xv is
30% of the way from the left edge of the viewport. Similarly, if yw is 30% of the way from
the bottom edge of the world window, then yv is 30% of the way from the bottom edge of the
viewport. The picture below shows this proportionality.
By solving these equations for the unknown viewport position (xv, yv), the following
becomes true:
49
The scale factors (Sx, Sy) would be:
The position of the viewport can be changed allowing objects to be viewed at different
positions on the Interface Window. Multiple viewports can also be used to display different
sections of a scene at different screen positions. Also, by changing the dimensions of the
viewport, the size and proportions of the objects being displayed can be manipulated. Thus, a
zooming affect can be achieved by successively mapping different dimensioned clipping
windows on a fixed sized viewport.
If the aspect ratio of the world window and the viewport are different, then the image may
look distorted.
In OpenGL, the function void gluOrtho2D(left, right, bottom, top); is used to set up the
world window. For example, if we wanted a world window with x varying from -1.0 to 1.0
and y varying from 3.0 to 5.0, we would use the following code to accomplish this:
glMatrixMode(GL_PROJECTION);
50
glLoadIdentity();
To set up the viewport, we would use glViewport(left, bottom, width, height); For example,
if we wished a viewport to start at the lower left corner of the interface window, have a width
of 200 and a height of 300, we would use the following OpenGL statement to accomplish
this:
If we draw a number of copies of the same image in rows and columns across the interface
window so that they cover the entire window, it is called tiling. The picture that is drawn
many times is called a motif. To achieve tiling in computer graphics, the window remains
static and the viewport is changed many times and the picture is redrawn each time the
viewport is changed. The following picture shows the same image from the world drawn 4
times in 4 different viewports.
51
{
glViewport (i * screenWidth/2.0, j * screenHeight/2.0, screenWidth/2,
screenHeight/2);
drawSaturn();
}
Zooming is a technique in which users can change the size of the area to be viewed in order
to see more detail or less detail. Panning or roaming means sliding the camera across the
scene, taking in different parts of it at different times. Both zooming and panning can be
achieved in computer graphics by leaving the viewport static and changing the world
window. The picture below (taken from wikipedia.org) shows these concepts.
The earlier chapters in this book have described how to construct a picture and position it on
a virtual device in a natural way. In many application areas, there is a need to display the
same or similar graphical information many times possibly at different positions on the
device. This leads to the need for some storage mechanism whereby pictures or subpictures
can be saved for later use during a program's execution. GKS has the concept of a segment
for this purpose. Graphical output can be stored in segments during the execution of a
52
program and later reused. Segments have a number of segment attributes associated with
them which allow the user to modify the appearance of the whole segment in a significant
way when it is reused.
To take a simple example not using segments, consider a crude animation system in which
the user constructs a scenic background and then displays an object moving across the scene
on successive frames; Suppose it is the duck we want to move across the pond on successive
frames; the position of the duck can be input by the operator on a keyboard and read by the
program using a FORTRAN READ statement.
100 CONTINUE
READ(5, '(2F6.2)') X, Y
NEW FRAME
DRAW BACKGROUND
DRAW DUCK AT(X, Y)
GOTO 100
where the subroutine DRAW BACKGROUND draws the outline of the tree, pond and
landscape and the subroutine DRAW DUCK AT draws the duck at the position (X,Y). Note
that NEW FRAME clears the display but is not a GKS function.
This is, however, a very inefficient program, because unnecessary work has to be performed.
For example, the normalization transformation has to be applied afresh to the background
scene for each frame despite the fact that the background does not change from frame to
frame. An obvious solution to this problem would be for GKS to store the background after
the normalization transformation has been applied so that on each new frame it is only
necessary to perform the minimum of computation to redraw the background on the display.
That is a good solution if the display is, say, a storage tube or pen plotter.
However, there are more sophisticated displays, such as vector refresh displays and raster
displays which allow the user to selectively erase parts of the picture or move parts of a
picture. Using such a display, the most efficient implementation of this example program
would be to draw the background and the duck in its initial position, then erase the duck (if
necessary) and move it to the new position specified. The picture contains one tree, one pond,
one landscape and three ducks. A program to draw such a picture might well be structured as
four subroutines, each corresponding to one of the graphical objects (tree, pond, landscape
53
and duck), where the subroutine to draw the duck would be parameterized on the position of
the duck:
TREE
LANDSCAPE
POND
DO 100 I = I, 3
100 DRAW DUCK AT(X(I), Y(I))
illustrates the correspondence between graphical objects and the picture. In particular, note
that one object can have more than one instance in the picture. The order in which the output
primitives are presented to GKS then reflects the structure of the picture, but we have as yet
seen no way in which this structure can be recorded and made use of in GKS.
In GKS, as mentioned above, output primitives may be grouped together into segments,
which are then associated with the output device. They can be manipulated in several ways as
will be described later in this chapter.
CREATE SEGMENT(ID)
where ID is the name by which the segment is to be known. This segment is then the open
segment. Subsequent calls to output primitive functions will result in those primitives being
inserted into this open segment, as well as being output, until such time as the function:
CLOSE SEGMENT
CREATE SEGMENT(1)
DUCK
CLOSE SEGMENT
will create a segment with name 1 which contains the duck outline.
It is important to note that at any time, only one segment can be open, thus a series of
function calls such as:
54
CREATE SEGMENT(1)
output primitives
is not permitted and will generate an error. It is also important to realize that once a segment
has been closed, further output primitives cannot be added to it.
Once created, there are a number of operations which can be performed on segments. The
simplest of these is deletion! A segment is deleted by calling the function:
DELETE SEGMENT(ID)
where ID is the name of the segment to be deleted. After a segment has been deleted, the
segment's name can be reused.
Segment Transformations
In the introduction to this chapter we discussed the need to move objects, or parts of objects,
around on a display in response either to some computation or to some operator
direction. Segment transformations provide the way to do this efficiently. The segment
transformation is a transformation operating on all the coordinates in the segment definition.
When a segment is created, the segment transformation is set to the null, or identity,
transformation. The segment transformation can be subsequently changed by invoking the
function:
where ID is the name of the segment whose transformation is to be changed. Note that this
name can be the name of the open segment; this is very useful as examples later will show.
The parameter MATRIX is a 2 × 3 transformation matrix.
Constructing transformation matrices can be a tricky task and so GKS provides two utility
functions, EVALUATE TRANSFORMATION MATRIX and ACCUMULATE
TRANSFORMATION MATRIX to help the application programmer. The first function:
55
EVALUATE TRANSFORMATION MATRIX(FX, FY, TX, TY, R, SX, SY, SWITCH,
MATRIX)
calculate a transformation matrix which may be fed straight into SET SEGMENT
TRANSFORMATION. FX and FY specify a fixed point; TX and TY specify a translation
or shift vector; R is an angle of rotation in radians and SX and SY are scale factors. The
transformation matrix computed is returned in the parameter MATRIX. Scale and rotation are
relative to the specified fixed point. The coordinate switch, SWITCH, can take the value WC
or NDC. In the former case, the values specified for the fixed point and shift vector are taken
as world coordinates, in the latter case as normalized device coordinates. If SWITCH takes
the value WC, then the fixed point (FX,FY) and the shift vector (TX,TY) are transformed to
normalized device coordinates by the current normalization transformation.
The elements of the resulting transformation matrix, which represent the shift component of
the transformation, are expressed in normalized device coordinates. The transformation
matrix is computed so that the order in which the transformations are applied to coordinate
data is scale, rotate and shift..
TX=5
TY=5
R=0
SX=1
SY=1
SWITCH=WC
56
What values do we assign to FX and FY? It is clear that a fixed point does not need to be
specified for a shift operation, since the effect of a shift is the same on all points in the
picture. However, since EVALUATE TRANSFORMATION MATRIX computes the
combined effects of a scale, rotation and shift, and a fixed point does need to be specified for
the first two, a fixed point must be given. Any point could be chosen in this instance, since
the scaling and rotation operations (by unity and zero) do not affect the appearance of the
picture. Typically the origin (0,0) would be specified as the fixed point, although if a
particular point is used to calculate the shift vector, it may be clearer to take that point as the
fixed point. We will use (0,8.8) as the fixed point.
Thus, the complete program to create a segment containing the duck, display it at position
(0,8.8), and then move it to position (5,13.8) would be:
CREATE SEGMENT(1)
DUCK
CLOSE SEGMENT
FX=0
FY=8.8
TX=5
TY=5
R=0
SX=1
SY=1
SWITCH=WC
EVALUATE TRANSFORMATION MATRIX(FX, FY, TX, TY, R, SX, SY, SWITCH,
MAT)
SET SEGMENT TRANSFORMATION(1, MAT)
We can now write the central part of the crude animation program described in the
introduction to this chapter, which obtains the position at which the duck is to be displayed
from the display operator and moves the duck to this position. The duck starts at the point
(0,8.8) and is to be redisplayed at the point (XL,YL) which is the position input by the
operator. The program is thus:
57
CREATE SEGMENT(1)
DUCK
CLOSE SEGMENT
FX=0
FY=8.8
R=0
SX=1
SY=1
SWITCH=WC
100 CONTINUE
READ(5, '(2F6.2)') XL, YL
TX=XL
TY=YL-8.8
EVALUATE TRANSFORMATION MATRIX(FX, FY, TX, TY, R, SX, SY, SWITCH,
MAT)
SET SEGMENT TRANSFORMATION(1, MAT)
GOTO 100
The size, at which a segment is displayed, is controlled by the scaling factors. To decrease the
size uniformly by a factor of 2, relative to the start point (0,8.8), the transformation matrix is
constructed as follows:
FX=0
FY=8.8
TX=0
TY=0
R=0
SX=0.5
SY=O.5
SWITCH = WC
EVALUATE TRANSFORMATION MATRIX(FX, FY, TX, TY, R, SX, SY, SWITCH,
MAT)
SET SEGMENT TRANSFORMATION(1, MAT)
An anticlockwise rotation of the segment by 30 degrees (π/6 radians), about the fixed point
(0,8.8) would be expressed by:
58
FX=0
FY=8.8
TX=0
TY=0
R=PI/6
SX=1
SY=1
SWITCH=WC
EVALUATE TRANSFORMATION MATRIX(FX, FY, TX, TY, R, SX, SY, SWITCH,
MAT)
SET SEGMENT TRANSFORMATION(1, MAT)
The parameters FX, FY, TX, TY, R, SX, SY and SWITCH have the same meanings as in
EVALUATE TRANSFORMATION MATRIX. The transformation specified by these
parameters is concatenated with the transformation specified by the matrix, MATIN, and the
resulting transformation matrix is returned in MATOUT. The order in which the
transformations are applied is input matrix, scale, rotate and shift. One likely use of this
function is to change the order in which scale, rotate and shift are applied, by specifying each
elementary transformation separately and using a call to EVALUATE TRANSFORMATION
MATRIX followed by two calls to ACCUMULATE TRANSFORMATION MATRIX to
build up the required matrix.
To explain the effects of clipping on transformed segments, something has to be said about
when segment transformation takes place. The segment transformation is actually applied
59
after the normalization transformation (which, it will be recalled, maps world coordinates into
normalized device coordinates) but before any clipping. Coordinates stored in segments are
in fact normalized device coordinates. It will be recalled that the elements of the
transformation matrix which define the shift to be applied are expressed in normalized device
coordinates.
If the clipping indicator is NOCLIP when a primitive is put into a segment, the clipping
rectangle [0,1] × [0,1] in normalized device coordinates is stored with the primitive. Thus, in
this example, the clipping rectangle [0,1] × [0,1] is stored with the polyline primitives
describing the duck. The effect of this program is to generate a picture in the lower left hand
quadrant of NDC space as shown in the left hand picture in Figure 4-9, This is then shifted by
(0.25, 0.25) in NDC space, as shown in the right hand picture. (Note the use of the coordinate
switch NDC in EVALUATE TRANSFORMATION MATRIX.) Now if the clipping
indicator is set to CLIP before CREATE SEGMENT is invoked, the clipping rectangle stored
with the polyline primitives is the viewport of normalization transformation 1 ([0,0.5] ×
[0,0.5]).
60
Note that the clipping rectangle was not transformed by the segment transformation.
Now we will consider a more complicated example in which more than one normalization
transformation is used in the definition of a segment:
Now if the clipping indicator is set to CLIP before CREATE SEGMENT is invoked, the
polyline defining the duck will be clipped against the NDC space rectangle [0,0,5] × [0,0,5]
and the tree will be clipped against the rectangle [0,0,5] × [0,5,1],
Segment Visibility
The segment visibility attribute determines whether a segment will be displayed or not. By
default when a segment is created it is visible; thus:
CREATE SEGMENT(1)
DUCK
CLOSE SEGMENT
will result in the duck picture being displayed. Normally the operator will see the picture
being built up on the display as each line is drawn. The visibility attribute may be changed by
the function:
61
SET VISIBILITY(ID, VIS)
where VIS specifies the visibility of segment ID. VIS may take the values VISIBLE and
INVISIBLE. Hence, if the program is modified by the insertion of:
after the call to CREATE SEGMENT, the duck will not be displayed on the screen. A
subsequent invocation of:
The visibility attribute is particularly useful for controlling the display of messages and
menus (though there are other ways to deal with menus in GKS). Typically each message will
be put into a separate segment, initially invisible. As a message is required, the segment
containing it is made visible.
Segment Highlighting
Most vector refresh display hardware has the capability of highlighting a segment, for
example by causing it to blink. The principal use of this facility is in drawing the operator's
attention to some facet of the display. For example, in the animation program described in
this chapter, when the operator has selected a new position at which the duck is to be
displayed, we might highlight the duck segment in this new position and ask the operator to
confirm that this is the position he really intends.
where HIGH specifies the highlighting for segment ID. HIGH may take the values
HIGHLIGHTED and NORMAL. When a segment is created, the highlighting attribute is
NORMAL. It is set to HIGHLIGHTED by:
For a segment to appear highlighted, not only must the highlighting attribute have the value
HIGHLIGHTED, but also the visibility attribute must have the value VISIBLE. If a segment
needs to be highlighted as it is being created, the CREATE SEGMENT function should be
followed by the SET HIGHLIGHTING function. The precise manner in which highlighting is
62
implemented will depend on the particular display hardware that is being used. For some
hardware, there will be no visible distinction between HIGHLIGHTED and NORMAL
segments.
Segment Priority
Suppose that the scene at the start of this chapter is to be displayed on a raster scan display;
then it might be done as follows. Firstly cover the entire display surface with a blue
background. This could be done using a fill area primitive with a rectangular area whose
boundary corresponds with that of the display surface. We now have a blue sky over the
entire display! Now paint-in the rolling green pastures. This could be done using a fill area
primitive. Painting-in means changing the current colour value of every picture element (or
pixel), in the portion of the frame buffer over which the filled area lies, to the colour
associated with the fill area primitive.
Now it is clear that the appearance of the final picture depends on the order in which the fill
area primitives are written into the frame buffer; for example, if the duck is created before the
pond, then since the area defining the duck lies wholly within the pond, the pixels
corresponding to the duck will. be overwritten with the colour of the pond and the duck will
disappear.
Suppose now we add the sun and wish, over a series of frames to observe a sunset! We could
define the sun as a segment, and let the operator define successive positions of the sun. This
works very well until the sun meets the green landscape, because the sun will then overwrite
pixels corresponding to the landscape and will not be observed to set. If the landscape had a
higher priority than the sun, in the sense that pixels corresponding to the landscape were not
overwritten by the setting sun, the desired effect would be achieved.
GKS provides a mechanism for doing this, segment priority, which can be set by the
function:
where PRIORITY is a value in the range 0 to 1, which specifies the priority of segment ID.
In this example, the sun would be put in a segment with priority higher than the sky, but
lower than that of the tree, landscape, pond and duck; the pond and tree need priority higher
than the landscape and the duck needs priority higher than the tree and pond. Suitable
priorities would be:
63
Segment Priority
sky 0.0
sun 0.25
landscape 0.5
pond 0.75
tree 0.75
duck 1.0
Segment priority controls the order in which segments are redrawn when the picture is
changed.
There are a number of points which need to be stressed about segment priority, because it is
not as universally useful as it might at first sight seem. The first point is that segment priority
only works for devices which have the appropriate hardware capability. It cannot be used to
force software checking of interference between segments for displays which do not have the
appropriate hardware capability.
In practice this is likely to mean that segment priority will only be available for colour raster
scan displays. Secondly, the description of the SET SEGMENT PRIORITY routine given
above conveys the impression that it is possible to distinguish between an infinite number of
segment priorities. In practice the particular display being used is likely to have a finite range
of priorities available, in which case the priority value specified is mapped onto this range.
This means that segments specified to GKS as having different priorities can end up having
the same priority because the hardware cannot distinguish sufficient levels.
A final point to note is that if two segments of the same priority overlap, or if primitives
within a given segment overlap, then the effects will be defined, but may vary from one
implementation of GKS to another.
64
RENAMING SEGMENTS
where OLD and NEW are the old and new segment names respectively. Thus, if segment 1
contains the duck outline and we invoke:
RENAME SEGMENT(1, 2)
the duck outline will now be segment 2 and the segment name 1 can be reused for some other
purpose. There are two points to note about this function. Firstly, there must be no segment
called NEW in existence when the function is called. If there is, an error message will be
generated. Secondly, it is perfectly permissible to do the following:
CREATE SEGMENT(1)
output primitives
RENAME SEGMENT(1, 2)
output primitives
CLOSE SEGMENT
A typical usage of RENAME SEGMENT is the following. In the animation program at the
start of this chapter, the operator wishes to determine a new position for the duck. Sometimes
the placement is facilitated if the duck in the initial position is still displayed whilst the new
position is selected. However, the application program wishes to use a particular segment
name for the duck, say 1. The duck would be created in segment I and a second duck in some
other segment, say 2. When the new position has been determined by positioning segment 2,
segment 1 is deleted and segment 2 is renamed segment 1. In some applications, a common
technique is to use a set of segment names cyclically to hold a segment in intermediate
positions, renaming the latest segment when the position is correct and deleting the others.
65
3.6 THE THYSICAL INPUT DEVICE
● Keyboard
● Mouse
● Joy Stick
● Light pen
● Track Ball
● Scanner
● Graphic Tablet
● Microphone
Keyboard
Keyboard is the most common and very popular input device which helps to input data to
the computer. The layout of the keyboard is like that of traditional typewriter, although there
are some additional keys provided for performing additional functions.
66
Keyboards are of two sizes 84 keys or 101/102 keys, but now keyboards with 104 keys or
108 keys are also available for Windows and Internet.
Typing Keys
1
These keys include the letter keys (A-Z) and digit keys (09) which generally give
the same layout as that of typewriters.
Numeric Keypad
Function Keys
The twelve function keys are present on the keyboard which are arranged in a row
3
at the top of the keyboard. Each function key has a unique meaning and is used for
some specific purpose.
4 Control keys
67
These keys provide cursor and screen control. It includes four directional arrow
keys. Control keys also include Home, End, Insert, Delete, Page Up, Page Down,
Control(Ctrl), Alternate(Alt), Escape(Esc).
5 Keyboard also contains some special purpose keys such as Enter, Shift, Caps
Lock, Num Lock, Space bar, Tab, and Print Screen.
Mouse
Mouse is the most popular pointing device. It is a very famous cursor-control device having
a small palm size box with a round ball at its base, which senses the movement of the mouse
and sends corresponding signals to the CPU when the mouse buttons are pressed.
Generally, it has two buttons called the left and the right button and a wheel is present
between the buttons. A mouse can be used to control the position of the cursor on the screen,
but it cannot be used to enter text into the computer.
Advantages
● Easy to use
● Moves the cursor faster than the arrow keys of the keyboard.
68
Joystick
Joystick is also a pointing device, which is used to move the cursor position on a monitor
screen. It is a stick having a spherical ball at its both lower and upper ends. The lower
spherical ball moves in a socket. The joystick can be moved in all four directions.
The function of the joystick is similar to that of a mouse. It is mainly used in Computer
Aided Designing (CAD) and playing computer games.
Light Pen
Light pen is a pointing device similar to a pen. It is used to select a displayed menu item or
draw pictures on the monitor screen. It consists of a photocell and an optical system placed
in a small tube.
When the tip of a light pen is moved over the monitor screen and the pen button is pressed,
its photocell sensing element detects the screen location and sends the corresponding signal
to the CPU.
Track Ball
69
Track ball is an input device that is mostly used in notebook or laptop computer, instead of a
mouse. This is a ball which is half inserted and by moving fingers on the ball, the pointer
can be moved.
Since the whole device is not moved, a track ball requires less space than a mouse. A track
ball comes in various shapes like a ball, a button, or a square.
Scanner
Scanner is an input device, which works more like a photocopy machine. It is used when
some information is available on paper and it is to be transferred to the hard disk of the
computer for further manipulation.
Scanner captures images from the source which are then converted into a digital form that
can be stored on the disk. These images can be edited before they are printed.
70
Digitizer
Digitizer is an input device which converts analog information into digital form. Digitizer
can convert a signal from the television or camera into a series of numbers that could be
stored in a computer. They can be used by the computer to create a picture of whatever the
camera had been pointed at.
Digitizer is also known as Tablet or Graphics Tablet as it converts graphics and pictorial
data into binary inputs. A graphic tablet as digitizer is used for fine works of drawing and
image manipulation applications.
Microphone
Microphone is an input device to input sound that is then stored in a digital form.
The microphone is used for various applications such as adding sound to a multimedia
presentation or for mixing music.
71
MICR input device is generally used in banks as there are large number of cheques to be
processed every day. The bank's code number and cheque number are printed on the cheques
with a special type of ink that contains particles of magnetic material that are machine
readable.
This reading process is called Magnetic Ink Character Recognition (MICR). The main
advantages of MICR is that it is fast and less error prone.
OCR scans the text optically, character by character, converts them into a machine readable
code, and stores the text on the system memory.
72
Bar Code Readers
Bar Code Reader is a device used for reading bar coded data (data in the form of light and
dark lines). Bar coded data is generally used in labelling goods, numbering the books, etc. It
may be a handheld scanner or may be embedded in a stationary scanner.
Bar Code Reader scans a bar code image, converts it into an alphanumeric value, which is
then fed to the computer that the bar code reader is connected to.
73
aid in positioning and other picture construction operations. The several techniques used for
interactive picture construction that are incorporated into graphics packages are:
(1) Basic positioning methods:- coordinate values supplied by locator input are often used
with positioning methods to specify a location for displaying an object or a character string.
Coordinate positions are selected interactively with a pointing device, usually by positioning
the screen cursor.
(2) constraints:-A constraint is a rule for altering input coordinates values to produce a
specified orientation or alignment of the displayed coordinates. the most common constraint
is a horizontal or vertical alignment of straight lines.
(3) Grids:- Another kind of constraint is a grid of rectangular lines displayed in some part of
the screen area. When a grid is used, any input coordinate position is rounded to the nearest
intersection of two grid lines.
(4) Gravity field:- When it is needed to connect lines at positions between endpoints, the
graphics packages convert any input position near a line to a position on the line. The
conversion is accomplished by creating a gravity area around the line. Any related position
within the gravity field of line is moved to the nearest position on the line. It illustrated with a
shaded boundary around the line.
(5) Rubber Band Methods:- Straight lines can be constructed and positioned using rubber
band methods which stretch out a line from a starting position as the screen cursor.
(6) Dragging:- This methods move object into position by dragging them with the screen
cursor.
(7) Painting and Drawing:- Cursor drawing options can be provided using standard curve
shapes such as circular arcs and splices, or with freehand sketching procedures. Line widths,
line styles and other attribute options are also commonly found in painting and drawing
packages.
74
– Locator
– Stroke
– String
– Valuator
– Choice
– Pick
Locator
A device that allows the user to specify one coordinate position. Different methods can be used,
such as a mouse cursor, where a location is chosen by clicking a button, or a cursor that is moved using
different keys on the keyboard. Touch screens can also be used as locators; the user specifies the location
by inducing force onto the desired coordinate on the screen.
Stroke
A device that allows the user to specify a set of coordinate positions. The positions can be
specified, for example, by dragging the mouse across the screen while a mouse button is kept pressed. On
release, a second coordinate can be used to define a rectangular area using the first coordinate in addition.
String
A device that allows the user to specify text input. A text input widget in combination with the
keyboard is used to input the text. Also, virtual keyboards displayed on the screen where the characters
can be picked using the mouse can be used if keyboards are not available to the application.
Valuator
A device that allows the user to specify a scalar value. Similar to string inputs, numeric values can
be specified using the keyboard. Often, up-down-arrows are added to increase or decrease the current
value. Rotary devices, such as wheels can also be used for specifying numerical values. Often times, it is
useful to limit the range of the numerical value depending on the value.
Choice
75
A device that allows the user to specify a menu option. Typical choice devices are menus or radio
buttons which provide various options the user can choose from. For radio buttons, often only one option
can be chosen at a time. Once another option is picked, the previous one gets cleared.
Pick
A device that allows the user to specify a component of a picture. Similar to locator devices, a
coordinate is specified using the mouse or other cursor input devices and then back-projected into the
scene to determine the selected 3-D object. It is often useful to allow a certain “error tolerance” so that an
object is picked even though the user did not exactly onto the object but close enough next to it. Also,
highlighting objects within the scene can be used to traverse through a list of objects that fulfill the
proximity criterion.
UNIT IV
In a 3-D coordinate system the X axis generally points from left to right, and the Y axis
generally points from bottom to top. ( Although some windowing systems will have their Y
coordinates going from top to bottom. )
When we add the third coordinate, Z, we have a choice as to whether the Z-axis points into
the screen or out of the screen:
76
Hand Coordinate System (RHS)
Z is coming out of the page
The important thing to note is what coordinate system is being used by the package you are
working with, both for the creation of models and the displaying of them. Also note that if the
two packages use different coordinate systems, then the model(s) may need to be inverted in
some fashion when they are loaded in for viewing.
77
OpenGL generally uses a right-hand coordinate system.
In a typical graphics program, we may need to deal with a number of different coordinate
systems, and a good part of the work ( and the cause of many headaches ) is the conversion of
coordinates from one system to another. We'll learn about the conversion process a little later,
but in the meantime, here is a list of some of the coordinate systems you may encounter:
78
● Model Window Coordinate System - Not to be confused with desktop windowing
systems ( MS Windows or X Windows ), this coordinate system refers to the subset of
the overall model world that is to be displayed on the screen. Depending on the
viewing parameters selected, the model window may be rectalinear or a distorted
viewing frustrum of some kind.
To obtain display of a three-dimensional scene that has been modeled in world coordinates.
we must first set up a coordinate reference for the "camera". This coordinate reference
defines the position and orientation for the plane of the carnera film which is the plane we
want to us to display a view of the objects in the scene. Object descriptions are then
transferred to the camera reference coordinates and projected onto the selected display plane.
We can then display the objects in wireframe (outline) form, or we can apply lighting surface
rendering techniques to shade the visible surfaces.
PARALLEL PROJECTION
In a parallel projection, parallel lines in the world-coordinate scene projected into parallel
lines on the two-dimensional display plane.
Perspective Projection
depth cueing
79
A simple method for indicating depth with wireframe displays is to vary the intensity of
objects according to their distance from the viewing position. The viewing position are
displayed with the highest intensities, and lines farther away are displayed with decreasing
intensities.
We can also clarify depth relationships in a wireframe display by identifying visible lines in
some way. The simplest method is to highlight the visible lines or to display them in a
different color. Another technique, commonly used for engineering drawings, is to display
the nonvisible lines as dashed lines. Another approach is to simply remove the nonvisible
lines
Surface Rendering
Added realism is attained in displays by setting the surface intensity of objects according to
the lighting conditions in the scene and according to assigned surface characteristics.
Lighting specifications include the intensity and positions of light sources and the general
background illumination required for a scene. Surface properties of objects include degree of
transparency and how rough or smooth the surfaces are to be. Procedures can then be applied
to generate the correct illumination and shadow regions for the scene.
Exploded and cutaway views of such objects can then be used to show the internal
structurand relationship of the object Parts
Stereoscopic devices present two views of a scene: one for the left eye and the other
for the right eye.
Representation schemes for solid objects are often divided into two broad categories
80
Boundary representations (B-reps) describe a three-dimensional object as a set of surfaces
that separate the object interior from the environment.Typical examples of boundary
representations are polygon facets and spline patches.
Space-partitioning representations are used to describe interior properties, by partitioning
the spatial region containing an object into a set of small, nonoverlapping, contiguous solids
(usually cubes).
In the 2D system, we use only two coordinates X and Y but in 3D, an extra coordinate Z is
added. 3D graphics techniques and their application are fundamental to the entertainment,
games, and computer-aided design industries. It is a continuing area of research in scientific
visualization.
Furthermore, 3D graphics components are now a part of almost every personal computer
and, although traditionally intended for graphics-intensive software such as games, they are
increasingly being used by other applications.
Graphics is a word used for all the different types of artwork, such as photographs, graphs,
charts etc.
Graphics packages may not be as detailed as you think. It can be a simple paint package,
which has features of shading, drawing line diagrams and many other simple but effective
81
features. These packages can be an alternative to complicated DTP packages. As it is very
difficult to draw with the mouse, many people scan the drawings on the computer and now
there are software packages, which do not use a mouse.
New equipment used by professionals so that they can get pictures from a variety of places.
A video grabber lets you get pictures from the television or a video camera and you then can
alter it on your computer. A digital camera is also very popular as you can take pictures and
then put them on your PC and alter then. This also means that you do not have to pay for the
developing cost. You can also use clip art for pictures.
Bit map vector graphics
When using a graphics package the graphics file can have the image represented as a:
1.Bit map
2.Vector image
A bit map files makes every dot or pixel on the screen has a single bit of information in a
file. If it is in colour, you then need to store additional bits. The disadvantage to this is that if
you want to alter anything you have to change it at a pixel at a time. When you enlarge an
image, the number of pixels stays the same.
In vector graphics, the lines are stored as equations on the computer. They are stored in
vectors. The advantage of vector graphics over bit map files is that it is easy to alter things
without any loss in resolution. When you enlarge an image, the number of pixels increases to
the proportion of the image. CAD packages use vector images.
Clip Art
Clip Art is a collection of copyright-free drawings which you can place on your drawings.
The drawings on clip-art look very professional, as they have been drawn in detail.
Translation
82
A point can be translated in 3D by adding translation coordinate (tx,ty,tz)(tx,ty,tz) to the original
coordinate (X, Y, Z) to get the new coordinate (X’, Y’, Z’).
Rotation
3D rotation is not same as 2D rotation. In 3D rotation, we have to specify the angle of rotation
along with the axis of rotation. We can perform 3D rotation about X, Y, and Z axes.
83
Scaling
You can change the size of an object using scaling transformation. In the scaling process, you
either expand or compress the dimensions of the object. Scaling can be achieved by multiplying the
original coordinates of the object with the scaling factor to get the desired result. The following figure
shows the effect of 3D scaling −
In 3D scaling operation, three coordinates are used. Let us assume that the original coordinates are
(X, Y, Z), scaling factors are (SX,SY,Sz)(SX,SY,Sz) respectively, and the produced coordinates are (X’,
Y’, Z’).
4.6 OTHER TRANSFORMATION
Shear
A transformation that slants the shape of an object is called the shear transformation. Like
in 2D shear, we can shear an object along the X-axis, Y-axis, or Z-axis in 3D.
84
As shown in the above figure, there is a coordinate P. You can shear it to get a new
coordinate P'
85
UNIT V
5.1 PROJECTION
Parallel projection
Parallel projection discards z-coordinate and parallel lines from each vertex on the object are
extended until they intersect the view plane. In parallel projection, we specify a direction of
projection instead of center of projection.
In parallel projection, the distance from the center of projection to project plane is infinite.
In this type of projection, we connect the projected vertices by line segments which
correspond to connections on the original object.
Parallel projections are less realistic, but they are good for exact measurements. In this type
of projections, parallel lines remain parallel and angles are not preserved. Various types of
parallel projections are shown in the following hierarchy.
Orthographic Projection
In orthographic projection the direction of projection is normal to the projection of the plane.
There are three types of orthographic projections −
86
● Front Projection
● Top Projection
● Side Projection
Oblique Projection
In orthographic projection, the direction of projection is not normal to the projection of
plane. In oblique projection, we can view the object better than orthographic projection.
There are two types of oblique projections − Cavalier and Cabinet. The Cavalier projection
makes 45° angle with the projection plane. The projection of a line perpendicular to the view
plane has the same length as the line itself in Cavalier projection. In a cavalier projection,
the foreshortening factors for all three principal directions are equal.
The Cabinet projection makes 63.4° angle with the projection plane. In Cabinet projection,
lines perpendicular to the viewing surface are projected at ½ their actual length. Both the
projections are shown in the following figure −
87
Isometric Projections
Orthographic projections that show more than one side of an object are called axonometric
orthographic projections. The most common axonometric projection is an isometric
projection where the projection plane intersects each coordinate axis in the model
coordinate system at an equal distance. In this projection parallelism of lines are preserved
but angles are not preserved. The following figure shows isometric projection −
88
Perspective Projection
In perspective projection, the distance from the center of projection to project plane is finite
and the size of the object varies inversely with distance which looks more realistic.
The distance and angles are not preserved and parallel lines do not remain parallel. Instead,
they all converge at a single point called center of projection or projection reference
point. There are 3 types of perspective projections which are shown in the following chart.
89
The following figure shows all the three types of perspective projection −
Viewing in 3D involves the following considerations: - We can view an object from any spatial
position, eg. In front of an object, Behind the object, In the middle of a group of objects, Inside an
object, etc. - 3D descriptions of objects must be projected onto the flat viewing surface of the output
device. - The clipping boundaries enclose a volume of space.
90
Viewing Transformation Conversion of objection descriptions from world to viewing coordinates
is equivalent to a transformation that superimposes the viewing reference frame onto the world frame
using the basic geometric translate-rotate operations:
1. Translate the view reference point to the origin of the world-coordinate system.
2. Apply rotations to align the xv, yv, and zv axes (viewing coordinate system) with the world xw,
yw, zw axes, respectively.
We will assume that the user has defined a camera transform which can be applied to the
object in the Cartesian frame. This transform will convert the coordinates of the object into
the local coordinate system of the camera. Assuming this, we can assume that we are viewing
the object from the origin of the camera frame and the scene has been transformed to lie on
the negative -axis of the frame. We also assume that the user has defined the following
parameters:
● A field-of-view angle, , representing the angle subtended at the apex of the viewing
pyramid, and
● The specification of ``near'' and ``far'' bounding planes. These planes are
A three-dimensional view of the camera and its viewing space is given in the following
figure.
91
A side view of the this space, with the -axis coming out of the paper, is given in the
following figure. Note the field-of-view angle .
The specification of forms a viewing volume in the shape of a pyramid with the camera
(placed at the origin) at the apex of the pyramid and the negative- axis forming the axis of
the pyramid. This pyramid is commonly referred to as the viewing pyramid.
92
The specification of the near and far planes forms a truncated viewing pyramid giving a
region of space that contains the portion of the scene which is the ``center of attention'' of the
camera. The viewing transform, defined below, will transform this truncated viewing
Motivation
As motivation, consider the case when the camera is at the origin, the viewing direction is
along the negative -axis, and points are to be projected along the line that passes through
93
both the origin and the point, onto a plane defined by . The following figure
(we note that the distance is since the coordinate of is negative) and
similarly
94
since
So the projection induces a unique fourth column in the matrix. When the matrix is applied to
Now, consider the case where , and the field of view are present as parameters, and it
is necessary to transform the viewing pyramid defined by the angle and the
95
To transform the truncated viewing pyramid to the cube, we will start with a
transformation of the form
Here we have incorporated the projection in the fourth column, and have recognized that we
must scale the resulting values (the values in the pyramid range between and
and the result in image space must lie between and ) and must translate the center
truncated pyramid over to the origin. The values and are chosen so that the face of the
truncated pyramid defined by the near plane ( ) goes to the face of the image
space cube, and the face defined by the far plane ( ) goes to the face of the
cube. At a minimum, this implies that
96
and
That is, in order that the values on the left map to and , respectively, we
must have
97
Subtracting the equations, obtains
or
and by substitution,
98
Unfortunately, this is not quite correct, as we have mapped only the near and far faces that
correspond to the near and far planes. We need to also adjust for the left, right, top and
bottom faces so that the viewing pyramid is transformed to the image space cube. So consider
points on the top plane that bounds the viewing pyramid.
Similarly
99
So after dividing by the fourth coordinate we see that the coordinates of the points that lie
Since we wish coordinates to be mapped to (which is the value of the top of the
image space cube), we must multiply our projection matrix by a matrix that scales the
and coordinates by
giving
This is the matrix that transforms the truncated viewing pyramid into image space.
100
The above transformation transforms the truncated viewing pyramid into image space. The
inverse of this transformation does the opposite - transforms points from image space into the
truncated viewing pyramid. This inverse is given by
Perspective Transformation and Perspective Projection To produce perspective viewing effect, after
Modelling Transformation, Viewing Transformation is carried out to transform objects from the world
coordinate system to the viewing coordinate system. Afterwards, objects in the scene are further
processed with Perspective Transformation: the view volume in the shape of a frustum becomes a regular
parallelepiped. The transformation equations are shown as follows and are applied to every vertex of each
object:
101
x' = x * (d/z), y' = y * (d/z), z' = z
Where (x,y,z) is the original position of a vertex, (x',y',z') is the transformed position of the vertex,
and d is the distance of image plane from the center of projection. Note that: Perspective transformation is
different from perspective projection: Perspective projection projects a 3D object onto a 2D plane
perspectively.
View Volumes
View window - A rectangular area in the view plane which controls how much of the scene is
viewed. The edges of the view window are parallel to the xv and yv viewing axes. View volume - formed
by the view window and the type of projection to be used. Only those objects within the view volume will
appear in the generated display. So we can exclude objects that are beyond the view volume when we
render the objects in the scene. A finite view volume is obtained by bounding with front plane and back
plane (or the near plane and the far plane). Hence a view volume is bounded by 6 planes => rectangular
parallelepiped or a frustum, for parallel projection and perspective projection respectively.
Some facts
Perspective effects depend on the positioning of the center point of projection. If it is close to the
view plane, perspective effects are emphasized, ie. closer objects will appear larger than more distant
objects of the same size. The projected size of an object is also affected by the relative position of the
object and the view plane. 'Viewing' a static view:
The view plane is usually placed at the viewing-coordinate origin and the center of projection is
positioned to obtain the amount of perspective desired. 'Viewing' an animation sequence: Usually the
center of projection point is placed at the viewing-coordinate origin and the view plane is placed in front
of the scene. The size of the view window is adjusted to obtain the amount of scene desired. We move
through the scene by moving the viewing reference frame (ie. the viewing coordinate system).
102
Task: Identification and Removal of parts of picture that are not visible from a chosen viewing
position.
Classification of Algorithms: 1. Object-Space Algorithms: algorithms that deal with the object
definition directly visibility is decided by Line of surface by line or surface • Back-Face Removal •
Depth Sorting (Painter Algorithm) • Area Subdivision (Quadtrees and Octrees) • Binary Space Partition
Trees
2. Image-Space Methods algorithms that deal with the projected image visibility is decided
point by point • Depth Buffer (Z-buffer) • Scan-line • Depth sorting (Painter Algorithm)
Both classes use sorting and coherence methods: sorting – to facilitate depth comparison coherence
– to exploit regularities in a scene
- Viewing - Looking along any projector (from center of projection, for example) we see one or
more surfaces.
Hidden Line - when outline of an object is to be displayed - similar to clipping a line segment
against a window - most surface algorithms can be applied for hidden line elimination.
Hidden Line Removal - assumes that objects are modeled with lines.
- if only the visible surfaces are drawn, the invisible lines are automatically eliminated.
ABCD, DCEF, ADFG are visible. Therefore, all lines are visible, that is, AB, DC, FE, AG, … ,
BC, CE, GF.
AGHB, GHEF, BHEC are invisible surfaces Therefore, BH, HE, … are invisible and must be
removed.
Example:
if we know that A is in front of B, and B is in front of C, we can fill or paint C followed by paint B,
and finally paint A onto the display.
103
The Concept: - if we have K objects, take one of the objects and determine its relationship to
each of the other K-1 objects, then: either : paint discard partially paint repeat recursively: we
do this operation: (K-1)+(K-2)+…+ 2 + 1 = K(K-1)/2 times
When we view a picture containing non-transparent objects and surfaces, then we cannot see those
objects from view which are behind from objects closer to eye. We must remove these hidden surfaces to
get a realistic screen image. The identification and removal of these surfaces is called Hidden-surface
problem.
There are two approaches for removing hidden surface problems − Object-Space
method and Image-space method. The Object-space method is implemented in physical coordinate
system and image-space method is implemented in screen coordinate system.
When we want to display a 3D object on a 2D screen, we need to identify those parts of a screen
that are visible from a chosen viewing position.
In this method each surface is processed separately one pixel position at a time across the surface.
The depth values for a pixel are compared and the closest (smallest z) surface determines the color to be
displayed in the frame buffer.
It is applied very efficiently on surfaces of polygon. Surfaces can be processed in any order. To
override the closer polygons from the far ones, two buffers named frame buffer and depth buffer, are
used.
Depth buffer is used to store depth values for (x, y) position, as surfaces are processed (0 ≤ depth
≤ 1).
The frame buffer is used to store the intensity value of color value at each position (x, y).
The z-coordinates are usually normalized to the range [0, 1]. The 0 value for z-coordinate indicates
back clipping pane and 1 value for z-coordinates indicates front clipping pane.
104
Algorithm
Step-1 − Set the buffer values −
Depthbuffer (x, y) = 0
If Z >depthbuffer (x, y)
setdepthbuffer (x, y) = z,
Advantages
● It is easy to implement.
Disadvantages
105
● It requires large memory.
The Edge Table − It contains coordinate endpoints of each line in the scene, the inverse slope of
each line, and pointers into the polygon table to connect edges to surfaces.
The Polygon Table − It contains the plane coefficients, surface material properties, other surface
data, and may be pointers to the edge table.
To facilitate the search for surfaces crossing a given scan-line, an active list of edges is formed. The
active list stores only those edges that cross the scan-line in order of increasing x. Also a flag is set for
each surface to indicate whether a position along a scan-line is either inside or outside the surface.
Pixel positions across each scan-line are processed from left to right. At the left intersection with a
surface, the surface flag is turned on and at the right, the flag is turned off. You only need to perform
depth calculations when multiple surfaces have their flags turned on at a certain scan-line position.
106