0% found this document useful (0 votes)
31 views78 pages

CG Unit1

Computer graphics is the art of creating visual content using computers, consisting of pixels that form images and graphical objects. It encompasses various operations such as imaging, modeling, rendering, and animation, and has numerous applications in areas like education, entertainment, and design. The document also discusses the software and devices used in computer graphics, including input devices, display technologies, and graphics software.

Uploaded by

blazingsword40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views78 pages

CG Unit1

Computer graphics is the art of creating visual content using computers, consisting of pixels that form images and graphical objects. It encompasses various operations such as imaging, modeling, rendering, and animation, and has numerous applications in areas like education, entertainment, and design. The document also discusses the software and devices used in computer graphics, including input devices, display technologies, and graphics software.

Uploaded by

blazingsword40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

Unit 1

Introduction to Computer Graphics

What is computer Graphics?


Computer graphics is an art of drawing pictures, lines, charts, etc.
using computers with the help of programming. Computer
graphics are made up of a number of pixels. Pixel is the smallest
addressable graphical unit represented on the computer screen.
Introduction
● Computer is an information processing machine. User needs to
communicate with the computer and the computer graphics is one of
the most effective and commonly used ways of communication with
the user.
● It displays the information in the form of graphical objects such as
pictures, charts, diagrams and graphs.
● Graphical objects convey more information in less time and easily
understandable formats, for example statically graphs shown in stock
exchange.
● In computer graphics, pictures or graphics objects are presented as a
collection of discrete pixels. We can control the intensity and color of
pixels which decide how a picture looks 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 a continuous picture or graphics object as a
collection of discrete pixels is called Scan Conversion.
● Basically, there are four major operations that we perform in
computer graphics:
1.Imaging: refers to the representation of 2D images.
2. Modeling: refers to the representation of 3D images.
3.Rendering: refers to the generation of 2D images from 3D models.
4.Animation: refers to the simulation of sequence of images over time.

Advantages of computer graphics


● Computer graphics is one of the most effective and commonly used
ways of communication with computers.
● It provides tools for producing pictures of “real-world” as well as
synthetic objects such as mathematical surfaces in 4D and of data
that have no inherent geometry such as survey results.
● It has the ability to show moving pictures thus making it possible to
produce animations with computer graphics.
● With the use of computer graphics we can control the animation by
adjusting the speed, portion of the picture in view, the amount of
detail shown and so on.
● It provides tools called motion dynamics. In which users can move
objects as well as observe as per requirement for example walk throw
made by builder to show flat interior and surrounding.
● It provides a facility called update dynamics. With this we can
change the shape, color and other properties of objects.

IMAGE REPRESENTATION
Image representation is the approximations of the real world displayed in a
computer.
A picture in computer graphics is represented as a collection of discrete picture
elements termed as pixels.
A pixel is the smallest element of a picture or object that can be represented on the
screen of a device like a computer.
Computer Graphics Application and Software

1.Graphical User interface: - Visual objects which we observe on screen which


communicate with the user are one of the most useful applications of computer
graphics.

2. Entertainment: Computer Graphics are now commonly used in making


motion pictures, music videos and television shows.

3.Visualization: It is used for visualization of scientists, engineers, medical


personnel, business analysts for the study of a large amount of information.
4.Education and training: - Computer graphics can be used to generate models
of physical, financial and economic systems. These models can be used as
educational aids.

5.Image processing: - It is used to process an image by changing the property of


the image.

6.Presentation Graphics: Examples of presentation Graphics are bar charts, line


graphs, pie charts and other displays showing relationships between multiple
parameters. Presentation Graphics is commonly used to summarize

● Financial Reports

● Statistical Reports
7. Computer Art: Computer Graphics are also used in the field of commercial
arts. It is used to generate television and advertising commercials.

8.Computer aided drafting and design: - It uses graphics to design components


and systems such as automobile bodies, structures of building etc.

9.Simulation and animation: - Use of graphics in simulation makes mathematical


models and mechanical systems more realistic and easy to study.
Computer Graphics Software
Graphics software is a type of computer program that is used to create
and edit images.

● Adobe Photoshop is a popular graphics software used by photographers


