Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views36 pages

Unit 1 Computer Graphics Notes

The document provides an overview of computer graphics, detailing its definition, applications, and types, including passive and interactive graphics. It discusses the components of graphics systems, such as frame buffers and display controllers, and highlights various areas of computer graphics like modeling, rendering, and animation. Additionally, it covers display technologies, including raster and random scan displays, as well as the differences between printers and plotters.

Uploaded by

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

Unit 1 Computer Graphics Notes

The document provides an overview of computer graphics, detailing its definition, applications, and types, including passive and interactive graphics. It discusses the components of graphics systems, such as frame buffers and display controllers, and highlights various areas of computer graphics like modeling, rendering, and animation. Additionally, it covers display technologies, including raster and random scan displays, as well as the differences between printers and plotters.

Uploaded by

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

1

Department of Computer Applications

COMPUTER GRAPHICS (CG)

UNIT - I Graphics Primitives

Basics of Graphics systems BCA: V SEM


CODE: BCA-17-302
Mr.Muzamil Aslam
Assistant Professor Global Institute Of Technology & Management

What Is Computer Graphics?

Computer Graphics including digital images, animations, and interactive graphics


are used in various sectors such as entertainment, education, scientific
visualization, and virtual reality. Computer Graphics can be used in UI design,
rendering, geometric objects, animation, and many more. In most areas,
computer graphics is an abbreviation of CG.
Computer Graphics refers to several things
The manipulation and the representation of the image or the data in a graphical
manner.
Various technologies are required for the creation and manipulation.
Digital synthesis and its manipulation.

Why are Computer Graphics used?

Imagine a car manufacturing company that wants to showcase its vehicle sales
over the past decade. Storing and presenting this huge amount of data can be
both time-consuming and memory intensive. Furthermore, it can be difficult for
the average person to understand. In such cases, using graphics can be a more
effective solution. By using charts and graphs to visually signify the data, it
becomes much easier to understand and analyze the data.
2

Interactive computer graphics utilize a two-way communication concept between


users and computers. The computer receives input signals from the user, and the
picture is modified accordingly. When a command is applied, the picture updates
promptly.

 The term computer graphics (CG) describes the use of computers to create
and manipulate images.
 Graphics can be two- or three-dimensional.
 Computer Graphics is the creation and manipulation of images or pictures
with the help of computers.
 The major product of computer graphics is the picture. With the help of CG,
pictures can be represented in 2D, and 3D space.
 Many applications show various parts of the displayed picture changing in
size and orientation. Such transformations, i.e., pictures can be made to
grow, shrink, rotate, etc., can be achieved through CG.
 The display on them is often too big to be shown in its entirety. Thus, with
the help of CG, a technique called clipping can be used to select just those
parts of the picture that lie on the screen and to discard the rest.
 CG is in daily use in the fields of science, engineering, medicine,
entertainment, advertising, graphic arts, fine arts, business, education, etc.
 The electronic industry is more dependent on the technologies provided by
CG,
such as:
o Engineers can draw their circuit in a much shorter time.
o Architects can have alternative solutions to design problems.
o Molecular biologists can display pictures of molecules and study their
structure.
o Town planners and transportation engineers use computer-
generated maps that display data useful to them in their planning
work.

There are two types of computer graphics:

1. Passive Computer Graphics (Non-interactive Computer Graphics)


3

2. Active Computer Graphics (Interactive Computer Graphics)

Non-interactive computer graphics


Non-interactive computer graphics, also known as passive graphics, are static
visual representations that do not change based on user interaction. Here are
some key points:
 Static Content: Pre-rendered images or animations.
 No User Interaction: Viewers cannot alter the graphics.
 Common Uses: Movies, advertisements, illustrations, educational
materials.
 Examples: CGI in films, digital art, static diagrams.
 Rendering Techniques: Often use methods like ray tracing and rasterization
for high-quality visuals.

Interactive Computer Graphics


 Interactive computer graphics (ICG) provide two-way communications
between the computer and the user.
 Various applications of ICG include:
o Using ICG systems to draw integrated electronic circuits, which are
very complex, in a much shorter time.
o It is very useful in the training of pilots, who spend much of their
training on the ground at the controls of a flight simulator rather
than in a real aircraft.
o Many tasks can be made easier and less expensive by the use of ICG.
The effectiveness of ICG lies in the speed with which the user can
absorb the displayed information.
 The Interactive Graphics display consists of three major components as
