CG Unit1
CG Unit1
Computer Aided Design (CAD) : It is used in the design of Buildings, Automobiles, Aircraft,
Watercraft, Spacecraft, Computers, Textiles and many more products
For some design applications, objects are first displayed in a wireframe outline which shows
the overall shape and internal features of objects
Circuits and Networks for communications, water supply or other utilities are constructed
The shapes used in a design represent the different network or circuit components
Real time animations using wireframe displays on a video monitor are useful for testing
performance of a vehicle or system
Realistic displays are generated for advertising of automobiles and other vehicles using special
lighting effects and background scenes
Architects use interactive graphics methods to layout floor plans such as positioning of rooms,
windows, stairs, shelves and other building features
Presentation Graphics
Presentation Graphics is used to produce illustrations for reports, Slides or transparencies for
use with projectors. It is used to summarize Financial, Statistical, Mathematical, Scientific as
well as Economic Data. For example, Bar charts, Line Graphs, Surface Graphs, Pie charts and
other displays shows relationships between multiple parameters.
Computer Art
Computer Graphics are used in both fine art and commercial art applications. Artists use a
variety of computer methods including special purpose hardware, artists paint brush
programs, specially developed software, symbolic mathematical packages, CAD software,
Desktop publishing software and Animation packages that provide facilities for designing
object shapes and specifying object motions eg) LOGOs , TV advertising, Combining Text and
Graphics, Morphing, etc.
Entertainment
Graphics objects are combined with actors and live scenes. eg) Motion pictures, Music Videos,
Television shows.
Visualization
Scientists, Engineers, Medical Personnel, Business Analysts need to analyze large amount of
data. Numerical simulations carried out on super computers frequently produce data files
containing thousands and millions of data values. Satellite cameras and other sources can
process amassing large data files faster than they can be interpreted .
Visualization can be of two types :
Scientific : Graphical representation for scientific, engineering and Medical datasets
Business : Datasets related to commerce, industry and other non-scientific areas
Image Processing
Image processing is applied to modify / interpret existing pictures such as photographs and TV
scans.
Applications of Image Processing:
Improving picture quality
M/C perception of visual information as used in robotics
Display Processor
It is interpreter or piece of hardware that converts display processor code into pictures. It is one
of the four main parts of the display processor
Display File Memory: It is used for generation of the picture. It is used for identification of
graphic entities.
Display Controller:
1. It handles interrupt
2. It maintains timings
3. It is used for interpretation of instruction.
Display Generator:
Display Console: It contains CRT, Light Pen, and Keyboard and deflection system.
The raster scan system is a combination of some processing units. It consists of the control
processing unit (CPU) and a particular processor called a display controller. Display Controller
controls the operation of the display device. It is also called a video controller.
Working: The video controller in the output circuitry generates the horizontal and vertical drive
signals so that the monitor can sweep. Its beam across the screen during raster scans.
As fig showing that 2 registers (X register and Y register) are used to store the coordinate of the
screen pixels. Assume that y values of the adjacent scan lines increased by 1 in an upward
direction starting from 0 at the bottom of the screen to ymax at the top and along each scan line
the screen pixel positions or x values are incremented by 1 from 0 at the leftmost position to
xmax at the rightmost position.
The origin is at the lowest left corner of the screen as in a standard Cartesian coordinate system.
At the start of a Refresh Cycle:
X register is set to 0 and y register is set to ymax. This (x, y') address is translated into a memory
address of frame buffer where the color value for this pixel position is stored.
The controller receives this color value (a binary no) from the frame buffer, breaks it up into
three parts and sends each element to a separate Digital-to-Analog Converter (DAC).
These voltages, in turn, controls the intensity of 3 e-beam that are focused at the (x, y) screen
position by the horizontal and vertical drive signals.
This process is repeated for each pixel along the top scan line, each time incrementing the X
register by Y.
As pixels on the first scan line are generated, the X register is incremented throughxmax.
Then x register is reset to 0, and y register is decremented by 1 to access the next scan line.
Pixel along each scan line is then processed, and the procedure is repeated for each successive
scan line units pixels on the last scan line (y=0) are generated.
For a display system employing a color look-up table frame buffer value is not directly used to
control the CRT beam intensity.
It is used as an index to find the three pixel-color value from the look-up table. This lookup
operation is done for each pixel on every display cycle.
As the time available to display or refresh a single pixel in the screen is too less, accessing the
frame buffer every time for reading each pixel intensity value would consume more time what
is allowed:
Multiple adjacent pixel values are fetched to the frame buffer in single access and stored in the
register.
After every allowable time gap, the one-pixel value is shifted out from the register to control
the warm intensity for that pixel.
The procedure is repeated with the next block of pixels,and so on, thus the whole group of pixels
will be processed.
Display Devices:
The most commonly used display device is a video monitor. The operation of most video
monitors based on CRT (Cathode Ray Tube). The following display devices are used:
Heat is supplied to the cathode by directing current through a coil of wire called filament,
inside a cylindrical cathode structure. This causes electrons to be “boiled off” the hot cathode
surface. In the vacuum inside the CRT envelope, the free negatively charged electrons are then
accelerated towards the phosphor coating by a high positive voltage or an accelerating anode
or focusing anode. Intensity of the electron beam is controlled by setting voltage levels on the
control grid will shut off the beam by repelling the electrons and stopping them from passing
through the small grid at the end of the control grid. A small negative charge will decrease the
electrons passing through.
The light emitted by the phosphor coating depends on the number of electrons striking the
screen, so we can control the brightness of a display by varying voltage on the control grid.
The focusing system in a CRT is needed to force the electron beam to converge into a small
spot as it strikes the phosphor, otherwise the electrons would repel each other and the beam
would spread out as it reaches the screen.
Deflection can be controlled by electric or magnetic fields. CRTs are constructed with magnetic
deflection coils mounted on the outside of the CRT. Spots of light are produced on the screen
by the transfer of CRT beam energy to the phosphor. When the electrons collide with
phosphor coated screen, they are stopped and their kinetic energy is absorbed by the
phosphor. Part of beam energy is converted by friction into heat energy and the remainder
causes electrons in the phosphor atoms to move upto high-quantum levels. After a short time,
the excited phosphor electrons begin dropping back to their stable ground state.
Fig 1.10 Example for construction of square with Random scan display
1. Inexpensive
Disadvantages:
2) Shadow-Mask Method:
Shadow Mask Method is commonly used in Raster-Scan System because they produce a much
wider range of colors than the beam-penetration method.It is used in the majority of color TV
sets and monitors.
Construction: A shadow mask CRT has 3 phosphor color dots at each pixel position.
The deflection system of the CRT operates on all 3 electron beams simultaneously; the 3
electron beams are deflected and focused as a group onto the shadow mask, which contains a
sequence of holes aligned with the phosphor- dot patterns.
When the three beams pass through a hole in the shadow mask, they activate a dotted triangle,
which occurs as a small color spot on the screen.
The phosphor dots in the triangles are organized so that each electron beam can activate only
its corresponding color dot when it passes through the shadow mask.
Inline arrangement: Another configuration for the 3 electron guns is an Inline arrangement in
which the 3 electron guns and the corresponding red-green-blue color dots on the screen, are
aligned along one scan line rather of in a triangular pattern.
This inline arrangement of electron guns in easier to keep in alignment and is commonly used
in high-resolution color CRT's.
Advantage:
1. Realistic image
2. Million different colors to be generated
3. Shadow scenes are possible
Disadvantage:
Advantage:
1) No refreshing is needed.
2) High Resolution
3) Cost is very less
Disadvantage:
1) It is not possible to erase the selected part of a picture.
2) It is not suitable for dynamic graphics applications.
3) They do not display colors and are available with single level of line intensity
4) If a part of picture is to modify, then time is consumed.
5) Erasing of screen produces unpleasant flash over the entire screen surface which prevents
its use of dynamic graphics applications.
6) It has poor contrast as a result of the comparatively low accelerating potential applied to
the flood electrons.
They are constructed by filling the region between two glass plates with a mixture of gases
that usually includes neon. A series of vertical conducting ribbon is placed on one glass panel
and a series of horizontal ribbon is built into the other glass panel.
Voltages applied to a pair of horizontal and vertical conductors cause the gas at the
intersection of the two conductors to break down into glowing plasma of electrons and icons.
Picture definition is stored in the refresh buffer and voltages are applied to refresh the pixel
positions 60 times / sec.
Advantages:
1) High Resolution
2) Large screen size is also possible.
3) Less Volume
4) Less weight
5) Flicker Free Display Disadvantage:
6) Poor Resolution
7) Its addressing is also complex.
LED (Light Emitting Diode):
In an LED, a matrix of diodes is organized to form the pixel positions in the display and picture
definition is stored in a refresh buffer. Data is read from the refresh buffer and converted to
voltage levels that are applied to the diodes to produce the light pattern in the display.
Advantage:
INPUT DEVICES
The Input Devices are the hardware that is used to transfer input to the computer. The data
can be in the form of text, graphics, sound, and text. Output device display data from the
memory of the computer. Output can be text, numeric data, line, polygon, and other objects.
The following are some of the examples of Input Devices :
1) Keyboard
2) Mouse
3) Trackball
4) Spaceball
5) Joystick
6) Lightpen
7) Digitizer
8) Touch panels
9) Image Scanner
1) Keyboard :
The most commonly used input device is a keyboard. The data is entered by pressing the set of
keys. All keys are labeled. A keyboard with 101 keys is called a QWERTY keyboard.
The keyboard has alphabetic as well as numeric keys. Some special keys are also available.
1. Numeric Keys: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Alphabetic keys: a to z (lower case), A to Z (upper case)
Special Control keys: Ctrl, Shift, Alt
Special Symbol Keys: ; , " ? @ ~ ? :
Cursor Control Keys: ↑ → ← ↓
Function Keys: F1 F2 F3. F9.
Numeric Keyboard: It is on the right-hand side of the keyboard and used for fast entry of
numeric data.
Functions of Keyboard:
Alphanumeric Keyboards are used in CAD. (Computer Aided Drafting)
Keyboards are available with special features line screen co-ordinates entry, Menu selection or
graphics functions, etc.
Special purpose keyboards are available having buttons, dials, and switches.
Advantage:
1) Suitable for entering numeric data.
2) Function keys are a fast and effective method of using commands, with fewer errors.
Disadvantage:
3) Keyboard is not suitable for graphics input.
2) Mouse
A Mouse is a pointing device and used to position the pointer on the screen. There are two or
three depression switches on the top. The movement of the mouse along the x-axis helps in
the horizontal movement of the cursor and the movement along the y-axis helps in the vertical
movement of the cursor on the screen. The mouse cannot be used to enter text.
Advantage:
1) Easy to use
2) Not very expensive
Trackball
It is a pointing device. It is similar to a mouse. This is mainly used in notebook or laptop
computer, instead of a mouse. This is a ball which is half inserted, and by changing fingers on
the ball, the pointer can be moved.
Advantage:
1) Trackball is stationary, so it does not require much space to use it.
2) Compact Size
3) Space ball
It is similar to trackball, but it can move in six directions where trackball can move in two
directions only. The movement is recorded by the strain gauge. Strain gauge is applied with
pressure. It can be pushed and pulled in various directions. The ball has a diameter around 7.5
cm. The ball is mounted in the base using rollers. One-third of the ball is an inside box, the rest
is outside.
Applications:
1) It is used for three-dimensional positioning of the object.
2) It is used to select various functions in the field of virtual reality.
3) It is applicable in CAD applications.
4) Animation is also done using spaceball.
5) It is used in the area of simulation and modeling.
4) Joystick
A Joystick is also a pointing device which is used to change cursor position on a monitor
screen. Joystick is a stick having a spherical ball as its both lower and upper ends as shown in
Fig. 1.20.
The lower spherical ball moves in a socket. The joystick can be changed in all four directions.
The function of a joystick is similar to that of the mouse. It is mainly used in Computer Aided
Designing (CAD) and playing computer games.
5) Light Pen
Light Pen (similar to the pen) is a pointing device which is used to select a displayed menu item
or draw pictures on the monitor screen. It consists of a photocell and an optical system placed
in a small tube. When its tip is moved over the monitor screen, and pen button is pressed, its
photocell sensing element detects the screen location and sends the corresponding signals to
the CPU.
Uses:
1) Light Pens can be used as input coordinate positions
2) If background color or intensity, a light pen can be used as a locator.
3) It is used as a standard pick device with many graphics system.
4) It can be used as stroke input devices.
5) It can be used as valuator
Digitizers
The digitizer is an operator input device, which contains a large, smooth board (the
appearance is similar to the mechanical drawing board) & an electronic tracking device
The electronic tracking device contains a switch for the user to record the desire x & y
coordinate positions. The coordinates can be entered into the computer memory or stored or
an off-line storage medium such as magnetic tape.
Advantages:
1) Drawing can easily be changed.
2) It provides the capability of interactive graphics.
3) Disadvantages:
4) Costly
5) Suitable only for applications which required high-resolution graphics
Touch Panels
Touch Panels is a type of display screen that has a touch-sensitive transparent panel covering
the screen. A touch screen registers input when a finger or other object comes in contact with
the screen. When the wave signals are interrupted by some contact with the screen, that
located is recorded. Touch screens have long been used in military applications.
Voice Recognition
Voice Recognition is one of the newest, most complex input techniques used to interact with
the computer. The user inputs data by speaking into a microphone. The simplest form of voice
recognition is a one-word command spoken by one person. Each command is isolated with
pauses between the words. Voice Recognition is used in some graphics workstations as input
devices to accept voice commands. The voice-system input can be used to initiate graphics
operations or to enter data. These systems operate by matching an input against a predefined
dictionary of words and phrase.
Advantage:
Disadvantages:
process is repeated until the complete line is scanned. Within 20-25 seconds a document of 4"
* 6" can be scanned.
Fig 1.24 Flatbed Scanner
Hand Held Scanner:
It has a number of LED's (Light Emitting Diodes). The LED's are arranged in the small case. It is
called a Hand held Scanner because it can be kept in hand which performs scanning. For
scanning the scanner is moved over document from the top towards the bottom. Its light is on,
while we move it on document. It is dragged very slowly over document. If dragging of the
scanner over the document is not proper, the conversion will not correct.
HARDCOPY DEVICES
Types of printers
1) Impact Printers: The printers that print the characters by striking against the ribbon and
onto the papers are known as Impact Printers.
These Printers are of two types:
1) Character Printers
2) Line Printers
2) Non-Impact Printers: The printers that print the characters without striking against the
ribbon and onto the papers are called Non-Impact Printers. These printers print a complete
page at a time, therefore, also known as Page Printers.
Dot matrix has printed in the form of dots. A printer has a head which contains nine pins. The
nine pins are arranged one below other. Each pin can be activated independently.
All or only the same needles are activated at a time. When needless is not activated, and then
the tip of needle stay in the head. When pin work, it comes out of the print head.
In nine pin printer, pins are arranged in 5 * 7 matrixes.
Dot Matrix Printers prints output as dots, so it can print any shape of the character. This allows
the printer to print special character, charts, graphs, etc.
Dot Matrix Printers come under the category of impact printers. The printing is done when the
hammer pin strikes the inked ribbon. The impressions are printed on paper. By placing
multiple copies of carbon, multiple copies of output can be produced.
It is suitable for printing of invoices of companies.
Daisy Wheel Printers
Head is lying on a wheel and Pins corresponding to characters are like petals of Daisy, that's
why called Daisy wheel printer.
Advantage:
More reliable than Dot Matrix Printers
Better Quality
Disadvantage:
Slower than Dot Matrix Printers
Drum Printers
These are line printers, which prints one line at a time. It consists of a drum. The shape of the
drum is cylindrical. The drum is solid and has characters embossed on it in the form of vertical
bands. The characters are in circular form. Each band consists of some characters.
Each line on drum consists of 132 characters. Because there are 96 lines so total characters are
(132 * 95) = 12, 672.
Chain Printers:
These are called as line printers. These are used to print one line at a line. Basically, chain
consists of links. Each link contains one character. Printers can follow any character set style,
i.e., 48, 64 or 96 characters. Printer consists of a number of hammers also.
Advantages:
Chain or Band if damaged can be changed easily.
It allows printing of different form.
Different Scripts can be printed using this printer.
Disadvantages:
It cannot print charts and graphs.
It cannot print characters of any shape.
Chain Printers is impact printer, hammer strikes so it is noise
2) Non-Impact Printers – Inkjet printers
These printers use a special link called electrostatic ink. The printer head has a special nozzle.
Nozzle drops ink on paper. Head contains up to 64 nozzles. The ink dropped is deflected by the
electrostatic plate. The plate is fixed outside the nozzle. The deflected ink settles on paper.
Advantages:
1) These produce high quality of output as compared to the dot matrix.
2) A high-quality output can be produced using 64 nozzles printed.
3) Inkjet can print characters in a variety of shapes.
4) Inkjet can print special characters.
5) The printer can print graphs and charts.
Disadvantages:
1) Inkjet Printers are slower than dot matrix printers.
2) The cost of inkjet is more than a dot matrix printer.
These printers uses laser lights to produces the dots needed to form the characters to be
printed on a page & hence the name laser printers.
Advantage:
1) It can produce high-quality output on large sheets.
2) It is used to provide the high precision drawing.
3) It can produce graphics of various sizes.
4) The speed of producing output is high
GRAPHICS SOFTWARE
There are two types of Graphics Software.
General Purpose Packages: Basic Functions in a general package include those for generating
picture components (straight lines, polygons, circles and other figures), setting color and
intensity values, selecting views, and applying transformations. Example of general-purpose
package is the GL (Graphics Library), GKS, PHIGS, PHIGS+ etc.
Special Purpose Packages: These packages are designed for non programmers, so that these
users can use the graphics packages, without knowing the inner details.
Example of special purpose package is :
1) Painting programs
2) Package used for business purpose
3) Package used for medical systems.
4) CAD packages
LINE DRAWING ALGORITHMS
A line connects two points. It is a basic element in graphics. To draw a line, you need two
end points (x1,y1) and (x2,y2). The line segment is sampled at unit intervals in one
coordinate and corresponding integer values nearer to the line path are determined for
other coordinates.
b = y-mx
Considering a line with positive slope, if the slope is less than or equal to 1, we sample at
unit x intervals (dx=1) and compute successive y values as :
Yk+1 =Yk + m
Subscript k takes integer values starting from 0, for the 1st point and increases along x axis
in unit intervals until the endpoint is reached. Y is rounded off to a nearest integer to
correspond to a screen pixel.
Similarly, if the slope is greater than or equal to 1, we sample at unit y intervals (dy=1) and
compute x in successive manner as :
X k+1 = X k + 1/m
Step-02:
Find the number of steps or points in between the starting and ending coordinates.
Step-03:
Suppose the current point is (Xp, Yp) and the next point is (Xp+1, Yp+1).
Find the next point by following the below three cases-
Step-04:
Keep repeating Step-03 until the end point is reached or the number of generated new
points (including the starting and ending points) equals to the steps count.
Example: Calculate the points between the starting point (5, 6) and ending point (8, 12).
Given-
Startingcoordinates = (X0, Y0) = (5, 6)
Ending coordinates = (Xn, Yn) = (8, 12)
Step-01:
Calculate ΔX, ΔY and M from the given input.
ΔX= Xn – X0 = 8 – 5 = 3
ΔY =Yn – Y0 = 12 – 6 = 6
M = ΔY / ΔX = 6 / 3 = 2
Step-02:
Calculate the number of steps.
As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6
Step-03:
As M > 1, so case-03 is satisfied.
Now, Step-03 is executed until Step-04 is satisfied.
5 6 5.5 7 (6, 7)
5.5 6 6 8 (6, 8)
6 8 6.5 9 (7, 9)
Procedure-
Given-
Starting coordinates = (X0, Y0)
Ending coordinates = (Xn, Yn)
The points generation using Bresenham Line Drawing Algorithm involves the following
steps-
Step-01:
Calculate ΔX and ΔY from the given input.
These parameters are calculated as-
ΔX = Xn – X0
ΔY =Yn – Y0
Step-02:
Calculate the decision parameter Pk.
It is calculated as-
Pk = 2ΔY – ΔX
Step-03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point depending on the value of decision parameter Pk.
Step-04:
Keep repeating Step-03 until the end point is reached or number of iterations equals to (ΔX-
1) times.
Example: Calculate the points between the starting coordinates (9, 18) and ending
coordinates (14, 22).
Given-
Starting coordinates = (X0, Y0) = (9, 18)
Ending coordinates = (Xn, Yn) = (14, 22)
Step-01:
Step-02:
Step-03:
Thus,
Pk+1 = Pk + 2ΔY – 2ΔX = 3 + (2 x 4) – (2 x 5) = 1
Xk+1 = Xk + 1 = 9 + 1 = 10
Yk+1 = Yk + 1 = 18 + 1 = 19
Similarly, Step-03 is executed until the end point is reached or number of iterations equals
to 4 times.
(Number of iterations = ΔX – 1 = 5 – 1 = 4)
Difference between DDA Line Drawing Algorithm and Bresenhams Line Drawing
Algorithm
Circle is an eight-way symmetric figure. The shape of circle is the same in all quadrants. In
each quadrant, there are two octants. If the calculation of the point of one octant is done,
then the other seven points can be calculated easily by using the concept of eight-way
symmetry.
For drawing, circle considers it at the origin. If a point is P1(x, y), then the other seven points
will be
So we will calculate only 45°arc. From which the whole circle can be determined easily.
If we want to display circle on screen then the putpixel function is used for eight points as
shown below:
putpixel (x, y ,color)
putpixel (x, -y, color)
putpixel (-x, y, color)
putpixel (-x, -y, color)
putpixel (y, x, color)
putpixel (y, -x, color)
putpixel (-y, x, color)
putpixel (-y, -x, color)
Example: Let we determine a point (2, 7) of the circle then other points will be (2, -7), (-2, -
7), (-2, 7), (7, 2), (-7, 2), (-7, -2), (7, -2)
These seven points are calculated by using the property of reflection. The reflection is
accomplished in the following way:
Given-
Centre point of Circle = (X0, Y0)
Radius of Circle = R
The points generation using Mid Point Circle Drawing Algorithm involves the following
steps-
Step-01:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R
Step-02:
Calculate the value of initial decision parameter P0 as-
P0 = 1 – R
Step-03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point of the first octant depending on the value of decision parameter Pk.
Follow the below two cases-
Step-04:
If the given centre point (X0, Y0) is not (0, 0), then do the following and plot the point-
Xplot = Xc + X0
Yplot = Yc + Y0
Step-05:
Step-06:
Solution-
Given-
Centre Coordinates of Circle (X0, Y0) = (0, 0)
Radius of Circle = 10
Step-01:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R = 10
Step-02:
Calculate the value of initial decision parameter P0 as-
P0 = 1 – R
P0 = 1 – 10
P0 = -9
Step-03:
Thus,
Xk+1 = Xk + 1 = 0 + 1 = 1
Yk+1 = Yk = 10
Pk+1 = Pk + 2 x Xk+1 + 1 = -9 + (2 x 1) + 1 = -6
Step-04:
This step is not applicable here as the given centre point coordinates is (0, 0).
Step-05:
Step-03 is executed similarly until Xk+1 >= Yk+1 as follows-
Now, the points for rest of the part are generated by following the signs of other quadrants.
The other points can also be generated by calculating each octant separately.
Here, all the points have been generated with respect to quadrant-1-
One of the most efficient and easiest to drive of the circle algorithms is due to Bresenham.
To begin, note that only one octant of the circle need be generated. The other parts can be
obtained by successive reflections. If the first octant ( 0 to 45 ccw ) is generated, the second
octant can be obtained by reflection through the line y=x to yield the first quadrant. The
results in the first quadrant are reflected through the line x=0 to obtain those in the second
quadrant.
The combined result in the upper semicircle are reflected through the line y=0 to complete
the circle. Bresenham`s Algorithm is consider the first quadrant of an origin- centered circle.
If the algorithm begins at x=0 , y=r, then for clockwise generation of the circle y is a
monotonically decreasing function of x in the first quadrant. Here the clockwise generation
starting at x=0, y=r is chosen. The center of the circle is ( 0,0 ).
We cannot display a continuous arc on the raster display. Instead, we have to choose the
nearest pixel position to complete the arc. From the following illustration, you can see that
we have put the pixel at (X, Y) location and now need to decide where to put the next pixel:
at N (X+1, Y) or at S (X+1, Y-1).
Algorithm
Given-
Centre point of Circle = (X0, Y0)
Radius of Circle = R
The points generation using Bresenham Circle Drawing Algorithm involves the following
steps-
Step-01:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R
Step-02:
Calculate the value of initial decision parameter P0 as-
P0 = 3 – 2 x R
Step-03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point of the first octant depending on the value of decision parameter Pk.
Follow the below two case:
Step-04:
If the given centre point (X0, Y0) is not (0, 0), then do the following and plot the point-
Xplot = Xc + X0
Yplot = Yc + Y0
Step-05:
Keep repeating Step-03 and Step-04 until Xplot => Yplot.
Step-06:
Step-05 generates all the points for one octant.
To find the points for other seven octants, follow the eight symmetry property of circle.
Example: Given the centre point coordinates (0, 0) and radius as 8, generate all the points to
form a circle.
Given-
Centre Coordinates of Circle (X0, Y0) = (0, 0)
Radius of Circle = 8
Step-01:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R = 8
Step-02:
Calculate the value of initial decision parameter P0 as-
P0 = 3 – 2 x R
P0 = 3 – 2 x 8
P0 = -13
Step-03:
As Pinitial < 0, so case-01 is satisfied.
Thus,
Xk+1 = Xk + 1 = 0 + 1 = 1
Yk+1 = Yk = 8
Pk+1 = Pk + 4 x Xk+1 + 6 = -13 + (4 x 1) + 6 = -3
Step-04:
This step is not applicable here as the given centre point coordinates is (0, 0).
Step-05:
Step-03 is executed similarly until Xk+1 >= Yk+1 as follows-
Now, the points for rest of the part are generated by following the signs of other quadrants.
The other points can also be generated by calculating each octant separately.
Here, all the points have been generated with respect to quadrant-1-
Decision parameter:
Initially, we have two decision parameters p1 0 in region 1 and p20 in region 2.
These parameters are defined as : p1 0 in region 1 is given as :
p10=ry2+1/4rx2-rx2ry
Mid-Point Ellipse Algorithm:
1. Take input radius along x axis and y axis and obtain center of ellipse.
2. Initially, we assume ellipse to be centered at origin and the first point as : (x, y 0)= (0, ry).
3. Obtain the initial decision parameter for region 1 as: p1 0=ry2+1/4rx2-rx 2ry
4. For every xk position in region 1 :
If p1k<0 then the next point along the is (x k+1 , yk) and p1k+1=p1k+2ry2xk+1+ry2
Else, the next point is (xk+1, yk-1 )
And p1k+1=p1k+2ry2xk+1 – 2rx2yk+1+ry2
5. Obtain the initial value in region 2 using the last point (x 0, y0) of region 1 as:
p20=ry2(x0+1/2)2+rx2 (y0-1)2-rx2ry2
6. At each yk in region 2 starting at k =0 perform the following task.
If p2k>0 the next point is (xk, yk-1) and p2k+1=p2k-2rx2yk+1+rx2
7. Else, the next point is (xk+1, yk -1) and p2k+1.=p2k+2ry2xk+1 -2rx2yk+1+rx2
8. Now obtain the symmetric points in the three quadrants and plot the coordinate value as:
x=x+xc, y=y+yc
9. Repeat the steps for region 1 until 2r y2x =2rx2y
In this seed fill algorithm, we select a starting point called seed inside the boundary of the
polygon. The seed algorithm can be further classified into two algorithms: Flood Fill and
Boundary filled.
In this flood-fill algorithm, a seed point is taken inside the polygon. The flood fill algorithm
is used when the polygon has multiple color boundaries. In this method, the related pixels
are replaced with the selected color using fill color. The selected pixel values before are
reassigned with the selected color value. This can be done using two approaches either
4-connected or 8-connected.
Algorithm:
Function floodfill(x, y, fillcolor, previouscolor)
if (getpixel (x, y) = previouscolor)
{
setpixel (x, y, fillcolor);
floodfill( x+1, y, fillcolor,previouscolor);
floodfill( x-1, y, fillcolor,previouscolor);
floodfill( x, y+1, fillcolor,previouscolor);
floodfill( x, y-1, fillcolor,previouscolor);
}
getpixel() - The color of specified pixel.
setpixel() - Sets the pixel to specified color.
Advantages:
This method is easy to fill colors in computer graphics.
It fills the same color inside the boundary.
Disadvantages:
Fails with large area polygons.
It is a slow method to fill the area.
The boundary fill algorithm uses polygon boundaries. It is also called an edge fill algorithm.
In this method, a seed point is taken in the polygon boundary and checks whether the
adjacent or neighboring pixel is colored or not. If the adjacent pixel is not colored then, fill
it. This can be done using two approaches: 4-connected or 8-connected.
Algorithm:
Function boundaryfill(x, y, color, color1)
int c;
c = getpixel(x ,y);
if (c! =color) & (c!=color1)
{
setpixel (x, y, color);
boundaryfill( x+1, y, color, color1);
boundaryfill( x-1, y, color, color1);
boundaryfill( x, y+1, color, color1);
boundaryfill( x, y-1, color, color1);
}
Advantages:
The boundary fill algorithm is used to create attractive paintings.
Disadvantages:
In the 4-connected approach, it does not color corners.
Scan fill algorithm is an area-filling algorithm that fill colors by scanning horizontal lines.
These horizontal lines intersect the boundaries of the polygon and fill colors between the
intersection points. Its main purpose is to fill colors in the interior pixels of the polygon.
Advantages:
Scan fill algorithm fills the polygon in the same order as rendering.
It takes advantage of coherence thus, a fast algorithm.
Disadvantages:
The intensity of the pixels is unequal.
Staircase-like appearance when scan line converted to circles.