and graphic designers.
● Adobe Illustrator is another popular graphics software used by graphic
designers, especially for creating vector illustrations.
● CorelDRAW is a graphics software used by both professionals and
hobbyists.
● GIMP is a free and open source graphics software with capabilities
similar to Photoshop.
● Inkscape is a free and open source vector graphics software used by
graphic designers and illustrators.
● Image editors: These are the tools that you use to create or edit your graphic
images. Common image editors include Photoshop, Illustrator, and Inkscape.
● Vector graphics editors: These are the tools that you use to create or edit vector
graphics. Common vector graphics editors include CorelDRAW and Inkscape.
● 3D modeling software: This is the software that you use to create
three-dimensional models. Common 3D modeling software includes Maya, 3ds
Max, and Cinema 4D.
● Animation software: This is the software that you use to create animations.
Common animation software includes Adobe After Effects, Apple Motion, and
Autodesk Maya.
● The Graphical Kernel System (GKS) was developed to adopt the first graphics
software standard by the International Standard Organization (ISO).
● Another graphics standard developed and approved was Programmers
Hierarchical Interactive Graphics System (PHIGS), which is an extension of
GKS.
● Computer Graphics Interface (CGI): system provides standards for device
interface methods and the Computer Graphics Metafile (CGM) system specifies
standards for archiving and transporting pictures.

Description of some graphics devices

❖ Input Devices for Operator Interaction

1.Keyboards:- Keyboards are used as text strings. It is an efficient device for


inputting such non-graphics data as picture labels. Cursor control keys &
function keys are common features on general purpose keyboards. Many other
applications of the keyboard which we are using daily computer graphics are
commanding & controlling through keyboard etc.
2.Mouse:- Mouse is a small size hand-held box used to position the screen
cursor. Wheel or roller or optical sensor is directing the pointer on the
movement of the mouse. Three buttons are placed on the top of the mouse for
signalling the execution of some operation. Nowadays more advanced mice are
available which are very useful in graphics applications, for example Z mouse.

3.Trackball and Spaceball:- Trackball is ball that can be rotated with the finger
or palm of the hand to produce cursor movement. Potentiometer attached to the
ball measures the amount and direction of rotation. They are often mounted on a
keyboard or Z mouse. Space balls provide six degrees of freedom i.e. three
dimensional. In space ball strain gauges measure the amount of pressure applied to
the space ball to provide input for spatial positioning and orientation as the ball is
pushed or pulled in various directions. Space balls are used in 3D positioning and
selection operations in virtual reality systems, modeling, animation, CAD and
other applications.
4.Joysticks:- A joystick consists of a small vertical lever mounted on a base that is
used to steer the screen cursor around. Most joysticks select screen positioning
according to actual movement of stick (lever). Some joysticks work on
pressure applied on sticks. Sometimes the joystick is mounted on the keyboard or
sometimes used alone. Movement of the stick defines the movement of the cursor.
In pressure sensitive stick pressure applied on the stick decides movement of
the cursor. This pressure is measured using a strain gauge. These pressure
sensitive joysticks are also called isometric joy sticks and they are non-movable
sticks.
Data glove:- Data glove is used to grasp virtual objects. The glow is constructed
with a series of sensors that detect hand and figure motions. Electromagnetic
coupling is used between transmitter and receiver antennas which are used to
provide position and orientation of the hand. Input from the glove can be used to
position or manipulate objects in a virtual scene.

Digitizer:- Digitizer is a common device for drawing, painting or interactively


selecting coordinates position on an object. One type of digitizer is a graphics
tablet which inputs two dimensional coordinates by activating the hand cursor or
stylus at a selected position on a flat surface. Stylus is a flat pencil shaped device
that is pointed at the position on the tablet.
Image Scanner:- Image Scanner scans drawing, graph, color, & black and
white photos or text and can be stored for computer processing by passing an
optical scanning mechanism over the information to be stored. Once we have
an internal representation of a picture we can apply transformation. We can also
apply various image processing methods to modify the picture. For scanned text
we can apply modification operations.
Touch Panels:- As name suggests Touch Panels allow displaying objects or
screen-position to be selected with the touch or finger. A typical application is
selecting the processing option shown in graphical icons. Some systems such as a
plasma panel are designed with a touch screen. Other systems can be adapted
for touch input by fitting transparent touch sensing mechanisms over a screen.
Touch input can be recorded with the following methods. 1. Optical methods
2. Electrical methods 3. Acoustical methods

Optical method:- Optical touch panel employs a line of infrared LEDs along one
vertical and one horizontal edge. The opposite edges of the edges containing
LEDs contain light detectors. When we touch at a particular position the line of
light path breaks and according to that breaking line coordinate values are
measured. In case two line cuts it will take the average of both pixel positions.
LEDs operate at infrared frequency so it cannot be visible to the user.
Electrical method:- An electrical touch panel is constructed with two
transparent plates separated by a small distance. One is coated with
conducting material and the other is coated with resistive material. When the
outer plate is touched it will come into contact with the internal plate. When both
plates touch it creates voltage drop across the resistive plate that is converted
into coordinate values of the selected position.