shown in Figure 1:
1. Frame Buffer
2. T.V. Monitor
3. Display Controller
4

Figure 1

1. Frame Buffer
o The images to be displayed are stored in a frame buffer in the form
of a matrix of intensity values.
o The frame buffer contains the image stored in binary form as a
matrix of 0’s and 1’s, representing the pixel. 0 indicates darkness, and
1 indicates the image.
o The Frame Buffer holds the set of intensity values for all the screen
points.
o The intensity values stored in a Frame Buffer are retrieved and
painted on a screen one row at a time. This row is called a scan line.

2. Display Controller
o The Display Controller passes the contents of the frame buffer to the
T.V. Monitor.
o The Display Controller reads successive bytes of data from the frame
buffer and then converts 0’s and 1’s into the corresponding video
signal.
o These signals are fed to the T.V. Monitor.
3. T.V. Monitor
o The T.V. Monitor then produces a black and white pattern on the
screen.
5

o The frame buffer contents are modified to represent the new pattern
of pixels or if some changes are to be made to the displayed picture.

GRAPHICS AREAS

 The following major areas of computer graphics are:

1. Modeling deals with the mathematical specification of shape and


appearance properties in a way that can be stored on the computer. For
example, a coffee mug might be described as a set of ordered 3D points
along with some interpolation rule to connect the points and a reflection
model that describes how light interacts with the mug.

2. Rendering is a term inherited from art and deals with the creation of
shaded images from 3D computer models.

3. Animation is a technique to create an illusion of motion through sequences


of images. Animation uses modeling and rendering but adds the key issue
of movement over time, which is not usually dealt with in basic modeling
and rendering.

 There are many other areas that involve computer graphics:

1. User Interaction deals with the interface between input devices such as
mice and tablets, the application, feedback to the user in imagery, and
other sensory feedback.

2. Virtual Reality attempts to immerse the user into a 3D virtual world. This
typically requires at least stereo graphics and a response to head motion.
For true virtual reality, sound and force feedback should be provided as
well.
6

3. Visualization attempts to give users insight into complex information via


visual display.

4. Image Processing deals with the manipulation of 2D images and is used in


both the fields of graphics and vision.

5. 3D Scanning uses range-finding technology to create measured 3D models.


Such models are useful for creating rich visual imagery, and the processing
of such models often requires graphics algorithms.

6. Computational Photography is the use of computer graphics, computer


vision, and image processing methods to enable new ways of
photographically capturing objects, scenes, and environments.

COMPUTER GRAPHICS APPLICATION

 Almost any field can make some use of computer graphics, but the major
consumers of computer graphics technology include the following
industries:

1. Video Games increasingly use sophisticated 3D models and rendering


algorithms.

2. Cartoons are often rendered directly from 3D models. Many traditional 2D


cartoons use backgrounds rendered from 3D models, which allows a
continuously moving viewpoint without huge amounts of artist time.

3. Visual Effects use almost all types of computer graphics technology. Almost
every modern film uses digital compositing to superimpose backgrounds
with separately filmed foregrounds. Many films also use 3D modeling and
animation to create synthetic environments, objects, and even characters
that most viewers will never suspect are not real.
7

4. Animated Films use many of the same techniques that are used for visual
effects, but without necessarily aiming for images that look real.

5. CAD/CAM stands for computer-aided design and computer-aided


manufacturing. These fields use computer technology to design parts and
products on the computer and then, using these virtual designs, to guide
the manufacturing process. For example, many mechanical parts are
designed in a 3D computer modeling package and then automatically
produced on a computer-controlled milling device.

 Simulation can be thought of as accurate video gaming. For example, a


flight simulator uses sophisticated 3D graphics to simulate the experience
of flying an airplane. Such simulations can be extremely useful for initial
training in safety-critical domains such as driving, and for scenario training
for experienced users such as specific firefighting situations that are too
costly or dangerous to create physically.

 Medical Imaging creates meaningful images of scanned patient data. For


example, a computed tomography (CT) dataset is composed of a large 3D
rectangular array of density values. Computer graphics is used to create
shaded images that help doctors extract the most salient information from
such data.

 Information Visualization creates images of data that do not necessarily


