Computer Graphics Handout
Computer Graphics Handout
Computer Graphics Handout
pixels.
We can control intensity and color of pixel which decide how picture look like.
·The special procedure determines which pixel will provide the best approximation to the
desired picture or graphics object this process is known as Rasterization.
·The process of representing continuous picture or graphics object as a collection of
discrete pixels is called Scan Conversion.
The term computer graphics has been used to define “almost everything on the computer,
including text or sound.” Generally, the term computer graphics refer to the following things:
Computer graphics study is a sub-field of computer science that studies methods for
digitally incorporating and manipulating visual content.
The next area of computer graphics that deals with the placement of a triangle is
called transformation. Here we can use matrices to get the mapping of a triangle in image space.
We can also set up the transformation matrix to con trol the location and orientation of the
displayed image. We can also resize the triangle.
In interactive computer graphics, users have some controls over the image, i.e., the user can
make any changes to the image produced.
Interactive Computer Graphics involves computer-user two-way communication.
For Example:
Ping-pong game.
Television monitor
1. Display controller or video controller- It’s a Memory Buffer and TV Monitor interface. Its
task is to pass Frame Buffer’s contents to the monitor. The display controller reads each
continuous byte of Memory frame buffer data and converts 0’s and 1’s into appropriate video
signals.
In today’s term, the display controller is recognized as a display card, and one of our choices can
be a VGA(Video Graphics Array) card with a resolution of 640×480. Display Controller is also
capable of displaying the image in colors.
2. Digital memory or frame buffer-This is a place where images and pictures are stored as an
array (matrix of 0 & 1, 0 represents darkness, and 1 represents image or picture). It is also called
a frame buffer.
In today’s term frame buffer is called V-RAM (video RAM), and it helps to store the image in
bit form. It helps to increase the speed of graphics.
3. Television monitor- Monitor helps us to view the display, and they make use of
CRT(Cathode ray tube) technology.
Advantages
1. Superior Quality.
3. Increased Productivity.
Non-interactive computer graphics are also known as passive computer graphics. It is a type of
computer graphics in which the user has no control over the image. The photo is completely
controlled by the instructions of the program, not by the user.
For Example:
Screen savers.
Graphic elements are used in the text, document, and PDF presentation.
Business graphics are used as brochures, business cards, menu of the hotel.
Raster Graphics: In raster graphics, the image is presented as a rectangular grid of colored
squares.
Raster images are also called bitmap images. Bitmap images are stored as the collection of small
individual dots called pixels.
Bitmap images require high resolution and anti-aliasing for a smooth appearance.
Raster images are the collection of the pixel. The Vector images are composed of paths.
Raster image takes less space to store. Vector image takes more space.
Raster graphics can draw mathematical curves, Vector graphics can only draw continuous
File Extension: .BMP, .TIF, .JPG etc. File Extension: .SVG, .PDF, .AI etc.
1940-1941: The first di recently digital computer-generated graphics that would associate with
today as being actual CG. The very first radiosity image was invented at MIT in the 1940s.
1946: The images were first presented at the 1946 national technical conference of the
Illuminating Engineering Society of North America.
1948: The images were published in the book: Lighting Design by Moon and D. E. Spencer.
1948.
1950: John Whitney Sr. invents his computer-assisted mechanisms to create some of his
graphic artwork and short films.
1951: Vectorscope computer graphics display on the computer at MIT.
The General Motors Research Laboratory also begins the study of computer-aided graphical
design applications.
1955: Sage system uses the first light pen as an input device at MIT Lab by Bert Sutherland.
1956: Lawrence Livermore labs associate graphics display with IBM 704 and film recorder for
color images.
Bertram Herzog uses analog computers to create CRT graphics in the behavior of military
vehicles at the University of Michigan computing center.
1957: In the National Bureau of Standards first image-processed photo was used.
The IBM 740 created a sequence of points on a CRT monitor to represent lines and shapes.
1958: Steven Coons, Ivan Sutherland, and Timothy Johnson started working with the TX-2
computer system to manipulate the drawn pictures.1959: The first commercial film recorder
produced in San Diego, CA.
Don Hart and Ed Jacks invented the first computer-aided drawing system at General Motors
Research Laboratory and IBM.
1960: William Fetter was first termed “Computer Graphics” for cockpit drawing.
John Whitney Sr. invents motion graphics in LA.
1962: In MIT Lincoln Laboratory Ivan Sutherland produced a man-machine graphical
communication system.
1963: An analog computer was developed by Charles Csuri and used to transform a drawing.
Edgar Horwood introduced a computer graphics mapping system which is used by U. S.
Housing and urban development.
1965: IBM 2250, the first graphics computer available.
1966: Ralph Baer developed the first consumer computer graphics game, “Odyssey.”
1968: Tony Pritchett made the first computer animation “FLEXIPEDE” in the UK.
1972: Nolan Bushnell, “the father of Electronic games,” developed PONG game.
1973: The concept of Z-buffer algorithm and texture mapping were developed by Edwin
Catmull.
1974: The Phong shading method is developed by Phong Bui-Toung.
1975: Dr. Edwin Catmull introduced the Tween animation system.
1976: The first 3D appearance film was created by Gary Demos, John Whitey Jr. at Triple-I.
1978: For the mechanical Universe Jim Blinn produced the first series of animation. Jim Blinn
has also published the technique of bump mapping.
1979: Ray tracing created at Bell Laboratory & Cornell University.
1980: The first digital computer was used in computer graphics in the Digital Equipment
Corporation (DEC).
1981: The making of computer graphics for IMAX film format is done by Nelson Max at
Lawrence Liver more National Laboratory. The Donkey Kong video game was introduced by
Nintendo.
1982: The first broad use of 3D graphics animation was done in Disney featured film.
AutoCAD 1.0 is launched-It is only used for wire frame representation.
1985: Medical imaging software combined with Voxel technology.
1987: Video graphics array (VGA) standard was introduced.
1989: Super video graphics array (SVGA) was recommended. Tim Berners Lee developed the
first website ever, which has the original URL (Universal resource locator).
1993: Mosaic, the web browser was released by UIUC for general usage. The Codename of
mosaic was “Mozilla.”
The Mosaic, the first web browser was released. First public call made by cell phone.
1994: Netscape founded by developers of the Mosaic.
1995: First, fully CGI (Computer-generated imagery) was released. MS Internet Explorer 1.0
released.
2000: The first web-based CAD system Sketchup released.
2006: Google acquires Sketchup.
2009: The state of the art of computer graphics, as of 2009, was brief in a short video.
2013: Now, it is possible to create graphics on a home computer.
2015: Big data is being used to create animations.
2018: Now, we can create “realistic” graphics on mobile phones. We can also create a
completely CGI-based human face in real-time.
Computer Graphics has numerous applications, some of which are listed below −
Typography − The use of character images in publishing - replacing the hard type of the
past.
Architecture − Construction plans, exterior sketches - replacing the blueprints and hand
drawings of the past.
Presentations: Computer graphics are used for making charts, bar diagrams, and other
images for the presentation purpose, with the graphical presentation the user, can easily
understand the points.
Education and Training: Computer graphics are also used to provide training to
students with simulators. The students can learn about the machines without physically
trying them.
Medical Imaging: MRIs, CT scans, and other internal scans are possible because of
computer graphics.
Flight Simulator: Computer graphic is used to provide training to pilots of aircraft. The
pilots give much time to a flight simulator on the ground instead of real airplanes.
Printing Technology: Computer graphics are used in textile designing and flex printing.
Cartography: Computer graphics are used in map drawing.
Increase Productivity
Computer graphics give us tools for creating pictures of solid objects as well as of
theoretical, engineered objects.
The computer can store complex drawings and display complex pictures.
Sound cards are used to make computers produce sound effects led to other uses of
graphics.
Technical issues.
Graphics hardware is the hardware components to quickly render3D objects as pixels on your
computer screen.
Graphics Hardware includes
Display (CRT, LCD, LED, Plasma panels …)
Graphics accelerator
Scan controller
Video Memory (frame buffer)
Display/Graphics Processor
CPU/Memory/Disk …
Today's graphics hardware do have great processing and rendering capacity.
There are two ways (Random scan and Raster scan) by which we can display an object on the
screen.
1. 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.
In this technique, the electron beam is directed only to the part of the screen where the picture is
to be drawn rather than scanning from left to right and top to bottom as in raster scan. It is also
called vector display, stroke-writing display, or calligraphic display.
Picture definition is stored as a set of line-drawing commands in an area of memory referred to
as the refresh display file. To display a specified picture, the system cycles through the 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.
Flat panels are used in calculators, pocket video games and laptop computers. There are two
categories of flat panel displays such as:
Emissive Display (Plasma Panels)
Two glass plates, each containing a light polarizer at right angles to the other plate, sandwich the
liquid-crystal material. Rows of horizontal transparent conductors are built into one glass plate,
and columns of vertical conductors are put into the other plate. The intersection of two
conductors defines a pixel position. Polarized light passing through the material is twisted so that
it will pass through the opposite polarizer. The light is then reflected back to the viewer. To turn
off the pixel, we apply a voltage to the two intersecting conductors to align the molecules so that
the light is not twisted.
Virtual reality system enables users to move and react in a computer-simulated environment.
Various types of devices allow users to sense and manipulate virtual objects much as they would real
objects. This natural style of interaction gives participants the feeling of being immersed in the
simulated world. Virtual reality simulations differ from other computer simulations in that they
require special interface devices that transmit the sights, sounds, and sensations of the simulated
world to the user. These devices also record and send the speech and movements of the participants
to the simulation program.
Hercules Adapter (HA): The Hercules card emulates the monochrome adapter but also
operates in a graphics mode. Having graphics capabilities the Hercules card became
somewhat of a standard for monochrome systems.
Color Graphics Adapter (CGA): This adapter can display text as well as graphics. In
text mode it operates in 25 rows by 80 column mode with 16 colors. In graphics mode
two resolutions are available:
Medium resolution graphics mode 320 * 200 with 4 colors available from palette
of 16 colors.
and 640 * 200 with 2 colors.
One drawback of CGA card is that it produces flicker and snow. Flicker is the annoying
tendency of the text to flash as it moves up or down. Snow is the flurry of bright dots that
can appear anywhere on the screen.
Enhanced Graphics Adapter (EGA): The EGA was introduced by IBM in 1984 as
alternative to CGA card. The EGA could emulate most of the functions and all the
display modes of CGA and MA. The EGA offered high resolution and was not plagued
with the snow and flicker problems of CGA. In addition EGA is designed to use the
enhanced color monitor capable of displaying 640 * 350 in 16 colors from a palette of 64.
The EGA card has several internal registers. A serious limitation of the EGA card is that
it supports write operations to most of its internal registers, but no read operation. The
result is it is not possible for software to detect and preserve the state of the adapter,
which makes EGA unsuited for memory resident application or for multitasking like
windows and OS/2.
Multicolor Graphics Adapter (MCGA): The MCGA was designed to emulate the
CGA card and to maintain compatibility with all the CGA modes. In addition to the text
and graphics modes of the CGA, MCGA has two new graphics modes:
640 * 480 with 2 colors
320 * 200 in with 256 colors
Video Graphics Adapter (VGA): The VGA supports all the display modes of MA,
CGA and MCGA. In addition VGA supports a graphics mode of 640 * 480 with 16
colors.
How much RAM? That is significant for color depth at the highest resolutions. Which type of
RAM? This is significant for card speed.
Video card RAM is necessary to keep the entire screen image in memory. The CPU sends its
data to the video card. The video processor forms a picture of the screen image and stores it in
the frame buffer. This picture is a large bit map. It is used to continually update the screen image.
3D - lots of RAM
Supporting the demand for high quality 3D performance many new cards come with a frame
buffer of 16 or 32 MB RAM and they use the AGP interface for better bandwidth and access to
the main memory.
VRAM
Briefly, in principle all common RAM types can be used on the video card. Most cards use very
fast editions of ordinary RAM (SDRAM or DDR).
Some high end cards (like Matrox Millennium II) earlier used special VRAM (Video RAM)
chips. This was a RAM type, which only was used on video cards. In principle, a VRAM cell is
made up of two ordinary RAM cells, which are "glued" together. Therefore, you use twice as
much RAM than otherwise.
VRAM also costs twice as much. The smart feature is that the double cell allows the video
processor to simultaneously read old and write new data on the same RAM address. Thus,
VRAM has two gates which can be active at the same time. Therefore, it works significantly
faster.
With VRAM you will not gain speed improvements increasing the amount of RAM on the
graphics controller. VRAM is already capable of reading and writing simultaneously due to the
dual port design.
UMA and DVMT
On some older motherboards the video controller was integrated. Using SMBA (Shared Memory
Buffer Architecture) or UMA (Unified Memory Architecture) in which parts of the system RAM
were allocated and used as frame buffer. But sharing the memory was very slow and the
standards never became very popular.
A newer version of this is found in Intel chip set 810 and the better 815, which also integrates the
graphics controller and use parts of the system RAM as frame buffer. Here the system is called
Dynamic Video Memory Technology (D.V.M.T.).
The RAMDAC
All traditional graphics cards have a RAMDAC chip converting the signals from digital to
analog form. CRT monitors work on analog signals. The PC works with digital data which are
sent to the graphics adapter. Before these signals are sent to the monitor they have to be
converted into analog output and this is processed in the RAMDAC:
The recommendation on a good RAMDAC goes like this:
External chip, not integrated in the VGA chip
Clock speed: 250 – 360 MHz.
With accelerated video chips, Windows (and with that the CPU) need not calculate and design
the entire bit map from image to image. The video card is programmed to draw lines, Windows
and other image elements.
The CPU can, in a brief code, transmit which image elements have changed since the last
transmission. This saves the CPU a lot of work in creating screen images. The video chip set
carries the heavy load:
All video cards are connected to the PCI or the AGP bus, this way providing maximum data
transmission. The AGP bus is an expanded and improved version of the PCI bus - used for video
cards only.
Modern video cards made for 3D gaming use expensive high-end RAM to secure a sufficient
bandwidth. If you for example want to see a game in a resolution of 1280 x 1024 at 80 Hz, you
may need to move 400 MB of data each second - that is quite a lot. The calculation goes like this:
1280 X 1024 pixels x 32 bit (color depth) x 80 = 419,430,400 bytes
419,430,400 bytes = 409,600 kilobytes = 400 megabytes.
It is a software interface for graphics hardware; OpenGL renders multidimensional objects into a
frame buffer. OpenGL is industry-standard graphics software with which programmers can
create high-quality motionless and animated three-dimensional colour images.
OpenGL is the premier environment for developing portable, interactive 2D and 3D graphics
applications. Since its introduction in 1992, OpenGL has become the industries
most widely used and supported 2D and 3D graphics application programming interface (API),
bringing thousands of applications to a wide variety of computer platforms. OpenGL promote
innovation and speeds application development by incorporating a broad set of rendering, texture
mapping, special effects, and other powerful visualization functions. Developers can leverage the
power of OpenGL across all popular desktop and workstation platforms, ensuring wide
application deployment.
announced in time for developers to adopt changes. Backward compatibility requirements ensure
that existing applications do not become obsolete.
Reliable and portable: All OpenGL applications produce consistent visual display results on
any OpenGL API-compliant hardware, regardless of operating system or windowing system.
Evolving: Because of its thorough and forward-looking design, OpenGL allows new hardware
innovations to be accessible through the API via the OpenGL extension mechanism. In this way,
innovations appear in the API in a timely fashion, letting application developers and hardware
vendors incorporate new features into their normal product release cycles.
Scalable: OpenGL API-based applications can run on systems ranging from consumer
electronics to PCs, workstations, and supercomputers. As a result, applications can scale to any
class of machine that the developer chooses to target.
Easy to use: OpenGL is well structured with an intuitive design and logical commands. Efficient
OpenGL routines typically result in applications with fewer lines of code than those that make up
programs generated using other graphics libraries or packages. In addition, OpenGL drivers
encapsulate information about the underlying hardware, freeing the application developer from
having to design for specific hardware features.
Well-documented: Numerous books have been published about OpenGL, and a great deal of
sample code is readily available, making information about OpenGL inexpensive and easy to
obtain.
Simplifies Software Development
Open GL routines simplify the development of graphics software from rendering a simple
geometric point, line, or filled polygon to the creation of the most complex lighted and texture-
mapped NURBS curved surface. OpenGL gives software developers access to geometric and
image primitives, display lists, modelling transformations, lighting and texturing, anti-aliasing,
blending, and many other features. Every conforming OpenGL implementation includes the full
complement of OpenGL functions. The well-specified OpenGL standard has language bindings
for C, C++, Fortran, Java.
Available everywhere
Supported on all UNIX workstations, and shipped standard with every Windows 95/98/2000/NT
and MacOS PC, no other graphics API operates on a wider range of hardware platforms and
software environments. OpenGL runs on every major operating system including Mac OS, OS/2,
UNIX, Windows 95/98, Windows 2000, Windows NT, Linux, OPENStep, and BeOS; it also
works with every major windowing system including Win32, MacOS, Presentation Manager,
and X-Window System. OpenGL is callable from Ada, C, C++, Fortran, Python, Perl and Java
and offers complete independence from network protocols and topologies.
Architected for Flexibility and Differentiation
Although the OpenGL specification defines a particular graphics processing pipeline, platform
vendors have the freedom to tailor a particular OpenGL implementation to meet unique system
cost and performance objectives. Individual calls can be executed on dedicated hardware, run as
software routines on the standard system CPU, or implemented as a combination of both
dedicated hardware and software routines. This implementation flexibility means that OpenGL
hardware acceleration can range from simple rendering to full geometry and is widely available
on everything from low-cost PCs to high-end workstations and supercomputers. Application
developers are assured consistent display results regardless of the platform implementation of the
OpenGL environment.
Using the OpenGL extension mechanism, hardware developers can differentiate their products
by developing extensions that allow software developers to access additional performance and
technological innovations.
Windows or Linux etc because it is platform independent. “glut” can create window, get
keyboard input and run an event handler or message loop in our graphics application.
All those functions that start with the prefix “gl” are the core OpenGL functions and those which
start with “glu” or “glut” are the OpenGL utility library functions.
Example-1: Let’s write a program that uses “glut” and then uses OpenGL function to
create graphics.
#include <GL/glut.h>
int main()
glutCreateWindow
Usage
int glutCreateWindow(char *name);
name:
ASCII character string for use as window name.
Description: glutCreateWindow creates a top-level window. The name will be provided to the
window system as the window's name. The intent is that the window system will label the
window with the name.
Example 2: Now we will use more features of “glut” library.
#include <GL/glut.h>
int main()
{
//Set up the OpenGL rendering context.
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
//Create a window and set its width and height.
glutCreateWindow( "Deform" );
glutReshapeWindow( 640, 480 );
//The keyboard function gets called whenever we hit a key.
glutKeyboardFunc( keyboard );
//The display function gets called whenever the window
//requires an update or when we explicitly call
glutDisplayFunc( display );
//The reshape function gets called whenever the window changes
//shape.
glutReshapeFunc( reshape );
// The idle function gets called when there are no window-
// events to process.
glutIdleFunc( idle );
//Get the ball rolling!
glutMainLoop();
}
In the above program we have used “glut” functions. Let us discuss them in detail.
GlutInitDisplayMode
glutInitDisplayMode sets the initial display mode.
Usage
void glutInitDisplayMode(unsigned int mode);
mode
Display mode, normally the bitwise OR-ing of GLUT display mode bit masks. See values below:
GLUT_RGBA
Bit mask to select an RGBA mode window. This is the default if neither
GLUT_RGBA nor GLUT_INDEX are specified.
GLUT_RGB
An alias for GLUT_RGBA.
GLUT_INDEX
Bit mask to select a color index mode window. This overrides GLUT_RGBA if it
is also specified.
GLUT_SINGLE
Bit mask to select a single buffered window. This is the default if neither
GLUT_DOUBLE or GLUT_SINGLE are specified.
GLUT_DOUBLE
Description
The initial display mode is used when creating top-level windows, sub windows, and overlays to
determine the OpenGL display mode for the to-be-created window or overlay.
Note that GLUT_RGBA selects the RGBA color model, but it does not request any bits of alpha
(sometimes called an alpha buffer or destination alpha) be allocated. To request alpha, specify
GLUT_ALPHA. The same applies to GLUT_LUMINANCE.
Example-2: Consider case of another line with points p1 (10, 10) and p2 (16, 20)
Now the difference between y coordinates that is dy = y2 – y1 = 20 – 10 = 10
Whereas difference between x coordinates is dx = x2 – x1 = 16 – 10 = 6
This means that there will be 10 pixels on the line in which for x-axis there will be distance of
0.6 between each pixel and for y-axis the distance will be 1.
Now having discussed this concept at length let us now understand the algorithm to draw a line
using above technique which is called as incremental line algorithm:
Incremental_Line (Point p1, Point p2)
dx = p2.x – p1.x
dy = p2.y – p1.y
m = dy / dx
x = p1.x
y = p1.y
b=y–m*x
if |m| < 1
for counter = p1.x to p2.x
drawPixel (x, y)
x=x+1
y=m*x+b
else
for counter = p1.y to p2.y
drawPixel (x, y)
y=y+1
x=(y–b)/m
Hence the above algorithm is quite simple and easy as it involves lot of mathematical
calculations that is for calculating coordinate using equation each time and secondly it works
only in incremental direction.
if |dx|>|dy| then
step = |dx|
else
step = |dy|
Now it is very simple to say that step is the total number of pixel required for a line. Next
step is to divide dx and dy by step to get xIncrement and yIncrement that is the increment
required in each step to find next pixel value.
xIncrement = dx/step
yIncrement = dy/step
Next a loop is required that will run step times. In the loop drawPixel and add xIncrement in x1
by and yIncrement in y1.
To sum-up all above in the algorithm, we will get,
DDA_Line (Point p1, Point p2)
dx = p2.x – p1. x
dy = p2.y – p1. y
x1=p1.x
y1=p1.y
if |dx|>|dy| then
step = |dx|
else
step = |dy|
xIncrement = dx/step
yIncrement = dy/step
for counter = 1 to step
drawPixel (x1, y1)
x1 = x1 + xIncrement
y1 = y1 + yIncrement
p = 2dy-dx
c1 = 2dy
c2 = 2(dy-dx)
x = x1
y = y1
plot (x,y,colour)
while (x < x2 )
x++;
if (p < 0)
p = p + c1
else
p = p + c2
y++
plot (x,y,colour)
Again, this algorithm can be easily generalized to other arrangements of the end points of the
line segment, and for different ranges of the slope of the line.
A pixel is represented by a dot or square on a computer monitor display screen. Pixels are the
basic building blocks of a digital image or display and are created using geometric coordinates.
Depending on the graphics card and display monitor, the quantity, size and color combination of
pixels varies and is measured in terms of the display resolution.
For example, a computer with a display resolution of 1280 x 768 will produce a maximum of
98,3040 pixels on a display screen. Each pixel has a unique logical address, a size of eight bits or
more and, in most high-end display devices, the ability to project millions of different colors.
The pixel resolution spread also determines the quality of display; more pixels per inch of
monitor screen yields better image results.
Setting a Pixel
Initial Task: Turning on a pixel (loading the frame buffer/bit-map). Assume the simplest case,
i.e., an 8-bit, non-interlaced graphics system. Then each byte in the frame buffer corresponds to a
pixel in the output display.
To find the address of a particular pixel (X,Y) we use the following formula:
addr(X, Y) = addr(0,0) + Y rows * (Xm + 1) + X (all in bytes)
addr(X,Y) = the memory address of pixel (X,Y)
addr(0,0) = the memory address of the initial pixel (0,0)
Number of rows = number of raster lines.
Number of columns = number of pixels/raster line.
Example: For a system with 640 × 480 pixel resolution, find the address of pixel X = 340, Y
= 150?
Solution: addr(340, 150) = addr(0,0) + 150 * 640 (bytes/row) + 340
= base + 96,340 is the byte location
Graphics system usually have a command such as set_pixel (x, y) where x, y are integers.
This technique uses the equation for a circle on radius r centred at (0, 0) given as:
Obviously in most of the cases the circle is not centered at (0, 0), rather there is a center point (Xc,
yc); other than (0, 0). Therefore the equation of the circle having center at point (Xc, yc).
Using above equation a circle can easily be drawn. The value of x varies from r – xc to r + xc .
Whereas y will be calculated using above formula. Using this technique we can write a simple
algorithm:
A better approach, to eliminate unequal spacing as shown in above figure is to calculate points
along with the circular boundary using polar coordinates r and θ expressing the circle equation in
parametric polar form yields the pair of equations:
Using above equation circle can be plotted by calculating x and y coordinates as θ takes values
from 0 to 360 degrees or 0 to . The step size chosen for θ depends on the application and the
display device. Larger angular separations along the circumference can be connected with
straight-line segments to approximate the circular path. For a more continuous boundary on a
raster display, we can set the step size at 1/r. This plots pixel positions that are approximately
one unit apart.
Now let us see how this technique can be sum up in algorithmic form.
Again this is very simple technique and also solves problem of unequal space but unfortunately
this technique is still inefficient in terms of calculations involves especially floating point
calculations.
Calculations can be reduced by considering the symmetry of circles. The shape of circle is
similar in each quadrant. We can generate the circle section in the second quadrant of the xy-
plane by noting that the two circle sections are symmetric with respect to the y axis and circle
sections in the third an fourth quadrants can be obtained from sections in the first and second
quadrants by considering symmetry about the x axis. We can take this one step further and note
that there is also symmetry between octants. Circle sections in adjacent octants within one
quadrant are symmetric with respect to the 450 line dividing the two octants. These symmetry
conditions are illustrated in above figure. Therefore above algorithm can be optimized by using
symmetric octants. Let’s see:
As in the Bresenham line drawing algorithm we derive a decision parameter that helps us to
determine whether or not to increment in the y coordinate against increment of x coordinate or
vice versa for slope > 1. Similarly here we will try to derive decision parameter which can give
us closest pixel position.
Let us consider only the first octant of a circle of radius r centred on the origin. We begin by
plotting point (r, 0) and end when x < y.
The decision at each step is whether to choose the pixel directly above the current pixel or the
pixel; which is above and to the left (8-way stepping).
The circle function tests given above are performed for the midpoints between pixels near the
circle path at each sampling step. Thus, the circle function is the decision parameter in the
midpoint algorithm, and we can set up incremental calculations for this function as we did in the
line algorithm.
Figure below shows the midpoint between the two candidate pixels at sampling position xk+1.
Assuming we have just plotted the pixel at (xk, yk), we next need to determine whether the pixel
at position (xk+1, yk), we next need to determine whether the pixel at position (xk+1, yk), or the
one at position (xk+1, yk-1) is closer to the circle. Our decision parameter is the circle function
evaluated at the midpoint between these two pixels:
If pk<0, this midpoint is inside the circle and the pixel on scan line yk is closer to the circle
boundary. Otherwise, the mid position is outside or on the circle boundary, and we select the
pixel on scan-line yk -1.
Successive decision parameters are obtained using incremental calculations. We obtain a
recursive expression for the next decision parameter by evaluating the circle function at sampling
position
Where yk+1 is either yk or yk-1, depending on the sign of Pk. Therefore, if Pk < 0 or negative then yk
+1 will be yk and the formula to calculate Pk+1 will be:
Otherwise, if Pk > 0 or positive then yk+1 will be yk-1 and the formula to calculate Pk+1 will
be:
Now a similar case that we observe in line algorithm is that how would starting Pk be evaluated.
For this at the start pixel position will be ( 0, r ). Therefore, putting this value is equation, we get
Since all increments are integer. Finally sum up all in the algorithm:
Now let us consider an example to calculate first octant of the circle using above algorithm;
while one quarter is displayed where you can observe that exact circle is passing between the
points calculated in a raster circle.
If the answer is no, the polygon is convex. This means that for any scan-line, the scanline will
cross at most two polygon edges (not counting any horizontal edges). Convex polygon edges
also do not intersect each other.
Concave: Concave polygons are a superset of convex polygons, having fewer restrictions than
convex polygons. The line connecting any two points that lie inside the polygon may intersect
more than two edges of the polygon. Thus, more than two edges may intersect any scan line that
passes through the polygon. The polygon edges may also touch each other, but they may not
cross one another.
Complex: Complex polygons are just what their name suggests: complex. Complex polygons
are basically concave polygons that may have self-intersecting edges. The complexity arises
from distinguishing which side is inside the polygon when filling it.
In order to determine which pixels are inside the polygon, the odd-parity rule is used within the
scan-line polygon fill algorithm.
4.3.1 Parity
Dept of CS MTU Page 48
Computer Graphics CoSc-3121 2022
Parity is a concept used to determine which pixels lie within a polygon, i.e. which pixels should
be filled for a given polygon.
The Underlying Principle: Conceptually, the odd parity test entails drawing a line segment
from any point that lies outside the polygon to a point P, which we wish to determine whether it
is inside or outside of the polygon. Count the number of edges that the line crosses. If the number
of polygon edges crossed is odd, then P lies within the polygon. Similarly, if the number of
edges is even, then P lies outside of the polygon. There are special ways of counting the edges
when the line crosses a vertex. Examples of counting parity can be seen in the following
demonstration.
Step 1 − Find out the Ymin and Ymax from the given polygon.
Step 2 − ScanLine intersects with each edge of the polygon from Ymin to Ymax. Name each
intersection point of the polygon. As per the figure shown above, they are named as p0, p1, p2,
p3.
Step 3 − Sort the intersection point in the increasing order of X coordinate i.e. (p0, p1), (p1, p2),
and (p2, p3).
Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the alternate pairs.
Algorithm
Step 1 − Initialize the value of seed point (seedx, seedy), fcolor and dcol.
Step 2 − Define the boundary values of the polygon.
Step 3 − Check if the current seed point is of default color, then repeat the steps 4 and 5 till the
boundary pixels reached.
If getpixel(x, y) = dcol then repeat step 4 and 5
Step 4 − Change the default color with the fill color at the seed point.
setPixel(seedx, seedy, fcol)
Step 5 − Recursively follow the procedure with four neighborhood points.
FloodFill (seedx – 1, seedy, fcol, dcol)
FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)
Step 6 − Exit
There is a problem with this technique. Consider the case as shown below where we tried to fill
the entire region. Here, the image is filled only partially. In such cases, 4-connected pixels
technique cannot be used.
Algorithm
Step 1 − Initialize the value of seed point (seedx, seedy), fcolor and dcol.
Step 2 − Define the boundary values of the polygon.
Step 3 − Check if the current seed point is of default color then repeat the steps 4 and 5 till the
boundary pixels reached.
If getpixel(x,y) = dcol then repeat step 4 and 5
Step 4 − Change the default color with the fill color at the seed point.
setPixel(seedx, seedy, fcol)
Step 5 − Recursively follow the procedure with four neighborhood points
FloodFill (seedx – 1, seedy, fcol, dcol)
FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx, seedy + 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)
FloodFill (seedx + 1, seedy + 1, fcol, dcol)
FloodFill (seedx + 1, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy - 1, fcol, dcol)
Step 6 − Exit
The 4-connected pixel technique failed to fill the area as marked in the following figure which
won’t happen with the 8-connected technique.
Odd-Even Rule
In this technique, we will count the edge crossing along the line from any point (x,y) to infinity.
If the number of interactions is odd, then the point (x,y) is an interior point; and if the number of
interactions is even, then the point (x,y) is an exterior point. The following example depicts this
concept.
From the above figure, we can see that from the point (x,y), the number of interactions point on
the left side is 5 and on the right side is 3. From both ends, the number of interaction points is
odd, so the point is considered within the object.
In another alternative method, give directions to all the edges of the polygon. Draw a scan line
from the point to be test towards the left most of X direction.
Give the value 1 to all the edges which are going to upward direction and all other -1 as
direction values.
Check the edge direction values from which the scan line is passing and sum up them.
If the total sum of this direction value is non-zero, then this point to be tested is
an interior point, otherwise it is an exterior point.
In the above figure, we sum up the direction values from which the scan line is passing
then the total is 1 – 1 + 1 = 1; which is non-zero. So the point is said to be an interior
point.
Homogeneous Coordinates
To perform a sequence of transformation such as translation followed by rotation and scaling,
we need to follow a sequential process −
Translate the coordinates,
Rotate the translated coordinates, and then
Scale the rotated coordinates to complete the composite transformation.
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).
Basically there are 5 types of 2D Transformations such as Translation, Rotation, Scaling, Sheer
and Reflection.
2.1.1 Translation
A translation moves an object to a different position on the screen (i.e change in the position).
You can translate a point in 2D by adding translation coordinate (tx, ty) to the original coordinate
(X, Y) to get the new coordinate (X’, Y’).
We can write it as −
P’ = P + T
2.1.2 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 –
Substituting equation (1) & (2) in (3) & (4) respectively, we will get
P’ = P . R
Where R is the rotation matrix
For positive rotation angle, we can use the above rotation matrix. However, for negative angle
rotation, the matrix will change as shown below –
2.1.3 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 (SX, SY), and the
produced coordinates are (X’, Y’). This can be mathematically represented as shown below –
The scaling factor SX, SY scales the object in X and Y direction respectively. The above
equations can also be represented in matrix form as below –
Or P’ = P . S
Where S is the scaling matrix. The scaling process is shown in the following figure.
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.
2.1.4 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.
2.1.5 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
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.
2.3.2 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 –
Dept of CS MTU Page 64
Computer Graphics CoSc-3121 2022
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) respectively, and the produced coordinates are
(X’, Y’, Z’). This can be mathematically represented as shown below-
2.3.3 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.
As shown in the above figure, there is a coordinate P. You can shear it to get a new coordinate P',
which can be represented in 3D matrix form as below –
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 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 −
The following figure shows all the three types of perspective projection –
2.6 Translation
In 3D translation, we transfer the Z coordinate along with the X and Y coordinates. The process
for translation in 3D is similar to 2D translation. A translation moves an object into a different
position on the screen. The following figure shows the effect of translation −
A point can be translated in 3D by adding translation coordinate (tx, ty, tz) to the original
coordinate (X, Y, Z) to get the new coordinate (X’, Y’, Z’).
x2 + y2 - R2 = 0
Explicit Curves
A mathematical function y = f(x) can be plotted as a curve. Such a function is the explicit
representation of the curve. The explicit representation is not general, since it cannot represent
vertical lines and is also single-valued. For each value of x, only a single value of y is normally
computed by the function.
Parametric Curves
Curves having parametric form are called parametric curves. The explicit and implicit curve
representations can be used only when the function is known. In practice the parametric curves
are used. A two-dimensional parametric curve has the following form:
P(t) = f(t), g(t) or P(t) = x(t), y(t)
The functions f and g become the (x, y) coordinates of any point on the curve, and the points are
obtained when the parameter t is varied over a certain interval [a, b], normally [0, 1].
Bezier curve was discovered by the French engineer Pierre Bézier. These curves can be
generated under the control of other points. Approximate tangents by using control points are
used to generate curve. The Bezier curve can be represented mathematically as:
Where,
the are the “normalized B-spline blending functions”. They are described by
the order k and by a non-decreasing sequence of real numbers normally called the “knot
sequence”.
And if P2 = (x2, y2, z2) is the starting point and P1 = (x1, y1, z1) is the ending point, then the vector
V = (x1 – x2, y1 – y2, z1 – z2)
Normal Vector
A vector that is perpendicular to a surface, such as a plane or a sphere, is said to be normal to it.
It's therefore called a normal vector. (Other vectors are not abnormal.) Normal vectors for
surfaces are crucial in lighting calculations, because the normal vector tells us the orientation of
the surface, and the orientation is important to how light falls on the surface and where it reflects
to.
A common way to find a normal vector for a plane is to find two vectors that lie in the plane and
take their cross product. To find a normal vector for a surface, find a plane that is tangent at the
desired point, and find the normal vector for that plane.
The Edge table is used to store the edge information of polygon. In the following figure,
edge E1 lies between vertex v1 and v2 which is represented in the table as E1: v1, v2.
Polygon surface table stores the number of surfaces present in the polygon. From the
following figure, surface S1 is covered by edges E1, E2 and E3 which can be represented
in the polygon surface table as S1: E1, E2, and E3.
Ax + By + Cz + D = 0
Where (x, y, z) is any point on the plane, and the coefficients A, B, C, and D are constants
describing the spatial properties of the plane. We can obtain the values of A, B, C, and D by
solving a set of three plane equations using the coordinate values for three non collinear points
in the plane. Let us assume that three vertices of the plane are (x1, y1, z1), (x2, y2, z2) and (x3, y3,
z3).
Let us solve the following simultaneous equations for ratios A/D, B/D, and C/D. You get the
values of A, B, C, and D.
For any point (x, y, z) with parameters A, B, C, and D, we can say that:
Advantages
It can be used to model almost any object.
They are easy to represent as a collection of vertices.
They are easy to transform.
The corner of RGB color cube that is at the origin of the coordinate system corresponds to black,
whereas the corner of the cube that is diagonally opposite to the origin represents white. The
diagonal line connecting black and white corresponds to all the gray colors between black and
white, which is also known as gray axis.
In the RGB color model, an arbitrary color within the cubic color space can be specified by its
color coordinates: (r, g.b).
Example:
(0, 0, 0) for black, (1, 1, 1) for white,
Color specification using the RGB model is an additive process. We begin with black and add on
the appropriate primary components to yield a desired color. The concept RGB color model is
used in Display monitor. On the other hand, there is a complementary color model known
as CMY color model. The CMY color model uses a subtraction process and this concept is used
in the printer.
In CMY model, we begin with white and take away the appropriate primary components to yield
a desired color.
Example:
If we subtract red from white, what remains consists of green and blue which is cyan. The
coordinate system of CMY model uses the three primaries’ complementary colors:
C(cray), M(magenta) and Y(yellow)
The corner of the CMY color cube that is at (0, 0, 0) corresponds to white, whereas the corner of
the cube that is at (1, 1, 1) represents black. The following formulas summarize the conversion
between the two color models:
and printing industry. The extensible feature of this format allows storage of multiple bitmap
images having different pixel depths, which makes it advantageous for image storage needs.
Since it introduces no compression artifacts, the file format is preferred over others for archiving
intermediate files.
Although TIFF does not use compression much compared to other image file formats, it supports
different types of data compression. In the case of photographic images, TIFF makes use of the
Lempel-Ziv-Welch lossless compression method. TIFF files can be either compressed or
uncompressed but are significantly larger than JPEGs and hence consume more space. However,
this format has a few advantages over the JPEG format, such as the ability to store multiple
layered images under a single TIFF file and to use a bit depth of 8 bits per channel or 16 bits per
channel. Again, free exchange is possible between computer platforms and applications that use
TIFF.
A TIFF file uses the file extension ".tif" or ".tiff". TIFF is also known for its flexibility and has
more features and capabilities than other image file formats. Often, these add to the complication
to learn and understand its features. A TIFF file is organized into an image file header, an image
file directory and a bitmap data, with the previous two being considered mandatory.
TIFF is largely used in imaging and 3D applications, medical imaging and desktop publishing.
Most image editing software or applications are capable of working with TIFF files.
TIFF, however, has a few drawbacks. One of them is the lack of mechanism to specify the multi-
layer relationships between different TIFF pages. Also, in some ways, it lacks standard support
for advanced imaging capabilities. Another major drawback lies in the size limitation. As the
format makes use of 32-bit offsets, the file size is limited to 4 gigabytes.
JPEG(.jpg,.jpeg)
The Joint Photographic Experts Group (JPEG) is a commission to maintain standards for image
rendering in technology. The acronym JPEG is much more commonly recognized as a file
extension for image files, representing the standard set by the international JPEG commission. A
JPEG file may also be abbreviated as JPG. This was created in 1986, the Joint Photographic
Experts Group is a product of efforts by the International Organization for Standardization (ISO)
and the International Telecommunication Union (ITU). Efforts to create standards for digital
images led to the creation of JPEG to promote consistency in software and hardware products.
JPEG continues to look at issues of image compression and new technology methods like
wavelets, which can promote a high standard for the creation and use of digital images in many
devices, from computers to handheld devices and other hardware.
It is a very common format and is good for digital cameras, nonprofessional prints, E-Mail,
Powerpoint etc., making it ideal for web use.
GIF(.gif)
The graphics interchange format (GIF) is a type of bitmap image format introduced by
CompuServe back in 1987 that has since gained wide support and use on the World Wide Web.
The format supports up to 8 bits per pixel, allowing an image to have access to a 255-color
palette. The most distinctive feature of GIF is its support for animation, with each frame being
allowed to use a separate palette.
The graphics interchange format became popular because of its use of the LZW (Lempel-Ziv-
Welch) compression method, which reduces the file size without reducing or degrading the
quality of the image. This compression method allows for larger images to be downloaded by
slow modems in a relatively short time. This method is also more efficient than the older run-
length compression method that other image formats like PCX used. Even with its merits, GIF is
not suitable for reproducing high-quality color photographs because of the limitations of its color
palette. It is better suited to other types of graphics like logos, which usually have a lot of solid
areas of color.
PNG(.png)
Portable network graphics (PNG) refers to a raster graphics image format used on websites and
Web applications. It is a type of open and bitmapped graphical file format that is built on the
concept of lossless data compression. It was created and conceived by the World Wide Web
Consortium as a replacement to graphics interchange format (GIF).
Unlike GIF, PNG is completely patent and license free, including its data compression algorithm.
It adds on to a GIF and JPEG image format by providing alpha channels, gamma correction and
a two-dimensional interlacing feature. Its features make it possible to enhance and modify the
image to a greater extent than its predecessors. For example, a PNG image supporting alpha
channel scan can have its background changed without inferring with the rest of its appearance.
It supports up to 48-bit true color and 16-bit grayscale imagery, and doesn’t deteriorate the image
quality if it’s re-saved or formatted. What PNG lacks is multiple-image support that provides the
animations as seen in a GIF.
PNG or Portable Network Graphics files are a lossless image format. It was designed to replace
gif format as gif supported 256 colors unlike PNG which support 16 million colors.
Bitmap(.bmp)
Bitmap (BMP) is an image file format that can be used to create and store computer graphics. A
bitmap file displays a small dots in a pattern that, when viewed from afar, creates an overall
image. A bitmap image is a grid made of rows and columns where a specific cell is given a value
that fills it in or leaves it blank, thus creating an image out of the data.
To create a bitmap, an image is broken into the smallest possible units (pixels) and then the color
information of each pixel (color depth) is stored in bits that are mapped out in rows and columns.
The complexity of a bitmap image can be increased by varying the color intensity of each dot or
by increasing the number of rows and columns used to create the image. However, when a user
magnifies a bitmap image enough, it eventually becomes pixelated as the dots resolve into tiny
squares of color on a grid.
MPEG
The Moving Picture Experts Group (MPEG) is the family of standards and file formats which are
used in digital video. MPEG was developed by the working group formed by IEC and ISO,
which is also known as moving picture experts group. Because of the various sophisticated
compression techniques used, MPEGs, when compared to most audio and video formats, are
smaller in size and more or less of same quality.
For broadcasting applications with limited resources, MPEG is one of the best options as it
allows streaming high quality video on platforms like the Internet. The file format is supported
by most electronic products and can be played using software like Windows Media Player,
Cyberlink PowerDVD, Apple Quick Time Player, etc. MPEG Features:
EPS(.eps)
Encapsulated PostScript file is a common vector file type. EPS files can be opened in
applications such as Adobe Illustrator or CorelDRAW.
RAW Image Files (.raw, .cr2, .nef, .orf, .sr2)
These Files are unprocessed created by a camera or scanner. Many digital SLR cameras can
shoot in RAW, whether it is a .raw, .cr2, or .nef. These images are the equivalent of a digital
negative, meaning that they hold a lot of image information. These images need to be processed
in an editor such as Adobe Photoshop or Lightroom. It saves metadata and is used for
photography.
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.
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.
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 endpoint.
Step 2 − If both endpoints have a region code 0000 then accept this line.
Step 3 − Else, perform the logical AND operation for both region codes.
Step 3.1 − If the result is not 0000, then reject the line.
Step 3.2 − Else you need clipping.
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.
Step 3.2.4 − Repeat step 2 until we find a clipped line either trivially accepted or trivially
rejected.
Step 4 − Repeat step 1 for other lines.
Let Ni be the outward normal edge Ei. Now pick any arbitrary point PEi on edge Ei then the dot
product Ni.[P(t) – PEi] determines whether the point P(t) is “inside the clip edge” or “outside”
the clip edge or “on” the clip edge.
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 –
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.
The following figure shows all or none character clipping –
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.
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.
It is a box with a small hole in the centre of one side with the film placed at the other end. It is
easy to model geometrically. Orient the camera along the z axis with the pinhole at the origin.
Suppose the camera has length d. Assuming the pinhole allows only one ray of light from any
point (x, y, z), the ray is clearly projected to the point (xp, yp, −d), with coordinates
The point (xp, yp, −d) is called the projection point. In an idealized model, the color on the film
plane at this point is the color of the point (x, y, z).
The field or angle of view of the pinhole camera is the angle of the largest object that is fully
visible on the film plane. If h is the height of the camera and θ the angle of view then
The pinhole camera has an infinite depth of field as every point in the field of view is in focus.
The pinhole camera has two disadvantages:
Too little light gets in, and
The angle of view cannot be adjusted.
More sophisticated cameras replace the pinhole with a lens. The lens allows more light to enter
and different lenses give different angles of view (as wide angle lenses). Lenses, however, do not
have an infinite depth of field; not all distances are in focus. Like the pinhole camera, computer
graphics produces images in which all objects are in focus.
9.2.3 The Synthetic Camera Model
In computer graphics we use a synthetic camera model to mimic the behavior of a real camera.
The image in a pinhole camera is inverted. The film plane is behind the lens.
In the synthetic camera model we avoid the inversion by placing the film plane, called the
projection plane, in front of the lens.
The clipping rectangle or clipping window determines the size of the image.