Acoustical method:- In an acoustical touch panel high frequency sound waves are
generated in horizontal and vertical direction across a glass plate. When we
touch the screen the waves from that line are reflected from our fingers. These
reflected waves reach again at transmitter position and the time difference between
sending and receiving is measured and converted into coordinate values.

Light pens:- Light pens are pencil-shaped devices used to select positions by
detecting light coming from points on the CRT screen. Activated light pens
pointed at a spot on the screen as the electron beam lights up that spot and
generates an electronic pulse that causes the coordinate position of the electron
beam to be recorded.
Voice systems:- It is used to accept voice command in some graphics workstations.
It is used to initiate graphics operations. It will match input against a predefined
directory of words and phrases. Dictionary is set up for a particular operator by
recording his voice. Each word is spoken several times and then analyzes the
word and establishes a frequency pattern for that word along with
corresponding functions that need to be performed. When the operator speaks
command it will match with a predefined dictionary and perform the desired
action.
Active and Passive Graphics Devices

1.Active Computer Graphics

● In interactive Computer Graphics users have some controls over the


picture, i.eThe user can make any change in the produced image.
● One example of it is the ping-pong game.
● Interactive Computer Graphics require two-way communication between the
computer and the user.
● A User can see the image and make any change by sending his command
with an input device.

Advantages:

1. Higher Quality

2. More precise results or products

3. Greater Productivity

2..Non-Interactive or Passive Computer Graphics:

● In non-interactive computer graphics, the picture is produced on the


monitor, and the user does not have any control over the image, i.e., the
user cannot make any change in the rendered image. One example of its
Titles shown on T.V.
● Non-interactive Graphics involves only one-way communication between
the computer and the user, User can see the produced image, and he cannot
make any change in the image.

Display Technologies

● There are a number of display devices used in graphics.


● Output devices is another name for display devices.
● The display devices generally used are CRT and LCD.
1.Storage Tubes Graphics Displays:

● This is also known as Direct View Storage Tubes (DVST).


● The raster scan display refreshes the screen to maintain a screen image
whereas DVST gives an alternate method of maintaining the screen image
without refreshing.

Components of DVST:

i) Two Electron Guns ii) Phosphor coated screen, iii) Storage grid mesh iv)
Collector

Working Principle:
● 1. There are two electron guns, namely primary gun and flood gun.
● 2. The primary gun stores the picture pattern and the flood gun maintains the
picture display.
● 3. A primary gun produces high-speed electrons, which strike on the storage
grid to draw the picture pattern.
● 4. Continuous low speed electrons from flood guns pass through the control
grid and get attracted to the positive charged areas of the storage grid.
● 5. The low speed electron then penetrates the storage grid and strikes the
phosphor coating.
● 6. During this process, the collector behind the storage grid smooths out the
flows of food electrons.

Advantage:

● It has flat screen.


● Refreshing of CRT is not required.
● Complex picture can be displayed on high resolution.

Disadvantages:

● The performance of DVST is poor compared to CRT.


● Erasing requires removal of charge on the storage grid.
● Selective or part erasing of the screen is not possible.
● Erasing the screen produces flash over the entire screen.

2.Cathode-ray-tubes

● CRT stands for Cathode Ray Tube. CRT is a technology used in traditional
computer monitors and televisions.

● The image on the CRT display is created by firing electrons from the back of the
tube of phosphorus located towards the front of the screen.

● Once the electron heats the phosphorus, they light up, and they are projected on
a screen. The color you view on the screen is produced by a blend of red, blue
and green light.

Main Components of CRT are:

1. Electron Gun: Electron gun consisting of a series of elements, primarily a


heating filament (heater) and a cathode. The electron gun creates a source of
electrons which are focused into a narrow beam directed at the face of the CRT.

2. Control Electrode: It is used to turn the electron beam on and off.

3. Focusing system: It is used to create a clear picture by focusing the electrons


into a narrow beam.

4. Deflection Yoke: It is used to control the direction of the electron beam. It


creates an electric or magnetic field which will bend the electron beam as it passes
through the area. In a conventional CRT, the yoke is linked to a sweep or scan
generator. The deflection yoke which is connected to the sweep generator creates a
fluctuating electric or magnetic potential.

5. Phosphor-coated screen: The inside front surface of every CRT is coated with
phosphors. Phosphors glow when a high-energy electron beam hits them.
Phosphorescence is the term used to characterize the light given off by a phosphor
after it has been exposed to an electron beam.