have a “natural” visual depiction. For example, the temporal trend of the
price of ten different stocks does not have an obvious visual depiction, but
clever graphing techniques can help humans see the patterns in such data.

 Presentation Graphics: In applications like summarizing data of financial,


statistical, mathematical, scientific, and economic research reports,
presentation graphics are used. It increases the understanding using visual
tools like bar charts, line graphs, pie charts, and other displays.
8

DISPLAY TECHNOLOGIES

Cathode Ray Tube (CRT)

 The most common graphics output device is the video monitor, which is
based on the standard cathode ray tube (CRT) design. Figure 4 illustrates
the basic operation of a CRT.

Figure 4 CATHODE RAY TUBE

 As shown in the above figure, it consists of an electron gun, focusing


system, deflection plates, and a phosphor-coated screen.
 The electron gun is the primary component of a CRT. When heat is supplied
to the electron gun by directing a current, a beam of electrons emitted by
an electron gun passes through focusing and deflection systems that direct
the beam toward specified positions on the phosphor-coated screen.
 The focusing system in a CRT is needed to force the electron beam to
converge into a small spot as it strikes the phosphor.
 There are two pairs of deflection plates: Horizontal deflection plates and
9

vertical deflection plates.


 One pair of plates is mounted horizontally to control the vertical deflection,
and the other pair is mounted vertically to control horizontal deflection.
 The beam passes between the two pairs of deflection plates and is
positioned on the screen.
 The phosphor then emits a small spot of light at each position contacted by
the electron beam.
 Because the light emitted by the phosphor fades very rapidly, some method
is needed for maintaining the screen picture.
 One way to keep the phosphor glowing is to redraw the picture repeatedly
by quickly directing the electron beam back over the same points. This type
of display is called a refresh CRT.

IN CRT MONITORS, THERE ARE TWO TECHNIQUES FOR DISPLAYING


IMAGES:

1. Raster scan displays


2. Random scan displays

Raster Scan Displays

In raster scan displays, the electron beam moves across the screen, one row at a
time from top to bottom. As it moves, it turns on and off to create a pattern of
illuminated pixels. This process is repeated quickly enough to create the illusion of
a stable image.
Figure 5: Raster Scan Display
The image on the screen is refreshed many times per second, which is why these
displays are also called refresh CRTs.
Horizontal and Vertical Retrace
During the raster scanning process, once the electron beam reaches the end of a
row, it must return to the start of the next row. This movement is known as the
horizontal retrace. Similarly, after completing the bottom row, the beam returns
to the top row, which is called the vertical retrace.
Figure 6: Horizontal and Vertical Retrace
10

Raster Scan Systems


A raster scan system is composed of several key components:
Frame Buffer: This memory buffer stores the intensity values of all the pixels to be
displayed on the screen.
Display Controller: It reads the pixel data from the frame buffer and converts it
into signals that control the electron beam.
CRT Monitor: This is the output device where the image is displayed.
Figure 7: Architecture of a Simple Raster System
Figure 8: Architecture of a Raster System

Raster Scan Display Processor


The raster scan display processor, also known as a graphics controller, is
responsible for managing the frame buffer and ensuring that the correct pixels
are illuminated on the screen. It converts the digital data stored in the frame
buffer into analog signals that drive the CRT monitor.
Figure 9: Architecture of a Raster-Graphics System with a Display Processor
The main advantages of raster scan displays include:
Capability to render complex scenes with detailed shading and color.
Widely used in television sets, computer monitors, and other display devices.
11
12

Raster Scan Displays


 Figure 5: Raster Scan Display
13

Figure 6: Horizontal and Vertical Retrace


Raster Scan Systems
 Figure 7: Architecture of a simple raster system
 Figure 8: Architecture of a raster system

Raster Scan Display Processor


 Figure 9 shows one way to set up the organization of a raster system
containing a separate display processor, sometimes referred to as a
graphics controller or a display coprocessor.

 Figure 9: Architecture of a raster-graphics system with a display processor


14

Random Scan Display/ Vector-Scan Display/ Calligraphic Displays

 Figure 10: Random Scan Display


Random Scan Display/Vector-Scan Display / Calligraphic Displays
A random scan display, also known as a vector-scan display or calligraphic
display, operates by drawing the picture one line at a time. This method is
distinct from the raster scan display, which illuminates pixels row by row.
Random scan displays are well-suited for line-drawing applications such as
computer-aided design (CAD), where precision and clarity of lines are
essential.
Figure 10: Random Scan Display
 Random-Scan Systems / Random-Scan Display Processor
In a random-scan system, the display processor, also known as the graphics
controller, directs the electron beam to trace only the desired lines on the
screen. This process involves calculating the endpoints of each line and
moving the beam directly from one endpoint to the next without
illuminating the intervening pixels.
Figure 11: Architecture of a Simple Random Scan System

The architecture of a random-scan system includes:


1. Display File: Stores the display list of vectors to be drawn.
2. Display Processor: Reads the display file and converts the commands
into signals to control the electron beam.
15

3. Digital-to-Analog Converter (DAC): Converts digital coordinates into


analog signals that control the beam's position.
4. Monitor: A CRT or other type of monitor that displays the vectors as
specified.
The primary advantages of random scan displays include:
o High resolution and quality for line drawings and text.
o Efficient for applications requiring precise and detailed line drawings.

Random-Scan Systems/ Random-Scan Display Processor

 Figure 11: Architecture of a simple random scan system


16

HARD COPY DEVICES


 Printers
 Plotters
Difference Between Plotter and Printer.
Plotter Vs. Printer: Know the Difference Between Plotter and Printer
Both are types of printers, but there is a fundamental difference between
plotter and printer. A plotter is a device that receives commands from the
computer and then draws its picture on the page. A printer is a device that
prints texts and images on a page after receiving commands from a
network. We will investigate more ways in which both differ. But let us first
know a bit more about them individually.

What is a Plotter?
It is basically a category of printers. They receive the commands from the
computers and then create drawings on paper using pens. We use plotters
for producing various hard copies of designs, large graphs, etc., on paper-
such as engineering drawings, business charts, construction maps,
architectural plans, etc.

A plotter is either a standalone device that has its own internal processor or
a peripheral computer that we add to a computer system. It performs the
production of data in the form of a hardcopy at a comparatively slower rate
than a printer. We mainly use these in specialized fields, such as
engineering, architecture, and drawing.

What is a printer?
It is basically a hardware device (output) that lets a user acquire graphics
and text output from the computer for generating a hard copy. Basically, a
printer processes the available soft copy for producing the hard copy for it.
These printers are of various types on the basis of the quality of hard copy
produced, size, cost, complex construction, and speed. As compared to a
plotter, a printer is capable of producing hardcopy at a much faster speed.
It basically prints one line at a time and is used for producing text and
graphics on physical mediums like paper.
17

Graphics Monitors and Workstations

Graphics monitors and workstations are crucial components in computer


graphics, providing the necessary hardware to display and manipulate images.
Here is an overview of these components:

1. Graphics Monitors

Graphics monitors are designed to display high-quality images and are essential
for any graphics system. The two main types of monitors used in graphics are:

Cathode Ray Tube (CRT) Monitors

These are traditional monitors that use electron beams to illuminate phosphor
dots on the screen.
Advantages: High contrast ratios, wide viewing angles, and fast response times.
Disadvantages: Bulky, heavy, and consume more power.

Liquid Crystal Display (LCD) Monitors

Modern monitors that use liquid crystals and a backlight to produce images.
Advantages: Slim profile, lightweight, and energy efficient.
Disadvantages: Limited viewing angles and contrast ratios compared to CRTs.

Workstations

Workstations are powerful computers designed for technical or scientific


applications. They are optimized for tasks that require high computational power
and advanced graphics capabilities. Key features include:

High-Performance Processors: Capable of handling complex calculations and large


datasets.
Advanced Graphics Cards: Essential for rendering detailed graphics and running
graphics-intensive applications.
Large Memory and Storage: To accommodate large files and multiple applications
running simultaneously.
18

Input Devices

Input devices are used to interact with the graphics system, allowing users to
create, modify, and manipulate images. Common input devices include:

Keyboards
Used for entering text and executing commands.
Standard layout with additional function keys for specific tasks.

Mouse
A pointing device that detects two-dimensional motion relative to a surface.
Essential for navigating graphical user interfaces.
Trackball and Spaceball

Trackball: A stationary device with a ball that can be rotated to move the cursor.

Spaceball: Used for 3D navigation by detecting motion in six degrees of freedom.

Joysticks: Used mainly in gaming and simulations.


Provides control in multiple directions with varying levels of force.

Data Glove: A wearable device that captures hand and finger movements.
Used in virtual reality and animation.