● There are two techniques used for producing images on the CRT screen: i.
Vector scan/Random scan display. ii. Raster scan display.

● A CRT is an evacuated glass tube. An electronic gun at the rear of the


tube produces a beam of electron, which is directed towards the front
of the screen by a high voltage.
● The inner side of the screen is coated with phosphor substance, which
gives off light when it is stroked by electron.
● The control grid voltage determines the velocity achieved by the
electrons before they hit the phosphor.
● The control grid voltage determines how many electrons are actually
in the electron beam. Thus, control grid controls the intensity of the
spot where the electron beam strikes the screen.
● The focusing system concentrates the electron beam so that the beam
converges to a small point when it hits the phosphor.
● The deflection system of CRT consists of two pairs of parallel plates,
namely horizontal and vertical deflection plates.
● The voltage applied to vertical deflection of the electron beam and the
voltage applied to the horizontal deflection plates controls the
horizontal deflection of the electron beam.
● There are two techniques used for producing images on CRT screen,
namely Random Scan and Raster Scan.

3.Raster graphics Display.

● Raster graphics, also called bitmap graphics, a type of digital image


that uses tiny rectangular pixels, or picture elements, arranged in a
grid formation to represent an image.
● Raster graphics are digital images represented by a matrix or grid of
pixels commonly called a bitmap.
● Each pixel or dot displays a unique color and together all of these
colored dots create an image. Every pixel in a bitmap is stored as one
or more bits in computer memory.
● In this method the horizontal and vertical deflection signals are generated to
move the beam all over the screen in a pattern shown in fig. 1.4. Here the
beam is swept back & forth from left to right.
● When the beam is moved from left to right it is ON. When a beam is
moved from right to left it is OFF and the process of moving beam from
right to left after completion of row is known as Horizontal Retrace.
● When the beam is reached at the bottom of the screen.
● It is made OFF and rapidly retraced back to the top left to start again and the
process of moving back to top is known as Vertical Retrace.
● The screen image is maintained by repeatedly scanning the same image.
This process is known as Refreshing of Screen.
● In raster scan displays a special area of memory is dedicated to graphics
only. This memory is called Frame Buffer.
● Frame buffer holds a set of intensity values for all the screen points. That
intensity is retrieved from the frame buffer and displayed on screen one row
at a time.
● Each screen point is referred to as pixel or Pel (Picture Element). Each
pixel can be specified by its row and column numbers.

4.Random- scan system

● Calligraphic refresh graphic displays are also referred to as random scan or


stroke-writing or vector displays.

Components: A CRT display unit with electron beam, Refresh display files,
Graphics controller.

Working Principle:

● A CRT, as a random scan display unit, has an electron beam directed only to
the parts of the screen where a picture is to be drawn.
● Random scan monitors draw a picture one line at a time.
● The component of a picture can be drawn and refreshed by a random scan
system in a specified order.
● A picture definition is stored as a set of line-drawing commands in an area
of memory called a refresh display file or refresh buffer.
● To display a specified picture, the system cycles through the set of
commands in the display file, drawing each component line one by one.
● After all line drawing commands have been processed, the system cycles
back to the first line command in the list and repeats the procedure of scan,
display, and retrace.
● Random scan displays draw all the component lines of a picture 30 to 60
times for each second.
● The faster refreshing of the set of lines could burn out the phosphor.
Therefore, when a small set of lines are to be displayed, each refresh cycle is
delayed to avoid greater refresh rates, typically 60 frames per second.
Random scan systems are designed for line drawing applications; hence it
cannot display realistic shaded scenes.
● Application program resides in system memory.
● Graphics packages translate the graphics commands in the application
program into a display file. Display file is also stored in system memory.
● Display processor accesses the content of the display file and displays it on
the monitor screen.
● Display processor retrieves one by one a command from the display file and
draws it on the screen.
● Display processor in a random scan system is also called a graphics
controller or display processing unit.
● Random scan devices render the scene using a short line.
● Electron beams track the line position directly, rather than going through
each and every pixel on screen. Entire scene is defined using a segment of
line in the application program.

Advantages:

1. A CRT has the electron beam directed only to the parts of the screen where
an image is to be drawn.

2. Produce smooth line drawings.

3. High Resolution

Disadvantages:

1. Random-Scan monitors cannot display realistic shades of scenes.


Random Scan Display V/S Raster Scan Display:
Raster-graphics system with a display processor

● One way to design a raster system is having a separate display


coprocessor. Purpose of the display processor is to free the CPU from
graphics work. Display processors have their own separate memory for
fast operation.
● Main work of the display processor is digitizing a picture definition given
into a set of pixel intensity values for store in frame buffer.
● This digitalization process is scan conversion. Display processor also
performs many other functions such as generating various line styles
(dashed, dotted, or solid).
● Display color areas and perform some transformation for manipulating
objects. It also interfaces with interactive input devices such as mouse.
● To reduce memory requirements in raster scan system methods have been
devised for organizing the frame buffer as a line list and encoding the
intensity information. One way to do this is to store each scan line as a set
of integer pairs.
● Video Controller is an interface that passes the contents of the frame buffer
to the monitor.

Color CRT Raster Scan Basic

● A CRT monitor displays color pictures by using a combination of


phosphors that emit different colored light.
● It produces a range of colors by combining the light emitted by
different phosphors.

There are two basic techniques for color display:

i. Beam-penetration technique

ii. Shadow-mask technique

Beam-penetration technique
● This technique is used with random-scan monitors. In this technique, the
inside of CRT screen is coated with two layers of phosphor, usually red and
green.
● The displayed color depends on how far the electron beam penetrates into
the phosphor layers.
● The outer layer is of red phosphor and the inner layer is of green phosphor.
A beam of slow electrons excites only the outer red color.
● A beam of very fast electrons penetrates through the red layer and excites
the inner green layer.
● At intermediate beam speeds, combination of red and green light are emitted
and two additional colors, orange and yellow are displayed.
● The beam acceleration voltage controls the speed of electrons and hence the
screen color at any point on the screen.

Merits:

● It is inexpensive technique to produce color in random scan monitors.

Demerits:

● It can display only four colors.


● The quality of picture produced by this technique is not good as compared to
other techniques.
Shadow-mask technique

● It produces a wide range of colors as compared to beam-penetration


techniques. This technique is generally used in raster scan displays.
Including color TV.
● In this technique CRT has three phosphor color dots at each pixel position.
One dot for red, one for green and one for blue light.
● This is commonly known as Dot Triangle. Here in CRT there are three
electron guns present, one for each color dot.
● And a shadow mask grid just behind the phosphor coated screen. The
shadow mask grid consists of a series of holes aligned with the phosphor dot
pattern.
● Three electron beams are deflected and focused as a group onto the shadow
mask and when they pass through a hole they excite a dot triangle.
● In a dot triangle three phosphor dots are arranged so that each electron beam
can activate only its corresponding color dot when it passes through the
shadow mask.
● A dot triangle when activated appears as a small dot on the screen which has
a color combination of three small dots in the dot triangle.
● By changing the intensity of the three electron beams we can obtain different
colors in the shadow mask CRT.

LCD displays.

● It is generally used in small systems such as calculators and portable laptops.


● This non-emissive device produces a picture by passing polarized light from
the surrounding or from an internal light source through liquid crystal
material that can be aligned to either block or transmit the light.
● The liquid crystal refreshes to the fact that these compounds have crystalline
arrangement of molecules then also flows like liquid.
● It consists of two glass plates each with light polarizer at right angles to
each other sandwich the liquid crystal material between the plates.
● Rows of horizontal transparent conductors are built into one glass plate, and
columns of vertical conductors are put into the other plates.
● The intersection of two conductors defines a pixel position. In the ON state
polarized light passing through material is twisted so that it will pass
through the opposite polarizer. In the OFF state it will reflect back
towards source.
● We applied a voltage to the two intersecting conductors to align the
molecules so that the light is not twisted.
● This type of flat panel device is referred to as a passive matrix LCD. In
active matrix LCD transistors are used at each (x, y) grid point.
● Transistors cause crystals to change their state quickly and also to control the
degree to which the state has been changed.
● Transistor can also serve as a memory for the state until it is changed.
● So transistors make the cell ON for all time giving a brighter display then it
would be if it had to be refreshed periodically .

Advantages of LCD display

Low cost.

Low weight.

Small size.

Low power consumption.


The Video Controller

Basic refresh operation of video controller

● Two registers are used to store the coordinates of the screen pixels which are
X and Y. Initially the X is set to 0 and Y is set to Ymax.
● The value stored in the frame buffer for this pixel is retrieved and used to set
the intensity of the CRT beam. After this X register is incremented by one.
● This procedure is repeated till X becomes equal to Xmax. Then X is set to 0
and Y is decremented by one pixel and repeat the above procedure.
● This whole procedure is repeated till Y becomes equal to 0 and completes
the one refresh cycle. Then controller reset the register as top –left corner i.e.
X=0 and Y=Ymax and the refresh process starts for the next refresh cycle.
● Since the screen must be refreshed at the rate of 60 frames per second the
simple procedure illustrated in figure cannot be accommodated by typical
RAM chips.
● To speed up pixel processing, the video controller retrieves multiple values
at a time using more numbers of registers and simultaneously refreshes
blocks of pixels.
● Such a way it can speed up and accommodate a refresh rate more than 60
frames per second.
Chapter 2 : Scan conversion