Digitizers: Devices that convert analog information into digital form.


Commonly used for tracing and capturing detailed drawings.

Touch Screens: Displays that detect touch input, allowing direct interaction with
the screen.
Widely used in tablets, smartphones, and interactive kiosks.

Light Pen: A pointing device that can detect the position on the screen when
touched.
19

Used for precise input in CAD and graphics applications.

Voice Systems: Allow users to interact with the computer using voice commands.
Used in accessibility applications and hands-free environments.

Image Scanners: Devices that convert physical images into digital form.
Used for digitizing photographs, documents, and artwork.

These components work together to create a robust graphics system capable of


producing and manipulating complex images, making them indispensable in fields
like design, animation, simulation, and visualization.

Output Primitives: Points and Lines

Output primitives are the basic elements used to create more complex graphical
images. The primary output primitives in computer graphics are points, lines, and
polygons.

Points and Lines

Points
 Points are the simplest graphical elements, representing a single location in
a coordinate space.
 Defined by a pair (x, y) in 2D or a triplet (x, y, z) in 3D.
 Used as the fundamental building blocks for more complex shapes.
Lines
 Lines are defined by two endpoints and are used to connect points.
 In 2D, a line segment is defined by its endpoints (x1, y1) and (x2, y2).
 In 3D, it’s defined by (x1, y1, z1) and (x2, y2, z2).
20

Line Drawing Algorithms

1. Digital Differential Analyzer (DDA) Algorithm.


 An incremental method for drawing lines.
 Computes intermediate points between the start and end points.
 Uses floating-point arithmetic, which can be slow and less efficient.

DDA Algorithm Steps:

1. Input:
o Two endpoints of the line: (x1,y1) and (x2,y2)
2. Calculate Differences:

Compute the differences between the x and y coordinates of the


endpoints:

Δx=x2−x1)

Δy=y2−y1

3. Determine the Number of Steps:


o The number of steps needed to generate the line is determined by
the larger of the absolute differences: Steps=max(∣Δx∣,∣Δy∣)

4. Calculate the Incremental Values:


o Calculate the increments for each step in the x and y directions:

xincrement=Δx/Stepsx

yincrement=Δy/Stepsy
21

5. Initialize the Starting Point:


o Start with the first point (x,y)=(x1,y1)
6. Plot the Line:
o For each step from 1 to the number of steps:
 Plot the current point (Round(x),Round(y)
 Update the x and y coordinates:
 x=x + x increment
 y=y + y increment
7. Output:
o The algorithm outputs a series of points that approximate the
desired line.

Example:

Let's say we want to draw a line from (2,3) (10,8).

1. Calculate Differences:

Δx=10−2=8

Δy=8−3=5

2. Determine Steps:

Steps=max(∣8∣,∣5∣)=8

3. Calculate Increments:

X increment= 8/8=1

Y increment= 5/8=0.625

4. Initialize Starting Point:


o Start with (x,y)=(2,3)
5. Plot the Line:
o For each step, calculate and plot the next point:
 x2=2+1=3
 y2=3+0.625=3.625→Round(3.625)=4
 Continue this process until all points are plotted.
22

Advantages and Disadvantages:

Advantages:

 Simple to implement.
 Works well for lines with small slopes.

Disadvantages:

 Involves floating-point operations, which can be slower.


 Rounding errors may affect the accuracy of the plotted line.
 Bresenham’s algorithm is often preferred for integer-only operations and
better performance.

3. Bresenham’s Line Algorithm

Bresenham's Line Drawing Algorithm

Bresenham's Line Drawing Algorithm is an efficient and accurate method for


drawing straight lines on a grid or raster display. It only uses integer calculations,
making it faster than methods that use floating-point arithmetic.

Key Concept

The algorithm determines which points on a 2D grid should be highlighted to


approximate the appearance of a straight line between two specified points. It
works by incrementally moving from the starting point to the ending point and
deciding at each step whether to move vertically, horizontally, or diagonally based
on a decision parameter.

Steps of the Algorithm

Given two endpoints of a line (x0,y0) and (x1,y1), follow these steps:
23

1. Initialize the variables:


o Calculate the differences: dx=x1−x0
o dy=y1−y0
o Determine the starting decision parameter: p=2×dy−dx
o Set the starting point (x,y)=(x0,y0)

2. Iterate over each x-coordinate from x0 to x1


o Plot the point (x,y)
o If p<0 the next point is (x+1,y) Update the decision parameter
p=p+2×dy.
o If p≥0 the next point is (x+1, y+1)
o Update the decision parameter p=p+2×dy−2×dx

Example: Drawing a Line from (3, 2) to (9, 4)

Let's go through a detailed example:

Initialize:

 Start Point: (x0, y0) =(3,2)


 End Point: (x1, y1) =(9,4)
 dx=9−3=6
 dy=4−2=2
 Initial decision parameter p=2×dy−dx=2×2−6=4−6=−2

Plotting the Points:

Current Point Decision Parameter Next Point


Step Updated p
(x,y) p Decision
1 (3, 2 -2 p<0 move right p+2×dy=2
p≥0 move up-
2 (4, 2) 2 p+2×dy−2×dx=−6
right
3 (5, 3) -6 p<0 move right p+2×dy=−4
4 (6, 3) -4 p<0 move right p+2×dy=0
p≥0, move up-
5 (7, 3) 0 p+2×dy−2×dx=−12
right
6 (8, 4) -12 p<0 move right p+2×dy=−8
7 (9, 4) -8 End point reached
24

Final Plotted Points:

The algorithm plots the points in the order: (3,2) (4,2), (5,3), (6,3), (7,3), (8,4), and
(9,4)

Midpoint Line Drawing Algorithm.

The Midpoint Line Algorithm is a rasterization algorithm used in computer


graphics to draw a straight line on a grid or pixel-based display. It is an
incremental algorithm that determines the points of a line based on the previous
points, ensuring a more efficient and accurate drawing of lines, particularly for
lines with a shallow slope.

Steps of the Midpoint Line Algorithm:

1. Initialization:
o Start with the two endpoints of the line, (x0, y0) and (x1,y1).
o Calculate the differences: Δx=x1−x0
o Δy=y1−y0
o Determine the initial decision parameter: p0=2Δy−Δx
o The initial point (x0, y0) is plotted.
2. Iteration:
o For each x from x0 to x1
 If pi<0:
 Plot (xi+1, yi)
 Update the decision parameter: pi+1=pi+2Δy
 Else:
 Plot (xi+1, yi+1) where yi+1=yi+1
 Update the decision parameter: pi+1=pi+2Δy−2Δx
3. Termination:
o The algorithm continues until all points on the line are plotted.
25

Example:

Let's say we want to draw a line from (2,3) to (7,5) using the Midpoint Line
Algorithm.

1. Initialization:
o x0=2, y0=3
o x1=7, y1=5
o Δx=7−2=5
o Δy=5−3=2
o Initial decision parameter p0=2×Δy−Δx=2×2−5=−1
2. Iteration:
o For x=2:
 p0=−1 (less than 0), plot (3,3).
 Update p1=p0+2×Δy=−1+4=3
o For x=3:
 p1=3 (greater than 0), plot (4,4).
 Update p2=p1+2×Δy−2×Δx=3+4−10=−3
o For x=4:
 p2=−3 (less than 0), plot (5,4).
 Update p3=p2+2×Δy=−3+4=1
o For x=5:
 p3=1 (greater than 0), plot (6,5).
 Update p4=p3+2×Δy−2×Δx=1+4−10=−5
o For x=6x = 6x=6:
 p4=−5 (less than 0), plot (7,5).
3. Result:
o The points plotted are (2,3), (3,3), (4,4), (5,4), (6,5), (7,5).

Difference between DDA Algorithm and Bresenham’s line drawing algorithm


26

Mid-point Circle and Ellipse Algorithms

Midpoint Circle Drawing Algorithm

The Midpoint Circle Drawing Algorithm is an efficient way to draw a circle by


determining the pixels that best approximate the desired circular shape. This
algorithm uses symmetry to reduce the amount of computation and decision-
making to select the next pixel. The algorithm is designed to avoid floating-point
arithmetic, making it faster and more efficient.
Algorithm Overview

Equation of circle.
X2 + y2 = r2
OR
27

(x−h)2 + (y−k)2=r2
 h and k are the coordinates of the center of the circle.
 r is the radius of the circle.

Given the center of a circle (xc, yc) and a radius r, the goal is to plot the circle
centered at (xc, yc) with radius r. The algorithm starts at the top of the circle and
moves counterclockwise, using the symmetry of the circle to reflect the points
into all eight octants.
Steps of the Algorithm.

1. Initialization:
o Start at the topmost point on the circle: (x0, y0) =(0, r)
o Compute the initial decision parameter: p0=1−r
o The circle is symmetric, so for each point (x, y) computed in the first
octant, plot the corresponding points in the other seven octants.
2. Iteration:
o For each pixel (xk, yk) starting from (0, r),
 If pk<0, the next pixel is (xk+1, yk) and the decision parameter
is updated as: pk+1=pk+2xk+3
 If pk≥0, the next pixel is (xk+1, yk−1) and the decision
parameter is updated as: pk+1=pk+2xk−2yk+5
o Continue the process until xk≥yk .
Example
Let's draw a circle centered at (0,0) with radius r=5
1. Calculate Initial Values:
o Initial point: (x0, y0) = (0,5)
o Initial decision parameter: p0=1−5=-4
2. Plotting Points:
o Start at (0,5).
o p0=−4<0, so plot (1,5) and compute the next decision parameter:
p1=p0+2(0) +3=−4+3=−1
o p1=−1<0, so plot (2,5) and compute: p2=p1+2(1) +3=−1+5=4
o p2=4>0, so plot (3,4) and compute: p3=p2+2(2) −2(5) +5=4+4−10+5=3
o Continue this process until xk≥yk
The algorithm will compute points like (0,5), (1,5), (2,5), (3,4) etc., and reflect
these points across the other seven octants to complete the circle.
Plotting the Full Circle
28

Given the symmetry, for each computed point (x, y) in the first octant, the
corresponding points in all octants are:
 (x, y)
 (y, x)
 (−x, y)
 (−y, x)
 (x, −y)
 (y, −x)
 (−x, −y)
 (−y, −x)
This approach ensures that the circle is plotted correctly by only calculating the
necessary points in the first octant and then reflecting them to the rest of the
circle.

Midpoint Ellipse Drawing Algorithm in Computer Graphics

Introduction

The Midpoint Ellipse Algorithm is an efficient technique to draw an ellipse on a


computer screen using pixels. This algorithm is particularly useful because it
minimizes the amount of computation required, relying on simple integer
operations instead of complex floating-point calculations.

Ellipse Equation

The standard form of an ellipse equation is:

x2 y2
-- + -- = 1
a2 b2

Where:

 a is the semi-major axis (the horizontal radius).


 b is the semi-minor axis (the vertical radius).
29

Key Concepts

1. Symmetry: The ellipse is symmetric about both its axes, which means only
one-quarter of the ellipse needs to be calculated. The rest can be mirrored
from the calculated points.
2. Decision Parameter: The decision parameter helps determine the next pixel
position based on the current location, choosing between moving
horizontally, vertically, or diagonally.

Algorithm Steps

The algorithm is divided into two regions:

1. Region 1: Where the slope of the curve is greater than or equal to -1.
2. Region 2: Where the slope of the curve is less than -1.

Region 1 (Slope ≥ -1)

 Initialization:

o Initialize the decision parameter p1 as: p1=b − a ⋅b+1/4 ⋅ a


o Start at the top of the ellipse at (0, b).
2 2 2

 Loop:
o Move along the ellipse by incrementing the xxx-coordinate and
determining whether to move the y-coordinate.
o If p1<0, move horizontally to the right.
o If p1≥0, move diagonally (right and down).

Region 2 (Slope < -1)

 Initialization:
o Start from the last point in region 1.
2 2 2
o Initialize the decision parameter p2 as: p2= b2(x+1/2) + a (y−1) -
a2b2
 Loop:
o Move along the ellipse by decrementing the y-coordinate and
determining whether to move the xxx-coordinate.
o If p2>0, move vertically down.
o If p2≤0, move diagonally (down and right).
30

Example

Let's consider an example with a=5 and b=3

1. Region 1 Calculation:

o Calculate the initial decision parameter p1=3 −5 ⋅3+1/4⋅5


o Start at (0,3).
2 2 2

=9−75+6.25=−59.75
o Since p1<0, move horizontally to (1,3).
o Recalculate p1 and determine the next move until the slope changes to
less than -1.
2. Region 2 Calculation:
o Start from the last point in region 1.
o Initialize p2 and follow the decision-making process like region 1,
but now focusing on decrementing y.
3. Plotting Points:
o Plot the calculated points on the screen.
o Mirror these points in all four quadrants to complete the ellipse.

Filled Area Primitives in Computer Graphics

When working with filled area primitives like polygons, circles, or other shapes in
computer graphics, specific algorithms are employed to determine which pixels
inside a defined boundary should be colored. The most common algorithms for
filling these areas are:

1. Scan Line Polygon Fill Algorithm


2. Seed fill Algorithm

1. Boundary Fill Algorithm


2. Flood Fill Algorithm
31

1. Scan Line Polygon Fill Algorithm

Introduction: The Scan Line Polygon Fill Algorithm is used to fill the area of a
polygon by processing each horizontal line (or scan line) of the polygon. It is an
efficient method for filling polygons in computer graphics, especially when dealing
with complex shapes.

Scan Line Algorithm

This algorithm works by intersecting scanline with polygon edges and fills the
polygon between pairs of intersections. The following steps depict how this
algorithm works.

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

Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the
alternate pairs.

Key Points:

 Works efficiently for polygons of any shape.


 Requires careful management of edge lists and intersections.
 Handles complex cases like vertices and horizontal edges systematically.

Boundary Fill Algorithm

Introduction: The Boundary Fill Algorithm is a recursive method used to fill an


area enclosed by a boundary. It starts at a seed point inside the area and spreads
outwards until it encounters the boundary.

Boundary Filled Algorithm:


33

Steps to Explain:
1. Choosing a Seed Point:
o Select a pixel inside the boundary where you want to start filling. This
is called the seed point.
2. Check Boundary Condition:
o If the current pixel is not the boundary color and has not been filled
yet, fill it with the desired color.
3. Recursive Filling:
o Move to the neighboring pixels:
 In 4-connected filling, check the pixels directly above, below,
left, and right.
 In 8-connected filling, also check the diagonally adjacent pixels.
o Recursively apply the fill operation to each neighbor.
4. Termination:
o The algorithm stops when it reaches the boundary or when there are
no more neighboring pixels to fill.

Four connected
34

Algorithm

void boundaryFill4(int x, int y, int fill_color,int boundary_color)


{
if(getpixel(x, y) != boundary_color &&
getpixel(x, y) != fill_color)
{
putpixel(x, y, fill_color);
boundaryFill4(x + 1, y, fill_color, boundary_color);
boundaryFill4(x, y + 1, fill_color, boundary_color);
boundaryFill4(x - 1, y, fill_color, boundary_color);
boundaryFill4(x, y - 1, fill_color, boundary_color);
}
}

Key Points:
 Simple to implement but can be inefficient for large areas.
 Careful with recursion to avoid stack overflow.
 Used in applications like paint programs for filling bounded regions.

2. Flood Fill Algorithm

Introduction: The Flood Fill Algorithm is used to replace a specific color with a
new color across a region. It is similar to the Boundary Fill Algorithm but does not
rely on a boundary. Instead, it fills all pixels connected to the seed point that have
the same initial color.
35

Steps to Explain:

1. Choosing a Seed Point:


o Start at a seed point where the target color (the color to be replaced)
is present.

2. Color Match Check:


o If the pixel matches the target color, change it to the fill color.

3. Recursive or Iterative Filling:


o Like the Boundary Fill, move to neighboring pixels (4-connected or 8-
connected) and apply the fill operation.

4. Termination:
o The algorithm continues until all connected pixels of the target color
are filled.

procedure floodFill(x, y, newColor, originalColor):

if pixel (x, y) is within image bounds and has originalColor:

set pixel (x, y) to newColor

floodFill(x + 1, y, newColor, originalColor) // Check right neighbor

floodFill(x - 1, y, newColor, originalColor) // Check left neighbor

floodFill(x, y + 1, newColor, originalColor) // Check bottom neighbor

floodFill(x, y - 1, newColor, originalColor) // Check top neighbor


36

Key Points:

 Useful for areas where a single color needs to be replaced.


 Can be implemented iteratively to avoid recursion limits.
 Often used in image editing and game development for coloring regions.

Conclusion: These three algorithms are essential tools in computer graphics for
filling areas. Each has its specific use case:

 Scan Line Polygon Fill is great for efficiently filling polygons.


 Boundary Fill is perfect for filling enclosed areas with a clear boundary.
 Flood Fill is ideal for replacing colors in connected regions.

THANK YOU

You might also like