Cartesian coordinate system

It is also known as a rectangular coordinate system and can be of two or


three dimensions. A point in the Cartesian coordinate system can be
defined by specifying two numbers, called the x – coordinate and the y –
coordinate of that point.

Digital Differential Analyzer (DDA) algorithm

● DDA stands for Digital Differential Analyzer. It is an incremental method


of scan conversion of lines.
● In this method calculation is performed at each step but by using results of
previous steps.
● 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. In the following
three algorithms, we refer the one point of line as
● 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 is the simple line generation algorithm which is explained
step by step here.
Algorithm: Refer Lecture Notes

Problem-01:

Calculate the points between the starting point (5, 6) and ending point (8, 12).
Advantages of DDA algorithm

● It is a faster algorithm.
● It is a simple algorithm.

Disadvantage of DDA algorithm

● Floating point arithmetic is time consuming.


● Poor endpoint accuracy.

Bresenhams’ Line drawing algorithm

● Bresenham's line drawing algorithm is a second method of generating a line


that was proposed after the DDA algorithm to overcome its limitations and
drawbacks.
● This algorithm determines the points which should be selected to form a
close approximation to a line between two points. It is also an incremental
method for creating a line.
● It is faster than the DDA algorithm as it does not involve the use of heavy
operations such as multiplication and division.
Algorithm : Refer Lecture Notes

Advantages of Bresenham's Algorithm

● It is faster because it does not involve floating-point calculations.


● It involves only integer arithmetic. Hence, it is easier to implement.

Disadvantages of Bresenham's Algorithm

● It also does not provide smooth lines though accuracy has been improved.

Example: 1

Polar coordinate system

In a polar coordinate system, the position of a point is defined by


specifying the distance (radius) from a fixed point called origin and the
angle between the line joining the point and the origin and the polar axis
(horizontal line passing through the origin).
Bresenhams’ method of Circle drawing

● The Bresenham's circle drawing algorithm is a circle drawing algorithm


which calculates all the nearest points nearest to the circle boundary.
● It is an incremental method (i.e. we increment one of the coordinates of the
point and calculate the other coordinate according to it.
● In this manner we find all the points of that particular polygon). It only uses
integer arithmetic which makes it's working faster as well as less complex.
● The strategy that is followed in this algorithm is to select the pixel which has
the least distance with the true circle boundary and then keep calculating the
successive points on the circle.
● As we know that the circle follows 8 symmetry properties, i.e. if we know
the boundary coordinates of the first octant, the rest 7 octant’s value can be
easily calculated by changing their magnitudes or by interchanging the
coordinate values according to the respective octants.
● This can be well illustrated by the following diagram
Advantages of Bresenham's Circle Drawing Algorithm

1. The Bresenhem’s circle drawing algorithm uses integer arithmetic which


makes the implementation less complex.
2. Due to its integer arithmetic, it is less time-consuming.
3. This algorithm is more accurate than any other circle drawing algorithm as it
avoids the use of round off functions.

Disadvantages of Bresenham's Circle Drawing Algorithm

1. This algorithm does not produce smooth results due to its integer arithmetic
as it fails to diminish the zigzags completely.
2. The Bresenhem’s circle drawing algorithm is not accurate in the case of
drawing of complex graphical images.

Example:
Midpoint Circle Algorithm

● The midpoint circle drawing algorithm is an algorithm used to


determine the points needed for rasterizing a circle.
● We use the midpoint algorithm to calculate all the perimeter points of
the circle in the first octant and then print them along with their mirror
points in the other octants.
● This will work because a circle is symmetric about its centre.

The points generation using Mid Point Circle Drawing Algorithm involves the
following steps-
Example:

1. Given the centre point coordinates (0, 0) and radius as 10, generate all the points
to form a circle.
2. Given the center point coordinates (4, -4) and radius as 10, generate all the points to
form a circle.
Advantages:

● The mid-point circle algorithm is an efficient algorithm in drawing a circle.


● The implementation of the algorithm is easy from the programmer’s point of
view.

Disadvantages:

● The time consumption of this algorithm is high.


Midpoint Ellipse Algorithm,
● This is an incremental method for scan converting an ellipse that is centered
at the origin in standard position i.e., with the major and minor axis parallel
to the coordinate system axis.
● It is very similar to the midpoint circle algorithm. Because of the four-way
symmetry property we need to consider the entire elliptical curve in the first
quadrant.

Algorithm
Step 1: Start

Step 2: Initialize the initial point of the Center is origin.

x=0 , y = ry

Step 3: Calculate Decision Parameter for region 1.

P= ry2 + rx2 / 4 - ry rx2


dx = 2 ry2 x

dy = 2 rx2 y

Step 5: Update values of dx and dy after each iteration.

Step 6: Repeat steps while (dx < dy):

Plot (x,y)

if(P < 0)

Update x = x+1 ;

P += ­ry2 [2x + 3 ]

Else

Update x = x + 1

y= y - 1

Step 7: When dx ≥ dy, plot region 2:

Step 8: Calculate P2 = ry2 ( x+1 / 2)2 + rx2 (y -1)2- rx2ry2

Step 9: Repeat till (y = 0)

If (P2 > 0)

Update y = y-1 (x will remain same)

P2 =­P2 -2 y rx2 + rx2

else

x = x+1

y = y-1

P2=­P2+ 2 ry2 [2x] -2 y rx2 + rx2


Step 10: End .

Advantages:

● The mid-point ellipse algorithm has simple and easy implementation as it


only includes additional operations.

Disadvantages:

● This algorithm is time consuming.

Problems of Aliasing
● In computer graphics, the process by which smooth curves and other lines
become jagged because the resolution of the graphics device or file is not
high enough to represent a smooth curve.
● In the line or circle drawing algorithms, we have seen that all rasterized
locations do not match with the true line and we have to select the optimum
raster locations to represent a straight line.
● This problem is severe in low resolution screens. In such screens the line
appears like a stair-step. This effect is known as aliasing.
● The aliasing effect occurs when rasterized images have jagged edges,
sometimes called "jaggies" (an image rendered using pixels).
● Technically, jagged edges are a problem that arises when scan conversion is
done with low-frequency sampling, also known as under-sampling; this
under-sampling causes distortion of the image.
● Moreover, when real-world objects made of continuous, smooth curves are
rasterized using pixels, aliasing occurs.
● Smoothing and Anti Aliasing techniques can reduce the effect of aliasing.
1.Jagged Profiles

The picture on the left shows the sampling grid superimposed on the original
scene. The picture on the right is the rendered image. A jagged profile is quite
evident in the rendered image. Also known as "jaggies", jagged silhouettes are
probably the most familiar effect caused by aliasing. Jaggies are especially
noticeable where there is a high contrast between the interior and the exterior of the
silhouette.

2.Improperly rendering

The original scene on the left shows a group of small polygons. In the rendered
scene, one of the two red rectangles disappears entirely, and the other doubles in
width. Two of the orange triangles disappear. Although the two yellow triangles are
identical in size, one is larger than the other in the rendered image.

3.Disintegrating textures.

This is a checkered texture on a plane. The checkers should become smaller as


the distance from the viewer increases. However, the checkers become larger
or irregularly shaped when their distance from the viewer becomes too great.
Simply increasing the resolution will not remove this artifact. Increasing the
resolution will only move the artifact closer to the horizon.

End-point ordering and clipping lines


The Clipping Window

● It is desirable to restrict the effect of graphics primitives to a


sub region of the canvas, to protect other portions of the
canvas.
● All primitives are clipped to the boundaries of this clipping
rectangle, that is, primitives lying outside the clip rectangle
are not drawn.
● Most graphics packages support rectangular clipping regions.
● Some Systems support rotated 2D viewing frames, but usually
the clipping window must be specified in world coordinates.
● Following figure shows the space of the line to be clipped.
● The default clipping rectangle is the full canvas , and it is
obvious that we cannot see any graphics primitives outside the
screen .
● Some of the 2D clipping examples are point clipping , line
clipping, polygon clipping etc.

1.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, the Y coordinate of the given point is
inside the window, if Y lies in between Wy1 ≤ Y ≤ Wy2.

2. Line Clipping

The concept of line clipping is the same as point clipping. In line clipping, we will
cut the portion of the line which is outside of the window and keep only the portion
that is inside the window.

1. Test a given line segment to determine whether it lies completely inside the
clipping window,

2. If it does not, we try to determine whether it lies completely outside the window.
3. If the line segment is not completely inside or completely outside, perform
intersection calculations with one or more clipping boundaries, with the use of
various line clipping algorithms.

Clipping Lines algorithms–


The concept of line clipping is the same as point clipping. In line clipping, we will
cut the portion of the line which is outside of the window and keep only the portion
that is inside the window.
1.Cohen-Sutherland Line Clippings

● This algorithm uses the clipping window as shown in the following figure.
The minimum coordinate for the clipping region is (XW min, YWmin) and
the maximum coordinate for the clipping region is (XW max, YWmax).
● 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.

There are three possible cases for any given line.


1. Completely inside the given rectangle : Bitwise OR of region of two end
points of line is 0
(Both points are inside the rectangle)
2. Completely outside the given rectangle : Both endpoints share at least one
outside region
which implies that the line does not cross the visible region. (bitwise AND of
endpoints != 0).
3. Partially inside the window : Both endpoints are in different regions. In this
case, the algorithm finds one of the two points that is outside the rectangular
region. The intersection of the line from outside point and rectangular window
becomes new corner point and the
algorithm repeats

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 − 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

based 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.

Example:

2.Cyrus-Beck Line Clipping Algorithm


● Cyrus Beck Line clipping algorithm is a parametric line-clipping algorithm.
● The term parametric means it is required to find the value of the parameter
„t‟ in the parametric representation of the line segment for the point at that
the segment intersects the clipping edge.
● This algorithm is more efficient than the Cohen-Sutherland algorithm. It
employs parametric line representation and simple dot products.
3. Liang Barsky Line Clipping algorithm.

The Liang-Barsky algorithm is a line clipping algorithm. This algorithm is more


efficient than Cohen–Sutherland line clipping algorithm and can be extended to
3-Dimensional clipping. This algorithm is considered to be the faster parametric
line-clipping algorithm. The following concepts are used in this clipping:

1. The parametric equation of the line.


2. The inequalities describing the range of the clipping window which is
used to determine the intersections between the line and the clip window.

When pk < 0, as t increase line goes from the outside to inside (entering).

When pk > 0, line goes from inside to outside (exiting).

When pk = 0 and qk < 0 then line is trivially invisible because it is outside view
window.

When pk = 0 and qk > 0 then the line is inside the corresponding window
boundary.
Algorithm:
3.Clipping Polygons and Problem with multiple components

● An algorithm that clips a polygon must deal with many different cases. The
case is particularly noteworthy in that the concave polygon is clipped into
two separate polygons. All in all, the task of clipping seems rather complex.
● Each edge of the polygon must be tested against each edge of the clip
rectangle; new edges must be added, and existing edges must be discarded,
retained, or divided.
● Multiple polygons may result from clipping a single polygon. We need an
organized way to deal with all these cases.
● Polygons are clipped based on the window, the portion inside the window is
kept as it is and the portion outside the window is clipped.
● There are two types of polygons: (i) Concave (ii) Convex.
● (i) Concave polygon: It does not have any part of its diagonal in its exterior
and at least one angle should be greater than 180o .
● (ii) Convex polygon: It has at least one part of the diagonal in its exterior
and all angles should be less than 180o .

Steps of Sutherland-Hodgman's polygon-clipping algorithm

● Polygons can be clipped against each edge of the window one at a time.
Windows/edge intersections, if any, are easy to find since the X or Y
coordinates are already known.
● Vertices which are kept after clipping against one window edge are saved for
clipping against the remaining edges.
● Note that the number of vertices usually changes and will often increase.
● We are using the Divide and Conquer approach.
There are four possible cases for any edge of a given polygon against the current
clipping edge.

Procedure:

● It first clips the polygon against the right clipping boundary.


● The resulting polygon is then clipped against the top boundary.
● The same process is repeated for the remaining two boundaries.
● It works in order and makes sure that all edges of clipping polygon are taken
sequentially.
● At each step a new sequence of vertices are generated and passed to the next
window boundary for clipping.
● To clip the vertices following cases are considered:

Case 1- Both vertices are inside: Only the second vertex is added to the output list.

Case 2 - First vertex is outside while second one is inside: Both the point of
intersection of the edge with the clip boundary and the second vertex are added to
the output list.
Case 3 - First vertex is inside while second one is outside: Only the point of
intersection of the edge with the clip boundary is added to the output list.

Case 4 - Both vertices are outside: No vertices are added to the output list.

Fig. 9 depicts the following cases:

a. Clipping against the left side of the clip window.

b. Clipping against the top side of the clip window.

c. Clipping against the right side of the clip window.

d. Clipping against the bottom side of the clip window.

Example:
Examples:

You might also like