0% found this document useful (0 votes)
3 views

Computer Graphics

The document provides an overview of computer graphics, covering topics such as display devices, techniques, scan conversion, and transformations. It discusses the goals and applications of computer graphics, including interactivity, education, and entertainment, as well as the functions of graphics hardware like graphics cards and display coprocessors. Additionally, it explains key concepts such as pixels, frame buffers, color systems, and memory requirements for various resolutions.

Uploaded by

Nushrat Imrose
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Computer Graphics

The document provides an overview of computer graphics, covering topics such as display devices, techniques, scan conversion, and transformations. It discusses the goals and applications of computer graphics, including interactivity, education, and entertainment, as well as the functions of graphics hardware like graphics cards and display coprocessors. Additionally, it explains key concepts such as pixels, frame buffers, color systems, and memory requirements for various resolutions.

Uploaded by

Nushrat Imrose
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

1

Computer Graphics
Table of Contents
1. Chapter 1: Introduction & Display Devices ..................................................................................................... 3
1.1. Cathode Ray Tube (CRT) ............................................................................................................................. 7
1.1.1. Construction of CRT ............................................................................................................................................. 7
1.2. Raster Scan Displays..................................................................................................................................... 8
1.3. Color CRT Monitors ..................................................................................................................................... 9
1.3.1. Beam Penetration Method .................................................................................................................................... 9
1.3.2. Shadow-Mask Method ........................................................................................................................................ 10
1.4. Flat-Panel Displays ..................................................................................................................................... 11
1.4.1. Liquid Crystal Display (LCD) ............................................................................................................................ 11
2. Chapter 2: Display Technique ......................................................................................................................... 13
2.1. Raster Scan Systems ................................................................................................................................... 13
2.1.1. Video Controller ................................................................................................................................................. 13
2.1.2. Raster Scan Display Processor ........................................................................................................................... 14
2.2. Random Scan Systems ................................................................................................................................ 15
2.3. Graphics Software ....................................................................................................................................... 15
2.3.1. Coordinate Representations ................................................................................................................................ 15
3. Chapter 3: Scan Conversion ............................................................................................................................ 17
3.1. Line Drawing Algorithms ........................................................................................................................... 17
3.1.1. DDA Algorithm .................................................................................................................................................. 17
3.1.2. Bresenham’s Line Algorithm .............................................................................................................................. 18
3.2. Circle Generating Algorithms ..................................................................................................................... 21
3.2.1. Bresenham’s Circle algorithm ............................................................................................................................ 22
3.2.2. Midpoint Circle Algorithm ................................................................................................................................. 24
3.3. Ellipse Generating Algorithm ..................................................................................................................... 27
3.3.1. Midpoint Ellipse Algorithm ................................................................................................................................ 28
3.4. Filled Area Primitives / Region Filling ....................................................................................................... 34
3.4.1. Boundary Fill Algorithm .................................................................................................................................... 36
3.4.2. Flood Fill Algorithm ........................................................................................................................................... 37
3.4.3. Scan Line Polygon Fill Algorithm ...................................................................................................................... 37
3.5. Character Generation Technique ................................................................................................................ 38
3.6. Antialiasing ................................................................................................................................................. 39
3.6.1. Supersampling .................................................................................................................................................... 40
3.7. Halftoning ................................................................................................................................................... 40
4. Chapter 4: Transformation .............................................................................................................................. 41
4.1. 2D Geometric Transformations................................................................................................................... 41
4.1.1. Translation .......................................................................................................................................................... 41
4.1.2. Rotation .............................................................................................................................................................. 42
4.1.3. Scaling ................................................................................................................................................................ 44
4.1.4. Reflection............................................................................................................................................................ 46
4.1.5. Shear ................................................................................................................................................................... 50
4.2. Composite Transformations ........................................................................................................................ 52
4.3. Coordinate Transformations ....................................................................................................................... 52
4.4. 3D Geometric Transformations................................................................................................................... 53
4.4.1. 3D Translation .................................................................................................................................................... 53
4.4.2. 3D Scaling .......................................................................................................................................................... 54
4.4.3. 3D Rotation......................................................................................................................................................... 55
4.4.4. 3D Shear ............................................................................................................................................................. 57
2

Reference book: Computer Graphics C Version by Donald Hearn & M Pauline Baker (2e)

Md. Nazmul Hossain (18 – 19)


3

Chapter 1: Introduction & Display Devices


Q. What is computer graphics?
Computer graphics refers to a technology that generates images on a computer screen. It is an art of drawing
pictures on computer screens with the help of programming. It involves computations, creation, and
manipulation of data. In other words, we can say that computer graphics is a rendering tool for the generation
and manipulation of images.
Q. List and explain the goals of computer graphics.
The goals of computer graphics include:
 Interactivity: Computer graphics is used to create interactive visual experiences, such as video games,
simulations, and user interfaces.
 Education and Training: Computer graphics supports educational and training goals by providing
realistic simulations and interactive learning environments.
 Scientific and Engineering Visualization: Computer graphics assists researchers, scientists, and
engineers in visualizing complex data and simulations.
 Entertainment: In the realm of entertainment, computer graphics aims to captivate and entertain
audiences.
 Communication: Computer graphics is used as a means of communication in various fields.
Q. Write the applications of computer graphics.
Computer graphics has a wide range of applications across various fields. Here are some of the key applications
of computer graphics:
 Computer graphics is used to create interactive visual experiences, such as video games, simulations,
and user interfaces.
 Used in engineering, architecture, and industrial design for creating and visualizing 2D and 3D models.
 Used in the production of animated films, television shows, and web animations.
 Used to develop interactive educational materials for schools and e-learning platforms.
 Used to create interactive simulations for training purposes, such as flight simulators and medical
training.
Q. What is a GUI?
A graphical user interface (GUI) is an interface through which a user interacts with electronic devices such as
computers and smartphones through the use of icons, menus and other visual indicators. GUIs graphically
display information and related user controls, unlike text-based interfaces, where data and commands are strictly
in text.
Key features of GUIs include:
 Visual Elements: GUIs use visual elements like icons, buttons, checkboxes, radio buttons, sliders, and
text fields to represent actions or options, making it easy for users to understand and interact with the
interface.
 Menus: GUIs typically include dropdown menus or context menus that provide access to various
functions and features. Menus are organized hierarchically for easy navigation.
 Windows: GUI-based applications often use multiple resizable windows to contain and display
information. Each window can contain various graphical elements and content.
 Multitasking: GUI-based operating systems and software allow users to run multiple applications
concurrently and switch between them effortlessly.
4

Q. Write the advantages of GUI.


Graphical User Interfaces (GUIs) offer several advantages. Some of the key advantages of GUIs include:
 User-Friendly: GUIs are designed to be intuitive and user-friendly, making them accessible to
individuals with varying levels of technical expertise. Users can interact with software and systems
using familiar visual elements, such as icons and buttons.
 Reduced Learning Curve: GUIs often require less training and have a shorter learning curve compared
to text-based interfaces or command-line interfaces.
 Multitasking: GUI-based operating systems and software allow users to run multiple applications
concurrently and switch between them effortlessly.
 Error Prevention: GUIs can include features like dialog boxes and confirmation prompts to help users
avoid mistakes, such as accidentally deleting files.
 Consistency: GUIs often follow design conventions and standards, providing a consistent user
experience across different applications and systems.
Q. Write the functions of graphics card.
The primary functions of a graphics card are:
 Image processing: A graphics card has its own processor, called the GPU (Graphics Processing Unit),
which is designed to handle complex image and video processing tasks. This allows the CPU to focus
on other tasks, improving overall system performance.
 Display output: A graphics card is responsible for sending the processed image data to the display
device, such as a monitor or TV. It does this by converting the digital image data into an analog signal
that can be transmitted over a cable.
 3D rendering: A graphics card is capable of rendering 3D images and videos in real-time, which is
essential for gaming and other applications that require high-quality 3D graphics.
 Video decoding: Graphics cards decode and render video content, reducing the CPU's load. This is
essential for smooth video playback, video editing, and streaming.
 Parallel processing: GPUs consist of multiple cores that can execute tasks in parallel, which makes it
ideal for parallel processing tasks such as machine learning or scientific simulations.
Q. Describe the functions of display coprocessor.
A display coprocessor, often integrated into modern graphics cards or system-on-chip (SoC) solutions, serves
several important functions related to managing and controlling the display output. Its primary role is to ensure
that the visual information is correctly processed and displayed on the screen.
The primary functions of a display coprocessor are:
 Resolution Management: A display coprocessor helps manage the screen resolution, allowing users to
adjust the display to different resolutions.
 Refresh Rate Control: The display coprocessor controls the refresh rate of the screen, ensuring that
the display is updated at the desired frequency. This is crucial for smooth animations, gaming, and video
playback.
 Color Management: Display coprocessors handle color calibration, ensuring accurate and consistent
color reproduction.
 Signal Processing: They process and encode signals for various display connectivity standards, such
as HDMI, DisplayPort, DVI, and VGA.
 Multiple Monitor Support: Display coprocessors enable the use of multiple monitors or displays
simultaneously.
5

Q. Define pixel.
A pixel, short for "picture element," is the smallest unit of a digital image or display. It represents a single point
in the image grid, with specific color information, position, and size. Pixels collectively form images on screens
and digital media.
Working of Interactive Computer Graphics
The modern graphics display is very simple in construction. It consists of three components:
1. Frame Buffer or Digital Memory
2. A Monitor likes a home T.V. set without the tuning and receiving electronics.
3. Display Controller or Video Controller: It passes the contents of the frame buffer to the monitor.

Figure 1-1
Frame Buffer
A frame buffer is a contiguous block of computer memory used to hold or map the image displayed on the
screen. It stores the color and intensity information for each pixel on a display screen. It is also known as a
raster buffer, screen buffer, pixel buffer, or refresh buffer.
The frame buffer is used to store the contents of the current frame being displayed on the screen. The picture is
built up in the frame buffer one bit at a time. A 1024 × 1024 element requires 220 (210 = 1024; 220 = 1024 ×
1024) sq.raster or 1,048,576 memory bits in a single bit plane.
Properties of Video Monitor
 Persistence: Persistence is the duration of phosphorescence exhibited by a phosphor. In CRT displays,
when an electron beam strikes the phosphor coating on the screen, it emits light. However, even after
the electron beam is no longer applied to that spot on the screen, the phosphors continue to emit light
for a short period, creating an afterglow. This phenomenon is known as phosphor persistence.
 Resolution: Resolution is the number of pixels per unit length (e.g., inch) in the horizontal as well as
vertical direction. Or, The amount of pixels a screen can display both horizontally and vertically is
referred to as its resolution.
 Aspect Ratio: Aspect ratio refers to the ratio of the width to the height of an image or screen. It is
measured in unit length or number of pixels.
Q. Define color lookup table.
A color lookup table (CLUT) is a matrix of color data that is used to change a source set of colors to a destination
set. It is commonly found in graphics cards (display adapters) and graphics formats, such as GIFs.
6

Q. What is true color system?


The "true color" system, also known as "24-bit color," is a method for representing and displaying colors in
computer graphics. In this system, each pixel's color is defined by a combination of red, green, and blue (RGB)
values, with each component typically having 8 bits (256 possible values). This results in a total of 16.8 million
possible colors (256 × 256 × 256), resulting in highly accurate and realistic color representation in digital
images and displays. The true color system is the most common method for representing and displaying colors
in modern computing and digital media.
Note:
1. Color depth, also known as bit depth, refers to the number of bits used to represent each pixel's color in
a digital image or on a display. It determines the range and precision of colors that can be displayed.
Common color depths include 1-bit (two colors, typically black and white), 8-bit (256 colors), 16-bit
(65,536 colors), and 24-bit (over 16 million colors in the "true color" system). Higher color depths
provide more accurate and detailed color representation but require more data storage and processing
power.
2. True color can also refer to a display mode that does not need a Color Look-Up Table (CLUT). Thus,
true color can be used with any color depth (e.g. 8-bit, 16-bit, 24-bit...) but only without a CLUT.
Q. Consider a system of resolution 600×600. What is its frame buffer size in KB if 3 byte is
required to define a pixel?
The resolution of the system is 600 × 600, which means there are 360000 pixels in total.
Since 3 bytes are required to define each pixel, the total number of bytes required is 360000 × 3 = 1080000
bytes.
To convert this to kilobytes, we divide by 1024, which gives us 1054.6875 KB.
Or,
Given,
Resolution = 600 × 600, and 3 bytes are required to define each pixel.
Then, the size of frame buffer = Resolution × bytes per pixel
= (600 × 600) × 3 bytes
= 1080000 bytes
= 1054.6875 KB
So, the frame buffer size for this system is 1054.6875 KB.
Q. Find the memory required for resolution (1024×972) where color system is true color.
Here, Resolution = 1024 × 972
Since the color system is true color, 24 bits (3 bytes) are required to define each pixel.
So, memory required = Resolution × bits per pixel
= (1024 × 972) × 24 bits
= 23887872 bits
= 2985984 bytes [∵ 8 bits = 1 byte]
= 2916 KB [∵ 1024 bytes = 1 KB]
So, the memory required for a resolution of 1024 × 972 pixels in a true color system is 2916 kilobytes (KB).
7

Q. Find the memory required for resolution (600×900), where color system is true color.
Here, Resolution = 600 × 900
Since the color system is true color, 3 bytes are required to define each pixel.
So, memory required = Resolution × bytes per pixel
= (600 × 900) × 3 bytes = 1620000 bytes = 1582.03125 KB
So, the memory required for a resolution of 600 × 900 pixels in a true color system is 1582.03125 KB
Q. Consider a system has 640×480 resolutions. What is its frame buffer size in KB, if the
system is true color?
Here, Resolution = 640 × 480
Since the color system is true color, 24 bits are required to define each pixel.
Then, the size of frame buffer = Resolution × color depth
= (640 × 480) × 24 bits = 7372800 bits = 921600 bytes = 900 KB
So, the frame buffer size for this system is 900 KB.
Q. How Many k bytes does a frame buffer needs in a 600×400 pixel?
Here, Resolution = 600 × 400
Suppose, n bits are required to define each pixel.
Then, the size of frame buffer = Resolution × bits per pixel
= (600 × 400) × n bits = 240000n bits = 30000n bytes = 29.296875n k bytes

Cathode Ray Tube (CRT)


CRT stands for Cathode Ray Tube. CRT is a technology used in traditional computer monitors and televisions.
The image on 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.
Construction of CRT

or

Figure 1-2: Cathode Ray Tube


The construction of a CRT involves three main components: the electron gun, the deflection plates, and the
fluorescent/phosphor-coated screen.
8

Electron Gun
The electron gun is responsible for generating the electron beam. It consists of several parts, including a cathode,
a heater, a control grid, a pre-accelerating anode, and an accelerating anode. When the cathode is heated, it
emits electrons, which pass through a small hole in the control grid. The electrons are then accelerated by the
pre-accelerating and accelerating anodes. The electron beam is then focused by a focusing node. The intensity
of the electron beam is controlled by setting voltage levels on the control grid.
Deflection plates
The deflection plates are used to control the direction of the electron beam. It creates an electric or magnetic
field that bends the electron beam when it passes through the area. There are two sets of deflection plates:
horizontal and vertical. The horizontal plates are placed vertically and produce an electric or magnetic field in
the horizontal direction, while the vertical plates are placed horizontally and produce an electric or magnetic
field in the vertical direction.
Phosphor-Coated Screen
The front of the CRT has a screen coated with phosphor compounds that emit light when struck by the electron
beams. When the electrons in the beam collide with the phosphor coating,
 they are stopped
 their kinetic energy is absorbed by the phosphor.
 part of the beam energy is converted by friction into heat energy,
 the remainder causes electrons in the phosphor atoms to move up to higher quantum-energy levels.
After a short time, the excited phosphor electrons begin dropping back to their stable ground state, giving up
their extra energy as small quantum’s of Light energy.

Raster Scan Displays


The most common type of graphics monitor employing a CRT is the raster-scan display, based on television
technology. In a raster-scan system, the electron beam is swept across the screen, one row at a time from top to
bottom. As the electron beam moves across each row, the beam intensity is turned on and off to create a pattern
of illuminated spots. Picture definition is stored in a memory area called the refresh buffer or frame buffer. This
memory area holds the set of intensity values for all the screen points. Stored intensity values are then retrieved
from the refresh buffer and "painted" on the screen one row (scan line) at a time (Fig. 1-3). Each screen point
is referred to as a pixel or pel (shortened forms of picture element). The capability of a raster-scan system to
store intensity information for each screen point makes it well suited for the realistic display of scenes containing
subtle shading and color patterns. Home television sets and printers are examples of other systems using
raster-scan methods.

Figure 1-3 A raster-scan system displays an object as a set of discrete points across each scan line.
9

Intensity range for pixel positions depends on the capability of the raster system. In a simple black-and-white
system, each screen point is either on or off, so only one bit per pixel is needed to control the intensity of screen
positions.
Q. Briefly describe raster scanning technique of a black and white system.
In a black and white raster-scan system, the electron beam is swept across the screen, one row at a time from
top to bottom. As the electron beam moves across each row, the beam intensity is turned on and off to create a
pattern of illuminated spots. Picture definition is stored in a memory area called the refresh buffer or frame
buffer. This memory area holds the set of intensity values for all the screen points. In a simple black-and-white
system, each screen point is either on or off, so only one bit per pixel is needed to control the intensity of screen
positions. Stored intensity values are then retrieved from the refresh buffer and "painted" on the screen one row
(scan line) at a time (Fig. 1-3).
Q. What is interlace system?
An interlace system is a method of displaying images on a screen, particularly in the context of older CRT
(cathode ray tube) monitors and television displays. In an interlace system, each frame of the displayed image
is divided into two fields: an odd-field and an even-field. These fields are displayed alternately, rather than
displaying the entire frame at once. The odd-field contains the odd-numbered lines of the image, and the
even-field contains the even-numbered lines.
The primary purpose of interlacing is to reduce flicker and improve the perceived image quality, especially
when using lower refresh rates. By displaying the odd and even lines in separate passes, the human eye perceives
a smoother image with reduced flicker.

Figure 1-4: Interlacing scan lines on a raster scan display. First, all points on the even-numbered
scan lines are displayed; then all points along the odd-numbered lines are displayed.

Color CRT Monitors


A CRT monitor displays color pictures by using a combination of phosphors that emit different-colored light.
By combining the emitted light from the different phosphors, a range of colors can be generated. The two basic
techniques for producing color displays with a CRT are the beam-penetration method and the shadow-mask
method.
Beam Penetration Method
The beam-penetration method for displaying color pictures has been used with random-scan monitors. Two
layers of phosphor, usually red and green, are coated onto the inside of the CRT screen, and the displayed color
depends on how far the electron beam penetrates into the phosphor layers. A beam of slow electrons excites
only the outer red layer. A beam of very fast electrons penetrates through the red layer and excites the inner
green layer. At intermediate beam speeds, combinations of red and green light are emitted to show two
additional colors, orange and yellow. The speed of the electrons, and hence the screen color at any point, is
controlled by the beam-acceleration voltage. Beam penetration has been an inexpensive way to produce color
in random-scan monitors, but only four colors are possible, and the quality of pictures is not as good as with
other methods.
10

Shadow-Mask Method
Shadow-mask methods are commonly used in raster scan systems (including color TV) because they produce a
much wider range of colors than the beam penetration method.
Construction & Working
A shadow-mask CRT has three phosphor color dots at each pixel position. One phosphor dot emits a red light,
another emits a green light, and the third emits a blue light. This type of CRT has three electron guns, one for
each color dot, and a shadow-mask grid just behind the phosphor-coated screen. Figure 1-4 illustrates the
delta-delta shadow-mask method, commonly used in color CRT systems. The three electron beams are deflected
and focused as a group onto the shadow mask, which contains a series of holes aligned with the phosphor-dot
patterns. When the three beams pass through a hole in the shadow mask, they activate a dot triangle, which
appears as a small color spot on the screen. The phosphor dots in the triangles are arranged so that each electron
beam can activate only its corresponding color dot when it passes through the shadow mask. Another
configuration for the three electron guns is an in-line arrangement in which the three electron guns, and the
corresponding red-green-blue color dots on the screen, are aligned along one scan line instead of in a triangular
pattern. This in-line arrangement of electron guns is easier to keep in alignment and is commonly used in high-
resolution color CRTs.

or,

Figure 1-5 Color CRT using a shadow mask (delta-delta shadow-mask method)
We obtain color variations in a shadow-mask CRT by varying the intensity levels of the three electron beams.
By turning off the red and green guns, we get only the color coming from the blue phosphor. Other combinations
of beam intensities produce a small light spot for each pixel position, since our eyes tend to merge the three
colors into one composite. The color we see depends on the amount of excitation of the red, green, and blue
phosphors. A white (or grey) area is the result of activating all three dots with equal intensity. Yellow is
produced with the green and red dots only, magenta is produced with the blue and red dots, and cyan shows up
when blue and green are activated equally. In some low-cost systems, the electron beam can only be set to on
or off, limiting displays to eight colors. More sophisticated systems can set intermediate intensity levels for the
electron beams, allowing several million different colors to be generated.
Q. Describe the construction and operation of color CRT.
The construction of a color CRT involves three main components: the electron gun, the deflection plates, and
the phosphor-coated screen.
The electron gun is responsible for generating the electron beam. It consists of several parts, including a cathode,
a heater, a control grid, a pre-accelerating anode, and an accelerating anode. When the cathode is heated, it
emits electrons, which pass through a small hole in the control grid. The electrons are then accelerated by the
pre-accelerating and accelerating anodes. The electron beam is then focused by a focusing node. The intensity
of the electron beam is controlled by setting voltage levels on the control grid.
11

The deflection plates are used to control the direction of the electron beam. It creates an electric or magnetic
field that bends the electron beam when it passes through the area. There are two sets of deflection plates:
horizontal and vertical. The horizontal plates are placed vertically and produce an electric or magnetic field in
the horizontal direction, while the vertical plates are placed horizontally and produce an electric or magnetic
field in the vertical direction.
The front of the color CRT has a screen coated with phosphor compounds that emit light when struck by the
electron beams. The phosphor dots are grouped together in threes, with one phosphor dot that is red, one that is
green, and one that is blue. The three dots combine together to make one point of light, or pixel, that we see on
the screen.
Q. Differentiate between electrostatic and electromagnetic deflection system. Which is
superior for computer graphics applications and why?
Electrostatic and electromagnetic deflection systems are two types of deflection systems used in CRTs.
Electrostatic deflection uses an electric field to move the electron beam across the screen, while electromagnetic
deflection uses a magnetic field to move the beam.
Electrostatic deflection is simpler and less expensive than electromagnetic deflection. It is also more accurate
and can produce sharper images. However, it is limited in its ability to deflect the beam over large angles, which
makes it less suitable for computer graphics applications.
Electromagnetic deflection, on the other hand, is more complex and expensive than electrostatic deflection. It
is also less accurate and can produce images that are not as sharp as those produced by electrostatic deflection.
However, it is capable of deflecting the beam over large angles, which makes it more suitable for computer
graphics applications.
In summary, electrostatic deflection is superior to electromagnetic deflection in terms of accuracy and image
sharpness, but electromagnetic deflection is superior in terms of its ability to deflect the beam over large angles,
making it more suitable for computer graphics applications.
(Electromagnetic deflection systems are generally preferred for computer graphics applications.)

Flat-Panel Displays
The term flat-panel display refers to a class of video devices that have reduced volume, weight, and power
requirements compared to a CRT. A significant feature of flat-panel displays is that they are thinner than CRTs,
and we can hang them on walls or wear them on our wrists.
Flat-panel displays can be classified into two categories:
1. Emissive displays: The emissive displays (or emitters) are devices that convert electrical energy into
light. Plasma panels, thin-film electroluminescent displays, and Light-emitting diodes (LEDs) are
examples of emissive displays.
2. Non-emissive displays: Non-emissive displays (or non-emitters) are devices that use optical effects to
convert sunlight or light from some other source into graphics patterns. Examples: Liquid Crystal
Displays (LCDs).
Note:
Plasma panels, also called gas-discharge displays, are constructed by filling the region between two glass plates
with a mixture of gases that usually includes neon.
Liquid Crystal Display (LCD)
Liquid-crystal displays (LCDs) are a type of flat-panel display that uses the light-modulating properties of liquid
crystals to display images. They are commonly used in small systems, such as calculators and portable laptop
computers. These non-emissive devices produce a picture by passing polarized light from the surroundings or
from an internal light source through a liquid-crystal material that can be aligned to either block or transmit the
light.
12

An LCD (Liquid Crystal Display) can be constructed with a nematic liquid crystal. Two glass plates, each
containing a light polarizer at right angles to the-other plate, sandwich the liquid-crystal material. Rows of
horizontal transparent conductors are built into one glass plate, and columns of vertical conductors are put into
the other plate. The intersection of two conductors defines a pixel position. Polarized light passing through the
material is twisted so that it will pass through the opposite polarizer. The light is then reflected back to the
viewer. To turn off the pixel, we apply a voltage to the two intersecting conductors to align the molecules so
that the light is not twisted. This type of flat-panel device is referred to as a passive-matrix LCD.
Picture definitions are stored in a refresh buffer, and the screen is refreshed at the rate of 60 frames per second,
as in the emissive devices. Back lighting is also commonly applied using solid-state electronic devices, so that
the system is not completely dependent on outside light sources. Colors can be displayed by using different
materials or dyes and by placing a triad of color pixels at each screen location.
Another method for constructing LCDs is to place a transistor at each pixel location, using thin-film transistor
technology. The transistors are used to control the voltage at pixel locations and to prevent charge from
gradually leaking out of the liquid-crystal cells. These devices are called active-matrix displays.
Q. How do we generate images from scenes?
Generating images from scenes is a complex process. One way to generate images from scenes is to use scene
graphs. Scene graphs are a way to represent a scene as a directed graph, where nodes represent objects and
edges represent relationships between objects. By traversing this graph, information is gathered about object
positions and transformations. The scene graph guides the removal of hidden surfaces and informs
post-processing effects. Finally, the processed information is used to generate a visually coherent image. This
approach, fundamental in computer graphics, enables efficient representation and manipulation of complex
scenes in applications.
Q. How real environments are represented by geometry and photometry?
Real environments can be represented by a combination of geometry and photometry. Geometry refers to the
3D structure of the environment, while photometry refers to the way light interacts with the environment.
Geometry involves the creation of 3D models that define the physical structure and spatial relationships of
objects, structures, terrain, and other elements. These models are constructed from vertices, edges, and faces to
form meshes that determine the shape and topology of surfaces. To add visual richness, textures are applied to
surfaces, conveying the realism of materials through color, normal, specular, and other maps. Lighting models,
such as ray tracing, simulate how light interacts with objects, casting shadows, reflecting surfaces, and creating
refractions. Furthermore, physics simulations are used to replicate real-world behaviors, such as gravity and
collision detection, enhancing realism. For outdoor environments, geographical information systems (GIS) data
can be used to represent terrain, vegetation, and other natural features accurately.
Photometry complements geometry. It utilizes textures to convey the visual appearance of surfaces.
High-Dynamic-Range Imaging (HDRI) captures a wide range of luminance values, vital for rendering scenes
with diverse lighting conditions. Global illumination and ambient occlusion create soft shadows and enhance
realism by simulating light interactions. Photogrammetry captures real-world objects or environments through
photography, transforming images into 3D models with accurate textures. Realistic rendering depends on
accurately representing light sources, be it sunlight, artificial lights, or atmospheric scattering.
The combination of precise geometry and advanced photometry is pivotal in creating realistic virtual
environments. However, achieving complete realism often requires a balance between computational resources
and artistic choices to optimize both visual quality and performance.
13

Chapter 2: Display Technique


Raster Scan Systems
A raster scan system consists of several key components working together to render images on a display device.
Interactive raster graphics systems typically employ several processing units. In addition to the central
processing unit (CPU), a special-purpose processor, called the video controller or display controller, is used to
control the operation of the display device. Organization of a simple raster system is shown in Fig. 2-1. Here,
the frame buffer can be anywhere in the system memory, and the video controller accesses the frame buffer to
refresh the screen. In addition to the video controller, more sophisticated raster systems employ other processors
as coprocessors and accelerators to implement various graphics operations.

Figure 2-1 Architecture of a simple raster graphics system.


Figure 2-2 shows a commonly used organization for raster systems. A fixed area of the system memory is
reserved for the frame buffer, and the video controller is given direct access to the frame-buffer memory.

Figure 2-2 Architecture of a raster system with a fixed portion of the system memory reserved for the frame buffer.

Video Controller
A video controller, also known as a display controller, is a specialized hardware component responsible for
managing and controlling the display output to a monitor or screen using a raster scanning method. The video
controller acts as an intermediary between the computer's graphics processing unit (GPU) or central processing
unit (CPU) and the display device.
Video Controller Refresh Operation
The video controller's refresh operation is a crucial process that ensures the consistent and continuous display
of images on a monitor or screen. It involves refreshing the screen's content by redrawing the image multiple
times per second to ensure a flicker-free and seamless viewing experience.
In Fig. 2-3, the basic refresh operations of the video controller are diagrammed. The video controller uses two
registers (x register and y register) to store the coordinates of screen pixels. At the start of a refresh cycle, the 𝑥
register is set to 0 and the 𝑦 register is set to 𝑦𝑚𝑎𝑥 . The value stored in the frame buffer for this pixel position is
then retrieved and used to set the intensity of the CRT beam. Then the 𝑥 register is incremented by 1, and the
process repeated for the next pixel on the top scan line. This procedure is repeated for each pixel along the scan
line. After the last pixel on the top scan line has been processed, the 𝑥 register is reset to 0 and the 𝑦 register is
decremented by 1. Pixels along this scan line are then processed in turn, and the procedure is repeated for each
successive scan line. After cycling through all pixels along the bottom scan line (𝑦 = 0), the video controller
resets the registers to the first pixel position on the top scan line and the refresh process starts over.
14

Figure 2-3 Basic video-controller refresh operations


Q. What is video controller? Write the function of a video controller.
A video controller, also known as a display controller, is a specialized hardware component responsible for
managing and controlling the display output to a monitor or screen in a computer system. The video controller
acts as an intermediary between the computer's graphics processing unit (GPU) or central processing unit (CPU)
and the display device.
The functions of a video controller are:
 controls the basic screen refreshing operations
 provides a fast mechanism for generating real-time animations
 some transformations can be accomplished by the video controller
 provides a fast method for changing screen intensity values
 controls the operation of the display device
Raster Scan Display Processor
Figure 2-4 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. The purpose of the display processor
is to free the CPU from the graphics chores. In addition to the system memory, a separate display-processor
memory area can also be provided.

Figure 2-4 Architecture of a raster-graphics system with a display processor


15

A major task of the display processor is digitizing a picture definition given in an application program into a set
of pixel-intensity values for storage in the frame buffer. This digitization process is called scan conversion.
Lines and other geometric objects are converted into set of discrete intensity points. Characters can be defined
with rectangular grids, or they can be defined with curved outlines.
Display processors are also designed to perform a number of additional operations. These functions include
generating various line styles (dashed, dotted, or solid), displaying color areas, and performing certain
transformations and manipulations on displayed objects. Also, display processors are typically designed to
interface with interactive input devices, such as a mouse.
To reduce the memory space required to store the image information, each scan line are stored as a set of integer
pairs. One number of each pair indicates an intensity value, and the second number specifies number of adjacent
pixels the scan line that is also having same intensity. This technique is called run-length encoding.

Random Scan Systems


The organization of a simple random-scan (vector) system is shown in Fig. 2-5. In random-scan systems, an
application program is input and stored in the system memory along with a graphics package. Graphics
commands in the application program are translated by the graphics package into a display file stored in the
system memory. This display file is then accessed by the display processor to refresh the screen. The display
processor cycles through each command in the display file program once during every refresh cycle. Sometimes
the display processor in a random-scan system is referred to as a display processing unit or a graphics controller.

Figure 2-5 Architecture of a simple random-scan system


Graphics patterns are drawn on a random-scan system by directing the electron beam along the component lines
of the picture. Lines are defined by the values for their coordinate endpoints, and these input coordinate values
are converted to 𝑥 and 𝑦 deflection voltages. A scene is then drawn one line at a time by positioning the beam
to fill in the line between specified endpoints.

Graphics Software
There are two general classifications for graphics software: general programming packages and special-purpose
applications packages. A general graphics programming package provides an extensive set of graphics functions
that can be used in a high-level programming language, such as C or FORTRAN. An example of a general
graphics programming package is the GL (Graphics Library) system on Silicon Graphics equipment.
Coordinate Representations
Coordinate representation techniques are used in graphics software to define the position and orientation of
objects in a graphical environment. Most graphics packages use Cartesian coordinates to specify objects.
Objects are specified in modeling coordinates (MC), which are then placed into the scene with world coordinates
(WC). World coordinates are then transformed into normalized device coordinates (NC), in the range from
0 to 1. This makes the system independent of the various devices that might be used at a particular workstation.
Normalized device coordinates are then changed into device coordinates (DC), which are pixel locations.
16

Figure 2-6 illustrates the sequence of coordinate transformations from modeling coordinates to device
coordinates for a two-dimensional application. An initial modeling-coordinate position (𝑥𝑚𝑐 , 𝑦𝑚𝑐 ) in this
illustration is transferred to a device coordinate position (𝑥𝑑𝑐 , 𝑦𝑑𝑐 ) with the sequence:
(𝑥𝑚𝑐 , 𝑦𝑚𝑐 ) → (𝑥𝑤𝑐 , 𝑦𝑤𝑐 ) → (𝑥𝑛𝑐 , 𝑦𝑛𝑐 ) → (𝑥𝑑𝑐 , 𝑦𝑑𝑐 )

Figure 2-6 The transformation sequence from modeling coordinates to device coordinates for a 2D scene
The modeling and world-coordinate positions in this transformation can be any floating-point values;
normalized coordinates satisfy the inequalities: 0 ≤ 𝑥𝑛𝑐 ≤ 1, 0 ≤ 𝑦𝑛𝑐 ≤ 1; and the device coordinates 𝑥𝑑𝑐 and
𝑦𝑑𝑐 are integers within the range (0, 0) to (𝑥𝑚𝑎𝑥 , 𝑦𝑚𝑎𝑥 ) for a particular output device. To accommodate
differences in scales and aspect ratios, normalized coordinates are mapped into a square area of the output
device so that proper proportions are maintained.
17

Chapter 3: Scan Conversion


Line Drawing Algorithms
There are several line drawing algorithms in computer graphics that are used to generate a set of discrete points
(pixels) to approximate a straight line between two given endpoints. Each algorithm has its own advantages and
limitations. Here are some common line drawing algorithms:
 DDA Algorithm (Digital Differential Analyzer)
 Bresenham's Line Algorithm
 Midpoint Line Algorithm
DDA Algorithm
The digital differential analyzer (DDA) algorithm is an incremental scan-conversion method. In this method
calculation is performed at each step using results from the preceding step.
Suppose at step 𝑘 we have calculated (𝑥𝑘 , 𝑦𝑘 ) to be a point on the line. Since the next point (𝑥𝑘+1, 𝑦𝑘+1 ) should
∆𝑦
satisfy ∆𝑥 = 𝑚 where ∆𝑦 = 𝑦𝑘+1 − 𝑦𝑘 and ∆𝑥 = 𝑥𝑘+1 − 𝑥𝑘 , we have Note:
∆𝑦
∆𝑦 =𝑚
𝑥𝑘+1 = 𝑥𝑘 + ∆𝑥
𝑚 ⇒
𝑦𝑘+1 −𝑦𝑘
=𝑚
𝑥𝑘+1 −𝑥𝑘
or, 𝑦𝑘+1 −𝑦𝑘
⇒ 𝑥𝑘+1 − 𝑥𝑘 = 𝑚
𝑦𝑘+1 = 𝑦𝑘 + 𝑚∆𝑥 ∆𝑦
∴ 𝑥𝑘+1 = 𝑥𝑘 + 𝑚
These formulas/equations are used in the DDA algorithm as follows.
Consider a line with positive slope, as shown in Fig. 3-1. If the slope is less than or equal to 1, we sample at
unit 𝑥 intervals (∆𝑥 = 1) and compute each successive 𝑦 value as
𝑦𝑘+1 = 𝑦𝑘 + 𝑚 … … … … … … (1)
Subscript 𝑘 takes integer values starting from 1, for the first point,
and increases by 1 until the final endpoint is reached. Since 𝑚 can
be any real number between 0 and 1, the calculated 𝑦 values must
be rounded to the nearest integer.
For lines with a positive slope greater than 1, we reverse the roles
of 𝑥 and 𝑦. That is, we sample at unit 𝑦 intervals (∆𝑦 = 1) and
calculate each succeeding 𝑥 value as
Fig. 3-1: Line path between endpoint
1 positions (𝑥1 , 𝑦1 ) and (𝑥2 , 𝑦2 ).
𝑥𝑘+1 = 𝑥𝑘 + … … … … … … (2)
𝑚
Equations 1 and 2 are based on the assumption that lines are to be processed from the left endpoint to the right
endpoint (Fig. 3-1). If this processing is reversed, so that the starting endpoint is at the right, then either we have
∆𝑥 = −1 and
𝑦𝑘+1 = 𝑦𝑘 − 𝑚 … … … … … … (3)
or (when the slope is greater than 1) we have ∆𝑦 = −1 with
1
𝑥𝑘+1 = 𝑥𝑘 − … … … … … … (4)
𝑚
Equations 1 through 4 can also be used to calculate pixel positions along a line with negative slope. If the
absolute value of the slope is less than 1 and the start endpoint is at the left, we set ∆𝑥 = 1 and calculate 𝑦
values with Eq. 1.
18

When the start endpoint is at the right (for the same slope), we set ∆𝑥 = −1 and obtain 𝑦 positions from
Eq. 3. Similarly, when the absolute value of a negative slope is greater than 1, we use ∆𝑦 = −1 and Eq. 4 or
we use ∆𝑦 = 1 and Eq. 2.
Note: On raster systems, lines are plotted with pixels, and step sizes in the horizontal and vertical directions are
constrained by pixel separations. That is, we must "sample" a line at discrete positions and determine the nearest
pixel to the line at each sampled position. In other words, since we are dealing with pixels, we need integer
values as coordinates. Thus we need to round off fraction values.
Algorithm
Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm which is explained step
by step here.
Step 1: Get the input of two endpoints (𝑥1 , 𝑦1 ) and (𝑥2 , 𝑦2 )
Step 2: Set pixel at position (𝑥1 , 𝑦1 ).
Step 3: Calculate the slope of the line.
∆𝑦 𝑦 −𝑦
𝑚 = ∆𝑥 = 𝑥2 − 𝑥1
2 1

Step 4: Case |𝑚| ≤ 1: repeat the following steps until (𝑥2 , 𝑦2 ) is reached:
𝑥𝑘+1 = 𝑥𝑘 + 1
𝑦𝑘+1 = 𝑦𝑘 + 𝑚
set pixel at position (𝑥𝑘+1 , Round(𝑦𝑘+1 ))
Case |𝑚| > 1: repeat the following steps until (𝑥2 , 𝑦2 ) is reached:
1
𝑥𝑘+1 = 𝑥𝑘 + 𝑚
𝑦𝑘+1 = 𝑦𝑘 + 1
set pixel at position (Round(𝑥𝑘+1), 𝑦𝑘+1 )

The DDA algorithm is faster than the direct use of the line equation since it calculates points on the line without
any floating-point multiplication. However, a floating-point addition is still needed in determining each
successive point. Furthermore, cumulative error due to limited precision in the floating-point representation
may cause calculated points to drift away from their true position when the line is relatively long.
Bresenham’s Line Algorithm
Bresenham's line algorithm is a highly efficient incremental method for scan-converting lines. It produces
mathematically accurate results using only integer addition, subtraction, and multiplication by 2, which can be
accomplished by a simple arithmetic shift operation.
To illustrate Bresenham's approach, we first consider the scan-conversion process for lines with positive slope
less than 1. Pixel positions along a line path are then determined by sampling at unit 𝑥 intervals. Starting from
the left endpoint (𝑥0 , 𝑦0 ) of a given line, we step to each successive column (𝑥 position) and plot the pixel
whose scan-line 𝑦 value is closest to the line path. Figure 3-2 demonstrates the 𝑘th step in this process.
Assuming we have determined that the pixel at (𝑥𝑘 , 𝑦𝑘 ) is to be displayed, we next need to decide which pixel
to plot in column 𝑥𝑘+1. Our choices are the pixels at positions (𝑥𝑘 + 1, 𝑦𝑘 ) and (𝑥𝑘 + 1, 𝑦𝑘 + 1).
19

Figure 3-2: Section of the screen grid showing


a pixel in column 𝑥𝑘 on scan line 𝑦𝑘 that is to Figure 3-3: Distances between pixel positions and
be plotted along the path of a line segment the line 𝑦 coordinate at sampling position 𝑥𝑘 + 1.
with slope |𝑚| < 1.

At sampling position 𝑥𝑘 + 1, we label vertical pixel separations from the mathematical line path as 𝑑1 and 𝑑2
(Fig. 3-3). The 𝑦 coordinate on the mathematical line at pixel column position 𝑥𝑘 + 1 is calculated as
𝑦 = 𝑚(𝑥𝑘 + 1) + 𝑏 … … … … . (1)
Then
𝑑1 = 𝑦 − 𝑦𝑘
= 𝑚(𝑥𝑘 + 1) + 𝑏 − 𝑦𝑘
and
𝑑2 = (𝑦𝑘 + 1) − 𝑦
= 𝑦𝑘 + 1 − 𝑚(𝑥𝑘 + 1) − 𝑏
The difference between these two separations is
𝑑1 − 𝑑2 = 2𝑚(𝑥𝑘 + 1) − 2𝑦𝑘 + 2𝑏 − 1
∆𝑦
⇒ 𝑑1 − 𝑑2 = 2 (𝑥 + 1) − 2𝑦𝑘 + 2𝑏 − 1
∆𝑥 𝑘
⇒ ∆𝑥(𝑑1 − 𝑑2 ) = 2∆𝑦(𝑥𝑘 + 1) − 2∆𝑥𝑦𝑘 + 2∆𝑥 ⋅ 𝑏 − ∆𝑥
⇒ ∆𝑥(𝑑1 − 𝑑2 ) = 2∆𝑦𝑥𝑘 + 2∆𝑦 − 2∆𝑥𝑦𝑘 + 2∆𝑥 ⋅ 𝑏 − ∆𝑥
⇒ ∆𝑥(𝑑1 − 𝑑2 ) = 2∆𝑦𝑥𝑘 − 2∆𝑥𝑦𝑘 + 2∆𝑦 + ∆𝑥(2𝑏 − 1)
⇒ 𝑝𝑘 = 2∆𝑦 ⋅ 𝑥𝑘 − 2∆𝑥 ⋅ 𝑦𝑘 + 𝑐 … … … … . (2)
Where 𝑝𝑘 = ∆𝑥(𝑑1 − 𝑑2 ) is the decision parameter for the 𝑘th step in the line algorithm. Parameter 𝑐 is constant
and has the value 2∆𝑦 + ∆𝑥(2𝑏 − 1), which is independent of pixel position and will be eliminated in the
recursive calculation for 𝑝𝑘 . The sign of 𝑝𝑘 is the same as the sign of 𝑑1 − 𝑑2 , since ∆𝑥 > 0 for our example.
If the pixel at 𝑦𝑘 is closer to the line path than the pixel at 𝑦𝑘 + 1 (that is, 𝑑1 < 𝑑2 ,), then decision parameter
𝑝𝑘 is negative. In that case, we plot the lower pixel; otherwise, we plot the upper pixel.
Coordinate changes along the line occur in unit steps in either the 𝑥 or 𝑦 directions. Therefore, we can obtain
the values of successive decision parameters using incremental integer calculations. At step 𝑘 + 1, the decision
parameter is evaluated from Eq. 2 as
𝑝𝑘+1 = 2∆𝑦 ⋅ 𝑥𝑘+1 − 2∆𝑥 ⋅ 𝑦𝑘+1 + 𝑐 … … … … . (3)
20

Subtracting Eq. 2 from Eq. 3, we have


𝑝𝑘+1 − 𝑝𝑘 = 2∆𝑦(𝑥𝑘+1 − 𝑥𝑘 ) − 2∆𝑥(𝑦𝑘+1 − 𝑦𝑘 )
Since 𝑥𝑘+1 = 𝑥𝑘 + 1, we have
𝑝𝑘+1 − 𝑝𝑘 = 2∆𝑦(𝑥𝑘 + 1 − 𝑥𝑘 ) − 2∆𝑥(𝑦𝑘+1 − 𝑦𝑘 )
⇒ 𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦 − 2∆𝑥(𝑦𝑘+1 − 𝑦𝑘 )
where the term 𝑦𝑘+1 − 𝑦𝑘 is either 0 or 1, depending on the sign of parameter 𝑝𝑘 .
If 𝑝𝑘 < 0, then the true line is close to the lower pixel and 𝑦𝑘+1 = 𝑦𝑘 . Hence
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦 − 2∆𝑥(𝑦𝑘 − 𝑦𝑘 ) = 𝑝𝑘 + 2∆𝑦
On the other hand, if 𝑝𝑘 ≥ 0, then the true line is close to the upper pixel and 𝑦𝑘+1 = 𝑦𝑘 + 1. Hence
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦 − 2∆𝑥(𝑦𝑘+1 − 𝑦𝑘 )
= 𝑝𝑘 + 2∆𝑦 − 2∆𝑥(𝑦𝑘 + 1 − 𝑦𝑘 )
= 𝑝𝑘 + 2∆𝑦 − 2∆𝑥
Hence we have
𝑝 + 2∆𝑦 if 𝑝𝑘 < 0
𝑝𝑘+1 = { 𝑘
𝑝𝑘 + 2∆𝑦 − 2∆𝑥 if 𝑝𝑘 ≥ 0
This recursive calculation of decision parameters is performed at each integer 𝑥 position, starting at the left
coordinate endpoint of the line. The first decision parameter, 𝑝0 , is evaluated from Eq. 2 at the starting pixel
position (𝑥0 , 𝑦0 ) as
𝑝0 = 2∆𝑦 ⋅ 𝑥0 − 2∆𝑥 ⋅ 𝑦0 + 𝑐
∆𝑦 ∆𝑦
⇒ 𝑝0 = 2∆𝑦 ⋅ 𝑥0 − 2∆𝑥 ( ⋅ 𝑥 + 𝑏) + 2∆𝑦 + 2∆𝑥 ⋅ 𝑏 − ∆𝑥 [∵ 𝑦0 = ⋅ 𝑥 + 𝑏]
∆𝑥 0 ∆𝑥 0
⇒ 𝑝0 = 2∆𝑦 ⋅ 𝑥0 − 2∆𝑦 ⋅ 𝑥0 − 2∆𝑥 ⋅ 𝑏 + 2∆𝑦 + 2∆𝑥 ⋅ 𝑏 − ∆𝑥
∴ 𝑝0 = 2∆𝑦 − ∆𝑥
For a line with positive slope greater than 1, we interchange the roles of the 𝑥 and 𝑦 directions. That is, we step
along the 𝑦 direction in unit steps and calculate successive 𝑥 values nearest the line path.
Bresenham's Line Drawing Algorithm for |𝒎| < 𝟏
1. Input the two endpoints of line and store the left endpoint in (𝑥0 , 𝑦0 )
2. Plot the point (𝑥0 , 𝑦0 )
3. Calculate the constants ∆𝑥, ∆𝑦, 2∆𝑦, and 2∆𝑦 − 2∆𝑥, and obtain the starting value for the decision
parameter as
𝑝0 = 2∆𝑦 − ∆𝑥
4. At each 𝑥𝑘 along the line, starting at 𝑘 = 0, perform the following test:
If 𝑝𝑘 < 0, the next point to plot is (𝑥𝑘 + 1, 𝑦𝑘 ) and
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦
Otherwise, the next point to plot is (𝑥𝑘 + 1, 𝑦𝑘 + 1) and
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦 − 2∆𝑥
5. Repeat step-4 (∆𝑥 − 1) times
21

Bresenham's Line Drawing Algorithm for |𝒎| ≥ 𝟏


1. Input the two endpoints of line and store the left endpoint in (𝑥0 , 𝑦0 )
2. Plot the point (𝑥0 , 𝑦0 )
3. Calculate the constants ∆𝑥, ∆𝑦, 2∆𝑥, and 2∆𝑥 − 2∆𝑦, and obtain the starting value for the decision
parameter as
𝑝0 = 2∆𝑥 − ∆𝑦
4. At each 𝑦𝑘 along the line, starting at 𝑘 = 0, perform the following test:
If 𝑝𝑘 < 0, the next point to plot is (𝑥𝑘 , 𝑦𝑘 + 1) and
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑥
Otherwise, the next point to plot is (𝑥𝑘 + 1, 𝑦𝑘 + 1) and
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑥 − 2∆𝑦
5. Repeat step-4 (∆𝑦 − 1) times
Some special condition for line drawing algorithm
 If we start at right end point both 𝑥 and 𝑦 decrease as we step from right to left.
 For a negative slope 𝑚 < 0, the procedures are similar except that one coordinate decreases and other
coordinate increases.
 For special case when ∆𝑦 = 0 or ∆𝑥 = 0 or 𝑚 = 1(∆𝑦 = ∆𝑥) each can be loaded in buffer without
processing through the line algorithm.

Circle Generating Algorithms


It is not easy to display a continuous smooth arc on the computer screen as our computer screen is made of
pixels organized in matrix form. So, to draw a circle on a computer screen we should always choose the nearest
pixels from a printed pixel so as they could form an arc. There are two algorithm to do this:
1. Bresenham’s Circle algorithm
2. Mid-Point Circle algorithm
Both of these algorithms uses the key feature of circle that it is highly symmetric. So, for whole 360 ° of circle
we will divide it in 8-parts each octant of 45°. Assumes that the circle is centered on the origin. So for every
pixel (𝑥, 𝑦) it calculates, we draw a pixel in each of the 8 octants of the circle as shown below:

or

Figure 3-4: Eight-point symmetry of a circle


22

Bresenham’s Circle algorithm


Bresenham's Circle Algorithm is a widely used method for drawing circles in computer graphics. This algorithm
efficiently calculates and plots the points along the circumference of a circle, given its center (𝑥𝑐 , 𝑦𝑐 ) and
radius 𝑟.
To illustrate Bresenham's Circle Algorithm, we first consider the scan-conversion process for circles with
center at (0, 0). Scan-converting a circle using Bresenham's algorithm works as follows. Points are generated
from 90° to 45°, moves will be made only in the +𝑥 and −𝑦 directions (see Fig. 3-5).

Figure 3-5: Circle scan-converted with Bresenham's algorithm.


The best approximation of the true circle will be described by those pixels in the raster that fall the least distance
from the true circle. Examine Fig. 3-6. Notice that, if points are generated from 90° and 45°, each new point
closest to the true circle can be found by taking either of two actions:
1. Move in the x-direction one unit, or
2. Move in the x-direction one unit and move in the negative y-direction one unit.

Figure 3-6: Choosing pixels in Bresenham's circle algorithm.


Assume that (𝑥𝑖 , 𝑦𝑖 ) are the coordinates of the last scan-converted pixel upon entering step 𝑖 (see Fig. 3-6). Let
the distance from the origin to pixel T squared minus the distance to the true circle squared = 𝐷(𝑇). Then let
the distance from the origin to pixel S squared minus the distance to the true circle squared = 𝐷(𝑆). As the
coordinates of T are (𝑥𝑖 + 1, 𝑦𝑖 ) and those of S are (𝑥𝑖 + 1, 𝑦𝑖 − 1), the following expressions can be developed:
𝐷(𝑇) = (𝑥𝑖 + 1)2 + 𝑦𝑖2 − 𝑟 2
and
𝐷(𝑆) = (𝑥𝑖 + 1)2 + (𝑦𝑖 − 1)2 − 𝑟 2
23

This function D provides a relative measurement of the distance from the center of a pixel to the true circle.
Since 𝐷(𝑇) will always be positive (T is outside the true circle) and 𝐷(𝑆) will always be negative (S is inside
the true circle), a decision parameter 𝑝𝑖 may be defined as follows:
𝑝𝑖 = 𝐷(𝑇) + 𝐷(𝑆)
Therefore
𝑝𝑖 = 2(𝑥𝑖 + 1)2 + 𝑦𝑖2 + (𝑦𝑖 − 1)2 − 2𝑟 2 … … … … . (1)
When 𝑝𝑖 < 0, we have |𝐷(𝑇)| < |𝐷(𝑆)| and pixel T is chosen. When 𝑝𝑖 ≥ 0, we have |𝐷(𝑇)| ≥ |𝐷(𝑆)| and
pixel S is selected. We can also write the decision parameter 𝑝𝑖+1 for the next step:
2
𝑝𝑖+1 = 2(𝑥𝑖+1 + 1)2 + 𝑦𝑖+1 + (𝑦𝑖+1 − 1)2 − 2𝑟 2 … … … … . (2)
Subtracting Eq. 1 from equation Eq. 2, we have
2
𝑝𝑖+1 − 𝑝𝑖 = 2(𝑥𝑖+1 + 1)2 + 𝑦𝑖+1 + (𝑦𝑖+1 − 1)2 − 2(𝑥𝑖 + 1)2 − 𝑦𝑖2 − (𝑦𝑖 − 1)2
Since 𝑥𝑖+1 = 𝑥𝑖 + 1, we have
2
𝑝𝑖+1 = 𝑝𝑖 + 4𝑥𝑖 + 2(𝑦𝑖+1 − 𝑦𝑖2 ) − 2(𝑦𝑖+1 − 𝑦𝑖 ) + 6
If T is the chosen pixel (meaning that 𝑝𝑖 < 0) then 𝑦𝑖+1 = 𝑦𝑖 and so
𝑝𝑖+1 = 𝑝𝑖 + 4𝑥𝑖 + 6
On the other hand, if S is the chosen pixel (meaning that 𝑝𝑖 ≥ 0) then 𝑦𝑖+1 = 𝑦𝑖 − 1 and so
𝑝𝑖+1 = 𝑝𝑖 + 4(𝑥𝑖 − 𝑦𝑖 ) + 10
Hence we have
𝑝 + 4𝑥𝑖 + 6 if 𝑝𝑖 < 0
𝑝𝑖+1 = { 𝑖
𝑝𝑖 + 4(𝑥𝑖 − 𝑦𝑖 ) + 10 if 𝑝𝑖 ≥ 0
Finally, we set (0, 𝑟) to be the starting pixel coordinates and compute the initial decision parameter 𝑝0 from
Eq. 1 as
𝑝0 = 2(0 + 1)2 + 𝑟 2 + (𝑟 − 1)2 − 2𝑟 2 = 3 − 2𝑟
Bresenham’s Circle Drawing Algorithm
1. Input radius 𝑟 and circle center (𝑥𝑐 , 𝑦𝑐 ), and obtain the first point on the circumference of a circle
centered on the origin as
(𝑥0 , 𝑦0 ) = (0, 𝑟)
2. Calculate the initial value of the decision parameter as
𝑝0 = 3 − 2𝑟
3. At each 𝑥𝑖 position, starting at 𝑖 = 0, perform the following test:
If 𝑝𝑖 < 0, the next point along the circle centered on (0, 0) is (𝑥𝑖 + 1, 𝑦𝑖 ) and
𝑝𝑖+1 = 𝑝𝑖 + 4𝑥𝑖 + 6
Otherwise, the next point along the circle is (𝑥𝑖 + 1, 𝑦𝑖 − 1) and
𝑝𝑖+1 = 𝑝𝑖 + 4(𝑥𝑖 − 𝑦𝑖 ) + 10
4. Determine symmetry points in the other seven octants.
5. Move each calculated pixel position (𝑥, 𝑦) onto the circular path centered on (𝑥𝑐 , 𝑦𝑐 ) and plot the
coordinate values:
𝑥 = 𝑥 + 𝑥𝑐
𝑦 = 𝑦 + 𝑦𝑐
6. Repeat steps 3 through 5 until 𝑥 ≥ 𝑦.

Or, more precisely:


1. Input radius 𝑟 and circle center (𝑥𝑐 , 𝑦𝑐 ).
2. Calculate the initial value of the decision parameter as
24

𝑝 = 3 − 2𝑟
3. Initialize, 𝑥 = 0 and 𝑦 = 𝑟.
4. Repeat steps 5 through 6 while 𝑥 ≤ 𝑦:
5. Plot eight points by using concepts of eight-way symmetry. The center is at (𝑥𝑐 , 𝑦𝑐 ). Current active pixel
is (𝑥, 𝑦).
Set pixel at position (𝑥 + 𝑥𝑐 , 𝑦 + 𝑦𝑐 )
Set pixel at position (𝑦 + 𝑥𝑐 , 𝑥 + 𝑦𝑐 )
Set pixel at position (−𝑦 + 𝑥𝑐 , 𝑥 + 𝑦𝑐 )
Set pixel at position (−𝑥 + 𝑥𝑐 , 𝑦 + 𝑦𝑐 )
Set pixel at position (−𝑥 + 𝑥𝑐 , −𝑦 + 𝑦𝑐 )
Set pixel at position (−𝑦 + 𝑥𝑐 , −𝑥 + 𝑦𝑐 )
Set pixel at position (𝑦 + 𝑥𝑐 , −𝑥 + 𝑦𝑐 )
Set pixel at position (𝑥 + 𝑥𝑐 , −𝑦 + 𝑦𝑐 )
6. Find location of next pixels to be scanned.
If 𝑝 < 0, then:
𝑥 =𝑥+1
𝑝 = 𝑝 + 4𝑥 + 6
Else:
𝑥 =𝑥+1
𝑦 =𝑦−1
𝑝 = 𝑝 + 4(𝑥 − 𝑦) + 10
7. Exit.
Midpoint Circle Algorithm
Midpoint Circle Algorithm is an incremental circle algorithm that is very similar to Bresenham's approach.
To apply the midpoint method, we define a circle function:
𝑓𝑐𝑖𝑟𝑐𝑙𝑒 (𝑥, 𝑦) = 𝑥 2 + 𝑦 2 − 𝑟 2 … … … … (1)
Any point (𝑥, 𝑦) on the boundary of the circle with radius 𝑟 satisfies the equation 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 (𝑥, 𝑦) = 0. If the point
is in the interior of the circle, the circle function is negative. And if the point is outside the circle, the circle
function is positive. To summarize, the relative position of any point (𝑥, 𝑦) can be determined by checking the
sign of the circle function:
< 0, if (𝑥, 𝑦) is inside the circle boundary
𝑓𝑐𝑖𝑟𝑐𝑙𝑒 (𝑥, 𝑦) {= 0, if (𝑥, 𝑦) is on the circle boundary … … … … (2)
> 0, if (𝑥, 𝑦) is outside the circle boundary
The circle-function tests in Eq. 2 are performed for the midpoints between pixels near the circle path at each
sampling step. Thus, the circle function is the decision parameter in the midpoint algorithm.

Figure 3-7: Midpoint between candidate pixels at sampling position 𝑥𝑘 + 1 along a circular path.
25

Figure 3-7 shows the midpoint between the two candidate pixels at sampling position 𝑥𝑘 + 1. Assume that we
have just plotted the pixel at (𝑥𝑘 , 𝑦𝑘 ). We next need to determine whether the pixel at position (𝑥𝑘 + 1, 𝑦𝑘 ) or
the one at position (𝑥𝑘 + 1, 𝑦𝑘 − 1) is closer to the circle.
Let 𝑀 is the midpoint between (𝑥𝑘 + 1, 𝑦𝑘 ) and (𝑥𝑘 + 1, 𝑦𝑘 − 1). Then, the co-ordinates of 𝑀 are
𝑥𝑘 + 1 + 𝑥𝑘 + 1 𝑦𝑘 + 𝑦𝑘 − 1 1
𝑀=( , ) = (𝑥𝑘 + 1, 𝑦𝑘 − )
2 2 2
Our decision parameter is the circle function-(1) evaluated at the midpoint: (or, We use this midpoint to define
our decision parameter as)
1
𝑝𝑘 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 (𝑥𝑘 + 1, 𝑦𝑘 − )
2
1 2
= (𝑥𝑘 + 1)2 + (𝑦𝑘 − ) − 𝑟 2 … … … … (3)
2
If 𝑝𝑘 < 0, the midpoint is inside the circle and the pixel at 𝑦𝑘 is closer to the circle boundary. Otherwise, the
midpoint is outside or on the boundary and the pixel at 𝑦𝑘 − 1 is closer to the circle boundary.
Successive decision parameters are obtained using incremental calculations. We obtain a recursive expression
for the next decision parameter by evaluating the circle function at sampling position 𝑥𝑘+1 + 1 = 𝑥𝑘 + 2:
1
𝑝𝑘+1 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 (𝑥𝑘+1 + 1, 𝑦𝑘+1 − )
2
1 2
= (𝑥𝑘+1 + 1)2 + (𝑦𝑘+1 − ) − 𝑟 2 … … … … (4)
2
Subtracting Eq. 3 from equation Eq. 4, we have
1 2 1 2
𝑝𝑘+1 − 𝑝𝑘 = 𝑘+1 + 1) + (𝑦𝑘+1 − ) − 𝑟 − 𝑘 + 1) − (𝑦𝑘 − ) + 𝑟 2
(𝑥 2 2 (𝑥 2
2 2
1 2 1 2
= (𝑥𝑘+1 + 1)2 + (𝑦𝑘+1 − ) − (𝑥𝑘 + 1)2 − (𝑦𝑘 − )
2 2
2
1 2 2
1 2
= [(𝑥𝑘 + 1) + 1] + (𝑦𝑘+1 − ) − (𝑥𝑘 + 1) − (𝑦𝑘 − ) [∵ 𝑥𝑘+1 = 𝑥𝑘 + 1]
2 2
2
1 1
= (𝑥𝑘 + 1)2 + 2(𝑥𝑘 + 1) + 1 + 𝑦𝑘+1 − 𝑦𝑘+1 + − (𝑥𝑘 + 1)2 − 𝑦𝑘2 + 𝑦𝑘 −
4 4
2 2
= 2(𝑥𝑘 + 1) + 1 + 𝑦𝑘+1 − 𝑦𝑘+1 − 𝑦𝑘 + 𝑦𝑘
2
= 2𝑥𝑘 + 𝑦𝑘+1 − 𝑦𝑘2 − 𝑦𝑘+1 + 𝑦𝑘 + 3
Therefore
2
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘 + 𝑦𝑘+1 − 𝑦𝑘2 − 𝑦𝑘+1 + 𝑦𝑘 + 3
where 𝑦𝑘+1 is either 𝑦𝑘 or 𝑦𝑘−1 , depending on the sign of 𝑝𝑘 .
If 𝑝𝑘 < 0 then 𝑦𝑘+1 = 𝑦𝑘 and so
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘 + 𝑦𝑘2 − 𝑦𝑘2 − 𝑦𝑘 + 𝑦𝑘 + 3
= 𝑝𝑘 + 2𝑥𝑘 + 3
= 𝑝𝑘 + 2(𝑥𝑘 + 1) + 1
On the other hand, if 𝑝𝑘 ≥ 0 then 𝑦𝑘+1 = 𝑦𝑘 − 1 and so
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘 + (𝑦𝑘 − 1)2 − 𝑦𝑘2 − (𝑦𝑘 − 1) + 𝑦𝑘 + 3
= 𝑝𝑘 + 2𝑥𝑘 + 𝑦𝑘2 − 2𝑦𝑘 + 1 − 𝑦𝑘2 − 𝑦𝑘 + 1 + 𝑦𝑘 + 3
= 𝑝𝑘 + 2𝑥𝑘 − 2𝑦𝑘 + 5
26

= 𝑝𝑘 + 2(𝑥𝑘 + 1) − 2(𝑦𝑘 − 1) + 1
We can write it in terms of (𝑥𝑘 , 𝑦𝑘 ) and get
𝑝 + 2𝑥𝑘 + 3 if 𝑝𝑘 < 0
𝑝𝑘+1 = { 𝑘
𝑝𝑘 + 2𝑥𝑘 − 2𝑦𝑘 + 5 if 𝑝𝑘 ≥ 0
Or, we can write it in terms of (𝑥𝑘+1 , 𝑦𝑘+1 ) and have
𝑝 + 2𝑥𝑘+1 + 1 if 𝑝𝑘 < 0
𝑝𝑘+1 = { 𝑘
𝑝𝑘 + 2𝑥𝑘+1 − 2𝑦𝑘+1 + 1 if 𝑝𝑘 ≥ 0
Finally, we set (𝑥0 , 𝑦0 ) = (0, 𝑟) to be the starting pixel coordinates and compute the initial decision parameter
𝑝0 from the Eq. 3 as
1
𝑝0 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 (0 + 1, 𝑟 − )
2
1 2
= (0 + 1) + ( 𝑟 − ) − 𝑟 2
2
2
1
= 1 + 𝑟2 − 𝑟 + − 𝑟2
4
5
∴ 𝑝0 = − 𝑟
4
If 𝑟 is an integer, we can simply round 𝑝0 to
𝑝0 = 1 − 𝑟
since all increments are integers.
Midpoint Circle Drawing Algorithm
1. Input radius 𝑟 and circle center (𝑥𝑐 , 𝑦𝑐 ), and obtain the first point on the circumference of a circle
centered on the origin as
(𝑥0 , 𝑦0 ) = (0, 𝑟)
2. Calculate the initial value of the decision parameter as
5
𝑝0 = − 𝑟
4
3. At each 𝑥𝑘 position, starting at 𝑘 = 0, perform the following test:
If 𝑝𝑘 < 0, the next point along the circle centered on (0, 0) is (𝑥𝑘 + 1, 𝑦𝑘 ) and
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1
Otherwise, the next point along the circle is (𝑥𝑘 + 1, 𝑦𝑘 − 1) and
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 − 2𝑦𝑘+1 + 1
where 2𝑥𝑘+1 = 2𝑥𝑘 + 2 and 2𝑦𝑘+1 = 2𝑦𝑘 − 2.
4. Determine symmetry points in the other seven octants.
5. Move each calculated pixel position (𝑥, 𝑦) onto the circular path centered on (𝑥𝑐 , 𝑦𝑐 ) and plot the
coordinate values:
𝑥 = 𝑥 + 𝑥𝑐
𝑦 = 𝑦 + 𝑦𝑐
6. Repeat steps 3 through 5 until 𝑥 ≥ 𝑦.

Or, more precisely:


1. Input radius 𝑟 and circle center (𝑥𝑐 , 𝑦𝑐 ).
2. Calculate the initial value of the decision parameter as
𝑝=1−𝑟
3. Initialize, 𝑥 = 0 and 𝑦 = 𝑟.
4. Repeat steps 5 through 6 while 𝑥 ≤ 𝑦:
27

5. Plot eight points by using concepts of eight-way symmetry. The center is at (𝑥𝑐 , 𝑦𝑐 ). Current active pixel
is (𝑥, 𝑦).
Set pixel at position (𝑥 + 𝑥𝑐 , 𝑦 + 𝑦𝑐 )
Set pixel at position (𝑦 + 𝑥𝑐 , 𝑥 + 𝑦𝑐 )
Set pixel at position (−𝑦 + 𝑥𝑐 , 𝑥 + 𝑦𝑐 )
Set pixel at position (−𝑥 + 𝑥𝑐 , 𝑦 + 𝑦𝑐 )
Set pixel at position (−𝑥 + 𝑥𝑐 , −𝑦 + 𝑦𝑐 )
Set pixel at position (−𝑦 + 𝑥𝑐 , −𝑥 + 𝑦𝑐 )
Set pixel at position (𝑦 + 𝑥𝑐 , −𝑥 + 𝑦𝑐 )
Set pixel at position (𝑥 + 𝑥𝑐 , −𝑦 + 𝑦𝑐 )
6. Find location of next pixels to be scanned.
If 𝑝 < 0, then:
𝑝 = 𝑝 + 2𝑥 + 3
𝑥 =𝑥+1
Else:
𝑝 = 𝑝 + 2𝑥 − 2𝑦 + 5
𝑥 =𝑥+1
𝑦 =𝑦−1
7. Exit.

Ellipse Generating Algorithm


The ellipse, like the circle, shows symmetry. In the case of an ellipse, however, symmetry is four rather than
eight-way.

Figure 3-8: Four-point symmetry of an ellipse.


Note:
𝑑𝑦 𝜕𝑥
The slope of a curve defined by 𝑓(𝑥, 𝑦) = 0 is 𝑑𝑥
= − 𝜕𝑦, where 𝜕𝑥 and 𝜕𝑦 are partial derivatives of 𝑓(𝑥, 𝑦)
with respect to 𝑥 and 𝑦, respectively.
The equation of an ellipse is
𝑥2 𝑦2
+ =1
𝑎2 𝑏 2
⇒ 𝑏 2 𝑥 2 + 𝑎2 𝑦 2 − 𝑎2 𝑏 2 = 0 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥, 𝑦)
𝑑𝑦 2𝑏2 𝑥
Hence, the ellipse slope, 𝑑𝑥 = − 2𝑎2𝑦
28

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 its major and minor axes parallel to the coordinate system axes). It works in a way that is very similar
to the midpoint circle algorithm. For understanding the proper working of the algorithm, let us consider the
elliptical curve in the first quadrant.
The midpoint ellipse method is applied throughout the first quadrant in two parts. Figure 3-9 shows the division
of the first quadrant according to the slope of an ellipse with 𝑟𝑥 < 𝑟𝑦 . We process this quadrant by taking unit
steps in the 𝑥 direction where the slope of the curve has a magnitude less than 1, and taking unit steps in the
𝑦 direction where the slop has a magnitude greater than 1.

𝑑𝑦
* In region 1, > −1
𝑑𝑥

𝑑𝑦
* In region 2, < −1
𝑑𝑥

Figure 3-9: Ellipse processing regions. Over region 1, the magnitude of the ellipse
slope is less than 1; over region 2, the magnitude of the slope is greater than 1.
Regions 1 and 2 (Fig. 3-9), can he processed in various ways. We can start at position (0, 𝑟𝑦 ) and step clockwise
along the elliptical path in the first quadrant, shifting from unit steps in 𝑥 to unit steps in 𝑦 when the slope
becomes less than −1. Alternatively, we could start at (𝑟𝑥 , 0) and select points in a counterclockwise order,
shifting from unit steps in 𝑦 to unit steps in 𝑥 when the slope becomes greater than −1. With parallel processors,
we could calculate pixel positions in the two regions simultaneously. As an example of a sequential
implementation of the midpoint algorithm, we take the start position at (0, 𝑟𝑦 ) and step along the ellipse path in
clockwise order throughout the first quadrant.
Let's define an ellipse function with (𝑥𝑐 , 𝑦𝑐 ) = (0, 0) as
𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥, 𝑦) = 𝑟𝑦2 𝑥 2 + 𝑟𝑥2 𝑦 2 − 𝑟𝑥2 𝑟𝑦2 … … … … (1)
which has the following properties:
< 0, if (𝑥, 𝑦) is inside the ellipse boundary
𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥, 𝑦) { = 0, if (𝑥, 𝑦) is on the ellipse boundary … … … … (2)
> 0, if (𝑥, 𝑦) is outside the ellipse boundary
Thus, the ellipse function 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥, 𝑦) serves as the decision parameter in the midpoint algorithm. At each
sampling position, we select the next pixel along the ellipse path according to the sign of the ellipse function
evaluated at the midpoint between the two candidate pixels.
Starting at (0, 𝑟𝑦 ), we take unit steps in the 𝑥 direction until we reach the boundary between region 1 and region
2 (Fig. 3-9). Then we switch to unit steps in the 𝑦 direction over the remainder of the curve in the first quadrant.
At each step, we need to test the value of the slope of the curve. The ellipse slope is calculated from Eq. 1 as
𝑑𝑦 2𝑟𝑦2 𝑥
=− 2
𝑑𝑥 2𝑟𝑥 𝑦
29

𝑑𝑦
At the boundary between region 1 and region 2, 𝑑𝑥 = −1 and
2𝑟𝑦2 𝑥 = 2𝑟𝑥2 𝑦
Therefore, we move out of region 1 whenever
2𝑟𝑦2 𝑥 ≥ 2𝑟𝑥2 𝑦
For the region 1:

Figure 3-10: Midpoint between candidate pixels at sampling position 𝑥𝑘 + 1 along an elliptical path.
Figure 3-10 shows the midpoint between the two candidate pixels at sampling position 𝑥𝑘 + 1 in the first regon.
Assuming position (𝑥𝑘 , 𝑦𝑘 ) has been selected at the previous step. We next need to determine whether the pixel
at position (𝑥𝑘 + 1, 𝑦𝑘 ) or the one at position (𝑥𝑘 + 1, 𝑦𝑘 − 1) is closer to the circle. We determine the next
position along the ellipse path by evaluating the decision parameter (that is, the ellipse function 1) at this
midpoint:
1
𝑝1𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥𝑘 + 1, 𝑦𝑘 − )
2
1 2
= 𝑟𝑦2 (𝑥𝑘 + 1)2 + 𝑟𝑥2 (𝑦𝑘 − ) − 𝑟𝑥2 𝑟𝑦2 … … … … (3)
2
If 𝑝1𝑘 < 0, the midpoint is inside the ellipse and the pixel on scan line 𝑦𝑘 , is closer to the ellipse boundary.
Otherwise, the midpoint is outside or on the ellipse boundary, and we select the pixel on scan line 𝑦𝑘 − 1.
At the next sampling position (𝑥𝑘+1 + 1 = 𝑥𝑘 + 2), the decision parameter for region 1 is evaluated as
1
𝑝1𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥𝑘+1 + 1, 𝑦𝑘+1 − )
2
1 2
= 𝑟𝑦2 (𝑥𝑘+1 + 1)2 + 𝑟𝑥2 (𝑦𝑘+1 − ) − 𝑟𝑥2 𝑟𝑦2 … … … … (4)
2
Subtracting Eq. 3 from equation Eq. 4, we have
1 2 1 2
𝑝1𝑘+1 − 𝑝1𝑘 = 𝑟𝑦2 (𝑥𝑘+1 + 1)2 + 𝑟𝑥2 (𝑦𝑘+1 − ) − 𝑟𝑥2 𝑟𝑦2 − 𝑟𝑦2 (𝑥𝑘 + 1)2 − 𝑟𝑥2 (𝑦𝑘 − ) + 𝑟𝑥2 𝑟𝑦2
2 2
1 2 1 2
= 𝑟𝑦2 (𝑥𝑘+1 2
+ 1) + 𝑟𝑥2 (𝑦𝑘+1 2 (𝑥 2 2
− ) − 𝑟𝑦 𝑘 + 1) − 𝑟𝑥 (𝑦𝑘 − )
2 2
1 2 1 2
= 𝑟𝑦2 [(𝑥𝑘 + 1) + 1]2 + 𝑟𝑥2 (𝑦𝑘+1 − ) − 𝑟𝑦2 (𝑥𝑘 + 1)2 − 𝑟𝑥2 (𝑦𝑘 − ) [∵ 𝑥𝑘+1 = 𝑥𝑘 + 1]
2 2
1 2 1 2
= 2𝑟𝑦2 (𝑥𝑘 + 1) + 𝑟𝑦2 + 𝑟𝑥2 [(𝑦𝑘+1 − ) − (𝑦𝑘 − ) ]
2 2
30

Therefore
1 2 1 2
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦2 (𝑥𝑘 + 1) + 𝑟𝑦2 + 𝑟𝑥2 [(𝑦𝑘+1 − ) − (𝑦𝑘 − ) ]
2 2
where 𝑦𝑘+1 is either 𝑦𝑘 or 𝑦𝑘 − 1, depending on the sign of 𝑝1𝑘 .
If 𝑝1𝑘 < 0 then 𝑦𝑘+1 = 𝑦𝑘 and so
1 2 1 2
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦2 (𝑥𝑘 + 1) + 𝑟𝑦2 + 𝑟𝑥2 [(𝑦𝑘 − ) − (𝑦𝑘 − ) ]
2 2
= 𝑝1𝑘 + 2𝑟𝑦2 (𝑥𝑘 + 1) + 𝑟𝑦2
= 𝑝1𝑘 + 2𝑟𝑦2 𝑥𝑘+1 + 𝑟𝑦2
On the other hand, if 𝑝1𝑘 ≥ 0 then 𝑦𝑘+1 = 𝑦𝑘 − 1 and so
1 2 1 2
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦2 (𝑥𝑘 + 1) + 𝑟𝑦2 + 𝑟𝑥2 [(𝑦𝑘 − 1 − ) − (𝑦𝑘 − ) ]
2 2
= 𝑝1𝑘 + 2𝑟𝑦2 (𝑥𝑘 + 1) + 𝑟𝑦2 − 2𝑟𝑥2 (𝑦𝑘 − 1)
= 𝑝1𝑘 + 2𝑟𝑦2 𝑥𝑘+1 + 𝑟𝑦2 − 2𝑟𝑥2 𝑦𝑘+1
Thus we can express 𝑝1𝑘+1 in terms of 𝑝1𝑘 and (𝑥𝑘 , 𝑦𝑘 ) as
𝑝1𝑘 + 2𝑟𝑦2 𝑥𝑘 + 3𝑟𝑦2 if 𝑝1𝑘 < 0
𝑝1𝑘+1 = {
𝑝1𝑘 + 2𝑟𝑦2 𝑥𝑘 + 3𝑟𝑦2 − 2𝑟𝑥2 𝑦𝑘 + 2𝑟𝑥2 if 𝑝1𝑘 ≥ 0
Or, we can express 𝑝1𝑘+1 in terms of 𝑝1𝑘 and (𝑥𝑘+1 , 𝑦𝑘+1 ) as
𝑝1𝑘 + 2𝑟𝑦2 𝑥𝑘+1 + 𝑟𝑦2 if 𝑝1𝑘 < 0
𝑝1𝑘+1 = {
𝑝1𝑘 + 2𝑟𝑦2 𝑥𝑘+1 + 𝑟𝑦2 − 2𝑟𝑥2 𝑦𝑘+1 if 𝑝1𝑘 ≥ 0
In region 1, the initial value of the decision parameter is obtained by evaluating the ellipse function-(1) at the
start position (𝑥0 , 𝑦0 ) = (0, 𝑟𝑦 ):
1
𝑝10 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (1, 𝑟𝑦 − )
2
1 2
= 𝑟𝑦2 + 𝑟𝑥2 (𝑟𝑦 − ) − 𝑟𝑥2 𝑟𝑦2
2
1
∴ 𝑝10 = 𝑟𝑦2 − 𝑟𝑥2 𝑟𝑦 + 𝑟𝑥2
4
For the region 2:

Figure 3-11: Midpoint between candidate pixels at sampling position 𝑦𝑘 − 1 along an elliptical path.
31

Over region 2, we sample at unit steps in the negative 𝑦 direction, and the midpoint is now taken between
horizontal pixels at each step (Fig. 3-22). For this region, the decision parameter is evaluated as
1
𝑝2𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥𝑘 + , 𝑦𝑘 − 1)
2
1 2
= 𝑟𝑦2 (𝑥𝑘 + ) + 𝑟𝑥2 (𝑦𝑘 − 1)2 − 𝑟𝑥2 𝑟𝑦2 … … … … (5)
2
If 𝑝2𝑘 > 0, the midpoint is outside the ellipse boundary, and we select the pixel at 𝑥𝑘 . If 𝑝2𝑘 ≤ 0, the midpoint
is inside or on the ellipse boundary, and we select pixel position 𝑥𝑘 + 1.
To determine the relationship between successive decision parameters in region 2, we evaluate the ellipse
function at the next sampling step 𝑦𝑘+1 − 1 = 𝑦𝑘 − 2:
1
𝑝2𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥𝑘+1 + , 𝑦𝑘+1 − 1)
2
1 2
= 𝑟𝑦2 (𝑥𝑘+1
+ ) + 𝑟𝑥2 (𝑦𝑘+1 − 1)2 − 𝑟𝑥2 𝑟𝑦2 … … … … (6)
2
Subtracting Eq. 5 from equation Eq. 6, we have
1 2 1 2
𝑝2𝑘+1 − 𝑝2𝑘 = 𝑟𝑦2 (𝑥𝑘+1 + ) + 𝑟𝑥 𝑘+1 − 1) − 𝑟𝑥 𝑟𝑦 − 𝑟𝑦 (𝑥𝑘 + ) − 𝑟𝑥2 (𝑦𝑘 − 1)2 + 𝑟𝑥2 𝑟𝑦2
2 (𝑦 2 2 2 2
2 2
1 2 1 2
= 𝑟𝑦2 (𝑥𝑘+1 + ) + 𝑟𝑥2 (𝑦𝑘+1 − 1)2 − 𝑟𝑦2 (𝑥𝑘 + ) − 𝑟𝑥2 (𝑦𝑘 − 1)2
2 2
1 2 1 2
= 𝑟𝑦2 (𝑥𝑘+1 + ) + 𝑟𝑥2 [(𝑦𝑘 − 1) + 1]2 − 𝑟𝑦2 (𝑥𝑘 + ) − 𝑟𝑥2 (𝑦𝑘 − 1)2 [∵ 𝑦𝑘+1 = 𝑦𝑘 − 1]
2 2
1 2 1 2
= −2𝑟𝑥2 (𝑦𝑘 − 1) + 𝑟𝑥2 + 𝑟𝑦2 [(𝑥𝑘+1 + ) − (𝑥𝑘 + ) ]
2 2
Therefore
1 2 1 2
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥2 (𝑦𝑘 − 1) + 𝑟𝑥2 + 𝑟𝑦2 [(𝑥𝑘+1 + ) − (𝑥𝑘 + ) ]
2 2
where 𝑥𝑘+1 is either 𝑥𝑘 or 𝑥𝑘 + 1, depending on the sign of 𝑝2𝑘 .
If 𝑝2𝑘 > 0 then 𝑥𝑘+1 = 𝑥𝑘 and so
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥2 (𝑦𝑘 − 1) + 𝑟𝑥2
On the other hand, if 𝑝2𝑘 ≤ 0 then 𝑥𝑘+1 = 𝑥𝑘 + 1 and so
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥2 (𝑦𝑘 − 1) + 𝑟𝑥2 + 2𝑟𝑦2 (𝑥𝑘 + 1)
Thus we can express 𝑝2𝑘+1 in terms of 𝑝2𝑘 and (𝑥𝑘 , 𝑦𝑘 ) as
𝑝2𝑘 − 2𝑟𝑥2 𝑦𝑘 + 3𝑟𝑥2 if 𝑝2𝑘 > 0
𝑝2𝑘+1 = {
𝑝2𝑘 − 2𝑟𝑥2 𝑦𝑘 + 3𝑟𝑥2 + 2𝑟𝑦2 𝑥𝑘 + 2𝑟𝑦2 if 𝑝2𝑘 ≤ 0
Or, we can express 𝑝2𝑘+1 in terms of 𝑝2𝑘 and (𝑥𝑘+1 , 𝑦𝑘+1 ) as
𝑝2𝑘 − 2𝑟𝑥2 𝑦𝑘+1 + 𝑟𝑥2 if 𝑝2𝑘 > 0
𝑝2𝑘+1 ={
𝑝2𝑘 − 2𝑟𝑥2 𝑦𝑘+1 + 𝑟𝑥2 + 2𝑟𝑦2 𝑥𝑘+1 if 𝑝2𝑘 ≤ 0
When we enter region 2, the initial position (𝑥0 , 𝑦0 ) is taken as the last position selected in region 1 and the
initial derision parameter in region 2 is then
1
𝑝20 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥0 + , 𝑦0 − 1)
2
32

1 2
= 𝑟𝑦2 (𝑥0 + ) + 𝑟𝑥2 (𝑦0 − 1)2 − 𝑟𝑥2 𝑟𝑦2
2
To simplify the calculation of 𝑝20 , we could select pixel positions in counterclockwise order starting at (𝑟𝑥 , 0).
Unit steps would then be taken in the positive 𝑦 direction up to the last position selected in region 1.
Midpoint Ellipse Drawing Algorithm
1. Input 𝑟𝑥 , 𝑟𝑦 and ellipse center (𝑥𝑐 , 𝑦𝑐 ), and obtain the first point on an ellipse centered on the origin as
(𝑥0 , 𝑦0 ) = (0, 𝑟𝑦 )
2. Calculate the initial value of the decision parameter in region 1 as
1
𝑝10 = 𝑟𝑦2 − 𝑟𝑥2 𝑟𝑦 + 𝑟𝑥2
4
3. At each 𝑥𝑘 position in region 1, starting at 𝑘 = 0, perform the following test:
If 𝑝1𝑘 < 0, the next point along the ellipse centered on (0, 0) is (𝑥𝑘 + 1, 𝑦𝑘 ) and
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦2 𝑥𝑘+1 + 𝑟𝑦2
Otherwise, the next point along the ellipse centered on (0, 0) is (𝑥𝑘 + 1, 𝑦𝑘 − 1) and
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦2 𝑥𝑘+1 + 𝑟𝑦2 − 2𝑟𝑥2 𝑦𝑘+1
with
2𝑟𝑦2 𝑥𝑘+1 = 2𝑟𝑦2 𝑥𝑘 + 2𝑟𝑦2, 2𝑟𝑥2 𝑦𝑘+1 = 2𝑟𝑥2 𝑦𝑘 − 2𝑟𝑥2
and continue step-3 until 2𝑟𝑦2 𝑥 ≥ 2𝑟𝑥2 𝑦.
4. Calculate the initial value of the decision parameter in region 2 using the last point (𝑥0 , 𝑦0 ) calculated
in region 1 as
1 2
𝑝20 = 𝑟𝑦2 (𝑥0 + ) + 𝑟𝑥2 (𝑦0 − 1)2 − 𝑟𝑥2 𝑟𝑦2
2
5. At each 𝑦𝑘 position in region 2, starting at 𝑘 = 0, perform the following test:
If 𝑝2𝑘 > 0, the next point along the ellipse centered on (0, 0) is (𝑥𝑘 , 𝑦𝑘 − 1) and
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥2 𝑦𝑘+1 + 𝑟𝑥2
Otherwise, the next point along the ellipse centered on (0, 0) is (𝑥𝑘 + 1, 𝑦𝑘 − 1) and
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥2 𝑦𝑘+1 + 𝑟𝑥2 + 2𝑟𝑦2 𝑥𝑘+1
and continue step-5 until 𝑦𝑘+1 = 0.
6. For both region determine symmetry points in the other three quadrants.
7. Move each calculated pixel position (𝑥, 𝑦) onto the elliptical path centered on (𝑥𝑐 , 𝑦𝑐 ) and plot the
coordinate values:
𝑥 = 𝑥 + 𝑥𝑐
𝑦 = 𝑦 + 𝑦𝑐

Or, more precisely:


1. Input 𝑟𝑥 , 𝑟𝑦 and ellipse center (𝑥𝑐 , 𝑦𝑐 ).
2. Calculate the initial value of the decision parameter in region 1 as
1
𝑝1 = 𝑟𝑦2 − 𝑟𝑥2 𝑟𝑦 + 𝑟𝑥2
4
3. Initialize initial point of region 1 as
𝑥 = 0 and 𝑦 = 𝑟𝑦
4. Repeat steps 5 through 6 while 2𝑟𝑦2 𝑥 < 2𝑟𝑥2 𝑦:
5. Plot four points by using concepts of eight-way symmetry. The center is at (𝑥𝑐 , 𝑦𝑐 ). Current active pixel
is (𝑥, 𝑦).
plot (𝑥 + 𝑥𝑐 , 𝑦 + 𝑦𝑐 ) plot (−𝑥 + 𝑥𝑐 , −𝑦 + 𝑦𝑐 )
plot (−𝑥 + 𝑥𝑐 , 𝑦 + 𝑦𝑐 ) plot (𝑥 + 𝑥𝑐 , −𝑦 + 𝑦𝑐 )
33

6. Find location of next pixels to be scanned.


If 𝑝1 < 0, then:
𝑝1 = 𝑝1 + 2𝑟𝑦2 𝑥 + 3𝑟𝑦2
𝑥 =𝑥+1
Else:
𝑝1 = 𝑝1 + 2𝑟𝑦2 𝑥 + 3𝑟𝑦2 − 2𝑟𝑥2 𝑦 + 2𝑟𝑥2
𝑥 =𝑥+1
𝑦 =𝑦−1
7. Calculate the initial value of the decision parameter in region 2 using the last point (𝑥, 𝑦) calculated in
region 1 as
1 2
𝑝2 = 𝑟𝑦2 (𝑥 + ) + 𝑟𝑥2 (𝑦 − 1)2 − 𝑟𝑥2 𝑟𝑦2
2
8. Repeat steps 9 through 10 while 𝑦 ≥ 0:
9. Plot four points by using concepts of eight-way symmetry. The center is at (𝑥𝑐 , 𝑦𝑐 ). Current active pixel
is (𝑥, 𝑦).
plot (𝑥 + 𝑥𝑐 , 𝑦 + 𝑦𝑐 )
plot (−𝑥 + 𝑥𝑐 , −𝑦 + 𝑦𝑐 )
plot (−𝑥 + 𝑥𝑐 , 𝑦 + 𝑦𝑐 )
plot (𝑥 + 𝑥𝑐 , −𝑦 + 𝑦𝑐 )
10. Find location of next pixels to be scanned.
If 𝑝2 > 0, then:
𝑝2 = 𝑝2 − 2𝑟𝑥2 𝑦 + 3𝑟𝑥2
𝑦 =𝑦−1
Else:
𝑝2 = 𝑝2 − 2𝑟𝑥2 𝑦 + 3𝑟𝑥2 + 2𝑟𝑦2 𝑥 + 2𝑟𝑦2
𝑥 =𝑥+1
𝑦 =𝑦−1
11. Exit.
Q. Write the reasons to avoid geometric equations for generate objects for computer.
There are several reasons why geometric equations may not be the best choice for generating objects in
computer graphics. Here are some of them:
 Geometric equations can be very complex, especially for more intricate shapes. This can make it
difficult to generate objects quickly and efficiently.
 Solving geometric equations can be computationally expensive, especially for 3D objects and complex
surfaces.
 Rendering objects generated from complex geometric equations can be challenging, requiring advanced
algorithms for shading, texturing, and rendering. This adds to the computational overhead.
 Geometric equations provide limited flexibility for object manipulation and interaction.
34

Q. What is polygon? Classify polygon with diagram.


A polygon is a two-dimensional closed shape formed with more than two straight lines. These straight lines are
connected end-to-end to enclose an area within the shape.
Polygons are classified into two types:
1. Convex Polygon
2. Concave Polygon
Convex Polygon
If all the interior angles of a polygon are strictly less than 180°, then it is known as a convex polygon. In a
convex polygon, all line segments that connect any two points within the polygon remain inside the polygon
boundary. The vertices of a convex polygon are always outwards.

Figure 3-12: Examples of Convex Polygon


Concave Polygon
If one or more interior angles of a polygon are greater than 180°, then it is known as a concave polygon. A
concave polygon can have at least four sides. The vertices of a concave polygon are inwards as well as outwards.

Figure 3-13: Examples of Concave Polygon

Filled Area Primitives / Region Filling


Region filling is the process of filling image or region. Filling can be of boundary or interior region as shown
in fig.3-14 Boundary Fill algorithms are used to fill the boundary and flood-fill algorithm are used to fill the
interior.

Figure 3-14
Inside-Outside Test
Area-filling algorithms and other graphics processes often need to identify interior regions of objects. Graphics
packages normally use either the odd-even rule or the nonzero winding number rule to identify interior regions
of an object.
We apply the odd-even rule, also called the odd parity rule or the even-odd rule, by conceptually drawing a line
from any position P to a distant point outside the coordinate extents of the object and counting the number of
edge crossings along the line. If the number of polygon edges crossed by this line is odd, then P is an interior
point. Otherwise, P is an exterior point. To obtain an accurate edge count, we must be sure that the line path we
choose does not intersect any polygon vertices. Figure 3-15(a) shows the interior and exterior regions obtained
35

from the odd-even rule for a self-intersecting set of edges. The scan-line polygon fill algorithm is an example
of area filling using the odd-even rule.
Another method for defining interior regions is the nonzero winding number rule, which counts the number of
times the polygon edges wind around a particular point in the counterclockwise direction. This count is called
the winding number, and the interior points of a two-dimensional object are defined to be those that have a
nonzero value for the winding number.

(a) Odd Even Rule (b) Nonzero Winding Number Rule


Figure 3-15 Identifying interior and exterior regions for a self-intersecting polygon.
We apply the nonzero winding number rule to polygons by initializing the winding number to 0 and imagining
a line drawn from any position P to a distant point beyond the coordinate extents of the object. The line we
choose must not pass through any vertices. As we move along the line from position P to the distant point, we
count the number of edges that cross the line in each direction. We add 1 to the winding number every time we
intersect a polygon edge that crosses the line from right to left, and we subtract 1 every time we intersect an
edge that crosses from left to right. The final value of the winding number, after all edge crossings have been
counted, determines the relative position of P. If the winding number is nonzero, P is defined to be an interior
point. Otherwise, P is taken to be an exterior point.
Figure 3-15(b) shows the interior and exterior regions defined by the nonzero winding number rule for a
self-intersecting set of edges. For standard polygons and other simple shapes, the nonzero winding number rule
and the odd-even rule give the same results. But for more complicated shapes, the two methods may yield
different interior and exterior regions, as in the example of Fig. 3-15.
Q. How to determine if a point is inside a polygon or not? Explain.
To determine whether a point is inside a polygon or not, we normally use either the odd-even rule or the nonzero
winding number rule.
Odd-Even Rule
Let P(x, y) be the point we are trying to determine if it is inside or outside of a polygon. We apply the odd-even
rule by conceptually drawing a line from the point P to a distant point outside the coordinate extents of the
polygon and counting the number of times the line intersects with the polygon edges. If the number of
intersections is odd, then the point P is inside the polygon; otherwise, it is outside the polygon. To obtain an
accurate edge count, we must be sure that the line path we choose does not intersect any polygon vertices.

Figure 3-16 Odd number indicates inside the polygon and even number indicates outside the polygon
36

Nonzero Winding Number Rule


Another method for defining inside points is the nonzero winding number rule, which counts the number of
times the polygon edges wind around a particular point in the counterclockwise direction. This count is called
the winding number. If the winding number is non-zero, the point is inside the polygon; otherwise, it is outside
the polygon.
We apply the nonzero winding number rule to polygons by initializing the winding number to 0 and imagining
a line drawn from any point P to a distant point beyond the coordinate extents of the polygon. The line we
choose must not pass through any vertices. As we move along the line from position P to the distant point, we
count the number of edges that cross the line in each direction. We add 1 to the winding number every time we
intersect a polygon edge that crosses the line from bottom to top, and we subtract 1 every time we intersect an
edge that crosses from top to bottom. If the final value of the winding number is nonzero, the point P is inside
the polygon; otherwise, it is outside the polygon.

Figure 3-17
In the above figure, we sum up the direction values from which the scan line is passing then the total is
1 – 1 + 1 = 1; which is non-zero. So the point is said to be an interior point.
Boundary Fill Algorithm
The Boundary Fill algorithm fills closed polygons with a specified color. This algorithm starts at a point (pixel)
inside the polygon to be filled and paints the interior outwards towards the boundary. If the boundary is specified
in a single color, the fill algorithm proceeds outward pixel by pixel until the boundary color is encountered.
Boundary Fill Algorithm is recursive in nature. It takes an interior point (𝑥, 𝑦), a fill color, and a boundary color
as the input. Starting from (𝑥, 𝑦), the procedure tests neighboring positions to determine whether they are of the
boundary color. If not, they are painted with the fill color, and their neighbors are tested. This process continues
until all pixels up to the boundary color for the area have been tested.
There are two methods for proceeding to neighboring pixels from the current test position: 4-connected and
8-connected.
4-connected: In this method, four neighboring points are tested (Fig. 3-18(a)). These are the pixel positions that
are right, left, above, and below the current pixel.
8-connected: In this method, eight neighboring points are tested, i.e., right, left, above, below and four diagonal
pixel. This method is used to fill more complex figures.

(a) 4-connected (b) 8-connected


Figure 3-18 Fill methods applied to a 4-connected area (a) and to an 8-connected area (b)
37

Flood Fill Algorithm


Sometimes we want to fill in (or recolor) an area that is not defined within a single color boundary. We can
paint such areas by replacing a specified interior color instead of searching for a boundary color value. This
approach is known as flood-fill algorithm.

Figure 3-19
We start from a specified interior point (𝑥, 𝑦) and reassign all pixel values that are currently set to a given
interior color with the desired fill color. If the area we want to paint has more than one interior color, we can
first reassign pixel values so that all interior points have the same color. Using either a 4-connected or
8-connected approach, we then step through pixel positions until all interior points have been repainted.
Scan Line Polygon Fill Algorithm
The Scan-Line Polygon Fill Algorithm is used to fill closed polygons by dividing the polygon into horizontal
lines (scan lines) and determining the intersections between these lines and the polygon edges. Figure 3-20
illustrates the scan-line procedure for solid filling of polygon areas. For each scan line crossing a polygon, the
area-fill algorithm locates the intersection points of the scan line with the polygon edges. These intersection
points are then sorted from left to right, and the corresponding frame-buffer positions between each intersection
pair are set to the specified fill color. In the example of Fig. 3-20, the four pixel intersection positions with the
polygon boundaries define two stretches of interior pixels from 𝑥 = 10 to 𝑥 = 14 and from 𝑥 = 18 to 𝑥 = 24.

Figure 3-20 Interior pixels along a scan line passing through a polygon area
Some scan-Line intersections at polygon vertices require special handling (Fig. 3-21):
1. If both lines intersecting at the vertex are on the same side of the scanline, consider it as two points.
2. If lines intersecting at the vertex are at opposite sides of the scanline, consider it as only one point.

Figure 3-21 Intersection points along scan lines that intersect polygon vertices
38

Character Generation Technique


Letters, numbers, and other characters can be displayed in a variety of sizes and styles. The overall design style
for a set (or family) of characters is called a typeface or font. Commonly used fonts include Arial, Century
Schoolbook, Courier, and Times New Roman. In addition, fonts can vary in appearance: bold, italic, and bold
and italic.
There are two methods for character generation:
1. Bitmap Method or Dot-Matrix Method
2. Stroke Method or Vector Method or Outline Method
Bitmap Method
The Bitmap Method is a method used for generating characters in computer graphics. In this method, the
character shapes in a particular font are represented in form of rectangular grid patterns. The set of characters
are then referred to as a bitmap font (or bitmapped font). This method uses an array of 1’s and 0’s to represent
pixels. Figure 3-22 illustrates the bitmap method for character representation.

Figure 3-22 The letter "B" represented with an 8 by 8 bilevel bitmap pattern
When the pattern in Fig. 3-22 is copied to an area of the frame buffer, the 1 bits designate which pixel positions
are to be displayed on the monitor. The size of the array determines the font size of the character.
Bitmap fonts are the simplest to define and display. The character grid only needs to be mapped to a frame
buffer position. However, bitmap fonts require more space, because each variation (size and format) must be
stored in a font cache. It is possible to generate different sizes and other variations, such as bold and italic, from
one set, but this usually does not produce good results.
Stroke Method
The Stroke Method is another method used for generating characters in computer graphics. In this method,
graphical primitives such as lines and arcs are used to define the outline of each character. In this case, the set
of characters is called an outline font. Figure 3-23 illustrates the stroke method for character representation. To
display the character shape in Fig. 3-23, the interior of the character outline must be filled using the scan-line
fill procedure.

Figure 3-23 The letter "B" represented with an outline shape defined with straight-line and curve segments
39

In contrast to bitmap fonts, outline fonts require less storage since each variation does not require a distinct font
cache. We can produce boldface, italic, or different sizes by manipulating the curve definitions for the character
outlines. For example, the outline definition in Fig. 3-23 can be resized through a scaling transformation, made
into italic through a shearing transformation, and turned around with respect to a reference point through a
rotation transformation. But it does take more time to process the outline fonts, because they must be scan
converted into the frame buffer.
Q. Describe bitmap font and outline font.
There are two basic approaches to character representation/Two different representations are used for storing
computer fonts:
1. Bitmap Font
2. Outline Font
Bitmap Font
A simple method for representing the character shapes in a particular typeface is to use rectangular grid patterns.
The set of characters are then referred to as a bitmap font (or bitmapped font). Figure 3-22 illustrates the bitmap
method for character representation. When the pattern in Fig. 3-22 is copied to an area of the frame buffer, the
1 bits designate which pixel positions are to be displayed on the monitor.
Bitmap fonts are the simplest to define and display. The character grid only needs to be mapped to a frame
buffer position. However, bitmap fonts require more space, because each variation (size and format) must be
stored in a font cache. It is possible to generate different sizes and other variations, such as bold and italic, from
one set, but this usually does not produce good results.
Outline Font
Another, more flexible, character representation method is called a vector or outline font, where graphical
primitives such as lines and arcs are used to define the outline of each character. Figure 3-23 illustrates the
stroke method for character representation. To display the character shape in Fig. 3-23, the interior of the
character outline must be filled using the scan-line fill procedure.
In contrast to bitmap fonts, outline fonts require less storage since each variation does not require a distinct font
cache. We can produce boldface, italic, or different sizes by manipulating the curve definitions for the character
outlines. For example, the outline definition in Fig. 3-23 can be resized through a scaling transformation, made
into italic through a shearing transformation, and turned around with respect to a reference point through a
rotation transformation. But it does take more time to process the outline fonts, because they must be scan
converted into the frame buffer.

Antialiasing
Antialiasing is a technique used in computer graphics to remove the aliasing effect. The aliasing effect occurs
when rasterized images have jagged edges, sometimes called "jaggies". The problem of jagged edges technically
occurs due to distortion of the image when scan conversion is done with sampling at a low frequency, which is
also known as under-sampling.
Under-sampling is an important factor in anti-aliasing. It results in a loss of information about the picture.
Under-sampling occurs when sampling is done at a frequency lower than the Nyquist Sampling Frequency. To
avoid this loss, we need to have our sampling frequency at least twice that of the highest frequency occurring
in the object.
There are several techniques for anti-aliasing, such as supersampling, area-sampling, filtering techniques, and
pixel phasing.
[Antialiasing refers to a technique used in computer graphics to reduce the appearance of jagged edges in images
or text displayed on a screen.]
40

Supersampling
Supersampling is a technique used in computer graphics to reduce the appearance of jagged edges in images or
text displayed on a screen. It works by rendering the image at a higher resolution than the target display
resolution and then downsampling it to the desired output resolution.
Steps in Supersampling to Reduce Jagged Effects:
1. Higher Resolution Rendering: The image is initially rendered at a higher resolution than the target
display resolution, such as at 2x or 4x the intended output resolution.
2. Sampling Multiple Points: At this higher resolution, multiple samples are taken within each pixel to
calculate the color value. More samples per pixel increase the accuracy of color representation and
contribute to smoother edges.
3. Averaging Colors: The colors obtained from the multiple samples within a pixel are averaged to
determine the final color for that pixel. Averaging these color values helps reduce the impact of
individual samples, leading to a more accurate and smoother final color for the pixel.
4. Downsampling: Finally, the image is resized or downsampled to the desired display resolution. The
averaged color values obtained from the higher-resolution rendering are used to generate the final image
at the intended output resolution.
This method is also known as post filtration as this procedure is done after generating the rasterized image.
However, super sampling is computationally expensive because it requires much greater video card memory
and memory bandwidth, since the amount of buffer used is several times larger. A way around this problem is
to use a technique known as adaptive super sampling, where only pixels at the edges of objects are super
sampled.

Halftoning
Halftoning is a technique used to simulate gray levels by creating patterns of black dots of varying size. It's
commonly employed in printing or displaying images on devices that can only produce binary output, such as
printers or screens. It works by converting continuous-tone images into binary form (black and white) output
by distributing dots or pixels in specific patterns. These patterns, known as dither matrices, vary dot sizes,
densities, and spatial arrangements to create the illusion of intermediate shades. By adjusting the size, spacing,
and density of dots, halftoning reproduces different levels of intensity. When viewed at a far enough distance,
the human eye blends these dots, creating the impression of continuous tones or colors.
Halftoning enhances the image quality by approximating continuous tones, enabling the representation of
complex images, despite the limitations of binary-output devices. Various halftoning methods like error
diffusion and ordered dithering achieve this effect using different dot-placement strategies.
41

Chapter 4: Transformation
Transformation refers to the process of changing the position, orientation, size, or shape of objects within a
virtual space or on a 2D or 3D canvas. Transformations are fundamental to the field of computer graphics as
they allow for the creation of complex images by altering the characteristics of graphical elements.
There are two complementary points of view for describing object transformation./There are two types of
Transformation:
1. Geometric Transformation
2. Coordinate Transformation
Differences between geometric and coordinate transformation:
Geometric Transformation Coordinate Transformation
Geometric transformations are used to modify the Coordinate transformations are focused on changing
shape, size, orientation, and position of objects while the coordinate system or frame of reference in which
preserving their intrinsic properties. objects are described or rendered.
Object itself transformed. Coordinate transformed.
Examples of geometric transformations include Examples of coordinate transformations include
rotating an object, resizing it, or skewing it. converting between different coordinate systems, or
changing the origin and scale of a coordinate system.

2D Geometric Transformations
The basic geometric transformations are translation, rotation, and scaling. Other transformations that are often
applied to objects include reflection and shear.
Translation
Translation refers to the process of moving an object or shape from one position to another in a coordinate
system, while maintaining its size, orientation, and shape. We translate a 2D point by adding translation
distances, 𝑡𝑥 and 𝑡𝑦 to the original coordinate position (𝑥, 𝑦) to move the point to a new position (𝑥 ′ , 𝑦 ′ ) as
𝑥 ′ = 𝑥 + 𝑡𝑥
𝑦 ′ = 𝑦 + 𝑡𝑦
The translation distance pair (𝑡𝑥 , 𝑡𝑦 ) is called a translation vector or shift vector.
42

Figure 4-1 Translating a point from position 𝑃 to position 𝑃′ with translation vector 𝑇
In matrix form, the above translation equations may be represented as-
𝑥′ 𝑥 𝑡𝑥
[ ′ ] = [𝑦] + [𝑡 ]
𝑦 𝑦

We can write it as-


𝑃′ = 𝑃 + 𝑇
For homogeneous coordinates, the above translation matrix may be represented by a 3 × 3 matrix as-
𝑥′ 1 0 𝑡𝑥 𝑥
[𝑦 ′ ] = [0 1 𝑡𝑦 ] ⋅ [𝑦]
1 0 0 1 1
This translation matrix can be written in the abbreviated form as
𝑃′ = 𝑇(𝑡𝑥 , 𝑡𝑦 ) . 𝑃
where 𝑇(𝑡𝑥 , 𝑡𝑦 ) is the 3 by 3 translation matrix.
The transformation matrix for 2D translation is
1 0 𝑡𝑥
[0 1 𝑡𝑦 ]
0 0 1

Rotation
Rotating objects is a common operation in computer graphics. It is a process of changing the angle of an object.
For rotation, we have to specify the angle of rotation and the position of the rotation point (or pivot point) about
which the object is to be rotated. Rotation can be clockwise or anticlockwise. Positive values for the rotation
angle define anticlockwise rotations about the pivot point and negative values rotate objects in the clockwise
direction. This transformation can also be described as a rotation about a rotation axis that is perpendicular to
the 𝑥𝑦 plane and passes through the pivot point.
Note: Default rotation center is origin (0, 0).
Rotation about the origin
We first determine the transformation equations for rotation of a point position 𝑃 when the pivot point is at the
coordinate origin. The angular and coordinate relationships of the original and transformed point positions are
shown in Fig. 4-2. In this figure, 𝑟 is the constant distance of the point from the origin, angle 𝜙 is the original
angular position of the point from the horizontal, and 𝜃 is the rotation angle. Using standard trigonometric
identities, we can express the transformed coordinates in terms of angles 𝜃 and 𝜙 as
𝑥 ′ = 𝑟 cos(𝜙 + 𝜃) = 𝑟 cos 𝜙 cos 𝜃 − 𝑟 sin 𝜙 sin 𝜃 ………… (1)
𝑦 ′ = 𝑟 sin(𝜙 + 𝜃) = 𝑟 cos 𝜙 sin 𝜃 + 𝑟 sin 𝜙 cos 𝜃 ………… (2)
43

The original coordinates of the point in polar coordinates are


𝑥 = 𝑟 cos 𝜙 ………… (3)
𝑦 = 𝑟 sin 𝜙 ………… (4)
Substituting equation 3 & 4 into 1 & 2 respectively, we obtain the transformation equations for rotating a point
at position (𝑥, 𝑦) through an angle 𝜃 about the origin:
𝑥 ′ = 𝑥 cos 𝜃 − 𝑦 sin 𝜃 ………… (5)
𝑦 ′ = 𝑥 sin 𝜃 + 𝑦 cos 𝜃 ………… (6)

Figure 4-2 Rotation of a point from position (𝑥, 𝑦) to position (𝑥 ′ , y') through an angle 𝜃 about the origin
We can write the rotation equations in the matrix form as
𝑥′ cos 𝜃 − sin 𝜃 𝑥
[ ′] = [ ] ⋅ [𝑦]
𝑦 sin 𝜃 cos 𝜃
For homogeneous coordinates, the above rotation matrix may be represented by a 3 × 3 matrix as-
𝑥′ cos 𝜃 −sin 𝜃 0 𝑥

[𝑦 ] = [ sin 𝜃 cos 𝜃 0] ⋅ [𝑦]
1 0 0 1 1
or as
𝑃′ = 𝑅(𝜃) ⋅ 𝑃

The transformation matrix for 2D rotation is


cos 𝜃 −sin 𝜃 0
[ sin 𝜃 cos 𝜃 0]
0 0 1

Rotation about an arbitrary point / General Pivot-Point Rotation


Rotation of a point about an arbitrary pivot position is illustrated in Fig. 4-3. Using the trigonometric
relationships in this figure, we can generalize Eqs. 5 & 6 to obtain the transformation equations for rotation of
a point about any specified rotation position (𝑥𝑟 , 𝑦𝑟 ):
𝑥 ′ = 𝑥𝑟 + (𝑥 − 𝑥𝑟 ) cos 𝜃 − (𝑦 − 𝑦𝑟 ) sin 𝜃
𝑦 ′ = 𝑦𝑟 + (𝑥 − 𝑥𝑟 ) sin 𝜃 + (𝑦 − 𝑦𝑟 ) cos 𝜃
We can rewrite these scaling transformations to separate the multiplicative and additive terms:
𝑥 ′ = 𝑥 cos 𝜃 − 𝑦 sin 𝜃 + 𝑥𝑟 (1 − cos 𝜃) + 𝑦𝑟 sin 𝜃
𝑦 ′ = 𝑥 sin 𝜃 + 𝑦 cos 𝜃 + 𝑦𝑟 (1 − cos 𝜃) − 𝑥𝑟 sin 𝜃
44

For homogeneous coordinates, these rotating equations can be represented by a 3 × 3 matrix as-
𝑥′ cos 𝜃 −sin 𝜃 𝑥𝑟 (1 − cos 𝜃) + 𝑦𝑟 sin 𝜃 𝑥

[𝑦 ] = [ sin 𝜃 𝑦
cos 𝜃 𝑦𝑟 (1 − cos 𝜃) − 𝑥𝑟 sin 𝜃 ] ⋅ [ ]
1 0 0 1 1

Figure 4-3 Rotating a point from position (𝑥, 𝑦) to position (𝑥 ′ , y') through an angle 𝜃 about rotation point (𝑥𝑟 , 𝑦𝑟 ).

We can also find the above transformation matrix as follows:


1. Translate the object so that the pivot-point position is moved to the coordinate origin.
2. Rotate the object about the coordinate origin.
3. Translate the object so that the pivot point is returned to its original position.
𝑅(𝑥𝑟 , 𝑦𝑟 , 𝜃) = 𝑇(𝑥𝑟 , 𝑦𝑟 ) ⋅ 𝑅(𝜃) ⋅ 𝑇(−𝑥𝑟 , −𝑦𝑟 )
1 0 𝑥𝑟 cos 𝜃 −sin 𝜃 0 1 0 −𝑥𝑟
= [0 1 𝑦𝑟 ] ⋅ [ sin 𝜃 cos 𝜃 0] ⋅ [0 1 −𝑦𝑟 ]
0 0 1 0 0 1 0 0 1
cos 𝜃 −sin 𝜃 𝑥𝑟 (1 − cos 𝜃) + 𝑦𝑟 sin 𝜃
= [ sin 𝜃 cos 𝜃 𝑦𝑟 (1 − cos 𝜃) − 𝑥𝑟 sin 𝜃 ]
0 0 1
Scaling
A scaling transformation alters the size of an object. Scaling factor determines whether the object size is to be
increased or reduced. If scaling factor > 1, then the object size is increased. If scaling factor < 1, then the object
size is reduced. Scaling factor 𝑠𝑥 , scales objects in the 𝑥 direction, while 𝑠𝑦 scales in the 𝑦 direction. A uniform
scaling is a special case of scaling where the scale factor is the same in all directions.

Figure 4-4 Square Scaling


Scaling can be achieved by multiplying the original coordinates of the object with the scaling factor to get the
desired result. Let us assume that the original coordinates of the point are (𝑥, 𝑦), the scaling factors are (𝑠𝑥 , 𝑠𝑦 ),
45

and the coordinates of the point after scaling are (𝑥 ′ , 𝑦 ′ ). Then, this scaling is achieved by using the following
scaling equations-
𝑥 ′ = 𝑥 ⋅ 𝑠𝑥
𝑦 ′ = 𝑦 ⋅ 𝑠𝑦
These transformation equations can also be represented in matrix form as:
𝑥′ 𝑠𝑥 0 𝑥
[ ′] = [ 0 𝑠𝑦 ] ⋅ [𝑦]
𝑦
or
𝑃′ = 𝑆 ⋅ 𝑃
whew 𝑆 is the 2 by 2 scaling matrix.
For homogeneous coordinates, the above scaling matrix can be represented by a 3 × 3 matrix as-
𝑥′ 𝑠𝑥 0 0 𝑥

[𝑦 ] = [ 0 𝑠𝑦 𝑦
0] ⋅ [ ]
1 0 0 1 1
or as
𝑃′ = 𝑆(𝑠𝑥 , 𝑠𝑦 ) ⋅ 𝑃
where 𝑆(𝑠𝑥 , 𝑠𝑦 ) is the 3 by 3 scaling matrix.

The transformation matrix for 2D scaling is


𝑠𝑥 0 0
[ 0 𝑠𝑦 0]
0 0 1

General Fixed-Point Scaling


We can control the location of a scaled object by choosing a position, called the fixed point, that is to remain
unchanged after the scaling transformation. Coordinates for the fixed point (𝑥𝑓 , 𝑦𝑓 ) can be chosen as one of the
vertices, the object centroid, or any other position (Fig. 4-5). A polygon is then scaled relative to the fixed point
by scaling the distance from each vertex to the fixed point. For a vertex with coordinates (𝑥, 𝑦), the scaled
coordinates (𝑥 ′ , 𝑦 ′ ) are calculated as
𝑥 ′ = 𝑥𝑓 + (𝑥 − 𝑥𝑓 )𝑠𝑥
𝑦 ′ = 𝑦𝑓 + (𝑦 − 𝑦𝑓 )𝑠𝑦
We can rewrite these scaling transformations to separate the multiplicative and additive terms:
𝑥 ′ = 𝑥 ⋅ 𝑠𝑥 + 𝑥𝑓 (1 − 𝑠𝑥 )
𝑦 ′ = 𝑦 ⋅ 𝑠𝑦 + 𝑦𝑓 (1 − 𝑠𝑦 )
where the additive terms 𝑥𝑓 (1 − 𝑠𝑥 ) and 𝑦𝑓 (1 − 𝑠𝑦 ) are constant for all points in the object.
For homogeneous coordinates, the above scaling equations can be represented by a 3 × 3 matrix as-
𝑥′ 𝑠𝑥 0 𝑥𝑓 (1 − 𝑠𝑥 ) 𝑥

[𝑦 ] = [ 0 𝑦
𝑠𝑦 𝑦𝑓 (1 − 𝑠𝑦 )] ⋅ [ ]
1 0 0 1 1
46

Figure 4-5 Scaling relative to a chosen fixed point (𝑥𝑓 , 𝑦𝑓 )


We can also find the above transformation matrix as follows:
4. Translate the object to so that the fixed point coincides with the coordinate origin.
5. Scale the object with respect to the coordinate origin.
6. Use the inverse of the translation in step-1 to return the object to its original position.
𝑆(𝑥𝑓 , 𝑦𝑓 , 𝑠𝑥 , 𝑠𝑦 ) = 𝑇(𝑥𝑓 , 𝑦𝑓 ) ⋅ 𝑆(𝑠𝑥 , 𝑠𝑦 ) ⋅ 𝑇(−𝑥𝑓 , −𝑦𝑓 )
1 0 𝑥𝑓 𝑠𝑥 0 0 1 0 −𝑥𝑓
= [0 1 𝑦𝑓 ] ⋅ [ 0 𝑠𝑦 0] ⋅ [0 1 −𝑦𝑓 ]
0 0 1 0 0 1 0 0 1
𝑠𝑥 0 𝑥𝑓 (1 − 𝑠𝑥 )
= [ 0 𝑠𝑦 𝑦𝑓 (1 − 𝑠𝑦 )]
0 0 1
Reflection
A reflection is a transformation that produces a mirror image of an object. The mirror image for a 2D reflection
is generated relative to an axis of reflection by rotating the object 180 ° about the reflection axis. In reflection
transformation, the size of the object does not change.
Reflection about x-axis
When a point is reflected across the x-axis, the x-coordinates remain the same, but the y-coordinates are
transformed into their opposite signs. Hence, this reflection is achieved by using the following reflection
equations-
𝑥′ = 𝑥
𝑦 ′ = −𝑦
Therefore, the reflection of the point (𝑥, 𝑦) across X-axis is (𝑥, −𝑦).

Figure 4-6 Reflection of an object about the 𝑥 axis


47

In matrix form, the above reflection equations may be represented as-


𝑥′ 1 0 𝑥
[ ′] = [ ] ⋅ [𝑦]
𝑦 0 −1
For homogeneous coordinates, the above reflection matrix may be represented as-
𝑥′ 1 0 0 𝑥

[𝑦 ] = [0 −1 0] ⋅ [𝑦]
1 0 0 1 1

Reflection about the line y = 0, the x axis, is accomplished with the transformation matrix
1 0 0
[0 −1 0]
0 0 1

Reflection about y-axis


When a point is reflected across the Y-axis, the Y-coordinates remain the same. But the X-coordinates is
transformed into its opposite signs. Therefore, the reflection of the point (𝑥, 𝑦) across Y-axis is (−𝑥, 𝑦).
The following figure shows the reflection about the y-axis:

Figure 4-7 Reflection of an object about the 𝑦 axis


The matrix for this transformation is
−1 0 0
[0 1 0]
0 0 1
Reflection about an axis perpendicular to 𝒙𝒚 plane and passing through origin
We flip both the x and y coordinates of a point by reflecting relative to an axis that is perpendicular to the 𝑥𝑦
plane and that passes through the coordinate origin. This transformation, referred to as a reflection relative to
the coordinate origin, has the matrix representation:
−1 0 0
[ 0 −1 0]
0 0 1
48

The following figure shows this reflection:

Figure 4-8
Reflection at origin (0, 0)
When a point is reflected about the origin, both the x-coordinate and the y-coordinate are negated (their signs
are changed). In other words, turn the plane 180 degrees around the origin to move 𝑃 onto 𝑃′ . If 𝑃(𝑥, 𝑦) is the
point on 𝑥𝑦 plane then 𝑃′ (𝑥 ′ , 𝑦 ′ ) is the reflection about origin given as
𝑥 ′ = −𝑥
𝑦 ′ = −𝑦
Therefore, the reflection of the point (𝑥, 𝑦) about the origin is (−𝑥, −𝑦).

Figure 4-9 reflection about the origin


In matrix form, the above reflection equations may be represented as-
𝑥′ −1 0 0 𝑥

[𝑦 ] = [ 0 −1 0] ⋅ [𝑦]
1 0 0 1 1
49

Reflection about line 𝒚 = 𝒙


When a point is reflected across the line 𝑦 = 𝑥, the x-coordinates and y-coordinates change their place.
Therefore, the reflection of the point (𝑥, 𝑦) across the line 𝑦 = 𝑥 is (𝑦, 𝑥).

Figure 4-10 Reflection of an object with respect to the line 𝑦 = 𝑥


The matrix for this transformation is
0 1 0
[1 0 0]
0 0 1
We can derive this matrix by concatenating a sequence of rotation and coordinate-axis reflection matrices. One
possible sequence is shown in Fig. 4-11. Here, we first perform a clockwise rotation through a 45° angle, which
rotates the line 𝑦 = 𝑥 onto the 𝑥 axis. Next, we perform a reflection with respect to the 𝑥 axis. The final step is
to rotate the line 𝑦 = 𝑥 back to its original position with a counterclockwise rotation through 45°. An equivalent
sequence of transformations is first to reflect the object about the 𝑥 axis, and then to rotate counterclockwise
90°.

(a) clockwise rotation of 45° (b) reflection about the x axis (c) counterclockwise rotation by 45°.
Figure 4-11 Sequence of transformations to produce reflection about the line 𝑦 = 𝑥
Reflection about line 𝒚 = −𝒙
When a point is reflected across the line 𝑦 = −𝑥, the x-coordinates and y-coordinates change their place and
are negated. Therefore, the reflection of the point (𝑥, 𝑦) across the line 𝑦 =– 𝑥 is (−𝑦, −𝑥).
To obtain a transformation matrix for reflection about the diagonal 𝑦 = −𝑥, we could concatenate matrices for
the transformation sequence: (1) clockwise rotation by 45°, (2) reflection about the y axis, and (3)
counterclockwise rotation by 45°. The resulting transformation matrix is
0 −1 0
[−1 0 0]
0 0 1
50

Figure 4-12 shows the original and final positions for an object transformed with this reflection matrix.

Figure 4-12 Reflection with respect to the line 𝑦 = −𝑥


Reflection about line 𝒚 = 𝒎𝒙 + 𝒄
Reflections about any line 𝑦 = 𝑚𝑥 + 𝑐 in the 𝑥𝑦 plane can be accomplished with a combination of
translate-rotate-reflect transformations. In general, we first translate the line so that it passes through the origin.
Then we can rotate the line onto one of the coordinate axes and reflect about that axis. Finally, we restore the
line to its original position with the inverse rotation and translation transformations.
Shear
Shear transformation refers to the process of changing the shape and size of an object in a coordinate system. It
is an ideal technique to change the shape of an existing object in a two dimensional plane. In a two dimensional
plane, the object size can be changed along x-direction or y-direction or both directions.
X-Shear
In x-shear, the 𝑦 co-ordinates remain the same but the 𝑥 co-ordinates changes.

Figure 4-13 X-Share


Let us assume that the original coordinates of the point are (𝑥, 𝑦), the shearing parameter towards x-direction is
𝑠ℎ𝑥 , and the coordinates of the point after shearing are (𝑥 ′ , 𝑦 ′ ). Then, this shearing is achieved by using the
following equations-
𝑥 ′ = 𝑥 + 𝑠ℎ𝑥 ⋅ 𝑦
𝑦′ = 𝑦
These transformation equations can also be written in matrix form as:
𝑥′ 1 𝑠ℎ𝑥 𝑥
[ ′] = [ ] ⋅ [𝑦]
𝑦 0 1
For homogeneous coordinates, the above x-shearing matrix can be represented by a 3 × 3 matrix as-
𝑥′ 1 𝑠ℎ𝑥 0 𝑥

[𝑦 ] = [0 1 0] ⋅ [𝑦]
1 0 0 1 1
51

Y-Shear
In y shear, the x co-ordinates remain the same but the y co-ordinates changes.

Figure 4-14 Y-Share


The y-shear is achieved by using the following equations-
𝑥′ = 𝑥
𝑦 ′ = 𝑦 + 𝑠ℎ𝑦 ⋅ 𝑥
These transformation equations can also be written in matrix form as:
𝑥′ 1 0 𝑥
[ ′ ] = [𝑠ℎ 1] ⋅ [𝑦]
𝑦 𝑦

For homogeneous coordinates, the above y-shearing matrix can be represented by a 3 × 3 matrix as-
𝑥′ 1 0 0 𝑥
′ 𝑠ℎ
[𝑦 ] = [ 𝑦 1 0] ⋅ [𝑦]
1 0 0 1 1
XY-Shear
In xy-shear, both the x and y co-ordinates changes.

Figure 4-15 XY-Share


The xy-shear is achieved by using the following equations-
𝑥 ′ = 𝑥 + 𝑠ℎ𝑥 ⋅ 𝑦
𝑦 ′ = 𝑦 + 𝑠ℎ𝑦 ⋅ 𝑥
These transformation equations can also be written in matrix form as:
𝑥′ 1 𝑠ℎ𝑥 𝑥
[ ′ ] = [𝑠ℎ 1 ] ⋅ [𝑦]
𝑦 𝑦

For homogeneous coordinates, the above xy-shearing matrix can be represented by a 3 × 3 matrix as-
𝑥′ 1 𝑠ℎ𝑥 0 𝑥

[𝑦 ] = [𝑠ℎ𝑦 1 0] ⋅ [𝑦]
1 0 0 1 1
52

Composite Transformations
As the name suggests itself Composition, here we combine two or more transformations into one single
transformation that is equivalent to the transformations that are performed one after one over a 2-D object.
Translations
If two successive translation vectors (𝑡𝑥1,𝑡𝑦1 ) and (𝑡𝑥2 ,𝑡𝑦2 ) are applied to a coordinate position 𝑃, the final
transformed location 𝑃′ is calculated as
𝑃′ = 𝑇(𝑡𝑥2 , 𝑡𝑦2 ) ⋅ {𝑇(𝑡𝑥1 , 𝑡𝑦1 ) ⋅ 𝑃}
= {𝑇(𝑡𝑥2 , 𝑡𝑦2 ). 𝑇(𝑡𝑥1 , 𝑡𝑦1 )} ⋅ 𝑃
where 𝑃 and 𝑃′ are represented as homogeneous-coordinate column vectors. We can verify this result by
calculating the matrix product for the two associative groupings. Also, the composite transformation matrix for
this sequence of translations is
1 0 𝑡𝑥2 1 0 𝑡𝑥1 1 0 𝑡𝑥1 + 𝑡𝑥2
[0 1 𝑡𝑦2 ] ⋅ [0 1 𝑡𝑦1 ] = [0 1 𝑡𝑦1 + 𝑡𝑦2 ]
0 0 1 0 0 1 0 0 1
or
𝑇(𝑡𝑥2 , 𝑡𝑦2 ). 𝑇(𝑡𝑥1 , 𝑡𝑦1 ) = 𝑇(𝑡𝑥1 + 𝑡𝑥2 , 𝑡𝑦1 + 𝑡𝑦2 )
which demonstrates that two successive translations are additive.
Rotations
Two successive rotations applied to point 𝑃 produce the transformed position
𝑃′ = 𝑅(𝜃2 ) ⋅ {𝑅(𝜃1 ) ⋅ 𝑃}
= {𝑅(𝜃2 ) ⋅ 𝑅(𝜃1 )} ⋅ 𝑃
By multiplying the two rotation matrices, we can verify that two successive rotations are additive:
𝑅(𝜃2 ) ⋅ 𝑅(𝜃1 ) = 𝑅(𝜃1 + 𝜃2 )
so that the final rotated coordinates can be calculated with the composite rotation matrix as
𝑃′ = 𝑅(𝜃1 + 𝜃2 ) ⋅ 𝑃
Scaling
Concatenating transformation matrices for two successive scaling operations produces the following composite
scaling matrix:
𝑠𝑥2 0 0 𝑠𝑥1 0 0 𝑠𝑥1 ⋅ 𝑠𝑥2 0 0
[0 𝑠𝑦2 0] ⋅ [ 0 𝑠𝑦1 0] = [ 0 𝑠𝑦1 ⋅ 𝑠𝑦2 0]
0 0 1 0 0 1 0 0 1
or
𝑆(𝑠𝑥2 , 𝑠𝑦2 ) ⋅ 𝑆(𝑠𝑥1 , 𝑠𝑦1 ) = 𝑆(𝑠𝑥1 ⋅ 𝑠𝑥2 , 𝑠𝑦1 ⋅ 𝑠𝑦2 )
The resulting matrix in this case indicates that successive scaling operations are multiplicative. That is, if we
were to triple the size of an object twice in succession, the final size would be nine times that of the

Coordinate Transformations
Coordinate transformation is simply reverse to geometric transformation.
53

Q. Write the three transformation matrices for coordinate transformation.


Translation:
1 0 −𝑥0
)
𝑇(−𝑥0 , −𝑦0 = [0 1 −𝑦0 ]
0 0 1
Rotation:
cos 𝜃 sin 𝜃 0
𝑅(−𝜃) = [− sin 𝜃 cos 𝜃 0]
0 0 1
Scaling:
1
𝑠𝑥
0 0
𝑆(𝑠𝑥 , 𝑠𝑦 ) = 0 1
0
𝑠𝑦
[0 0 1]
Q. Why do we use 3 × 3 matrix in 2D transformation?
In 2D transformation, we use a 3 × 3 matrix to represent the transformation. The extra row in the matrix is used
to represent the homogeneous coordinate of the point, allowing representation of translation alongside scaling,
rotation, and shearing. It simplifies composite transformations by merging multiple transformation matrices into
a single matrix. Moreover, it facilitates computational operations, offering an efficient and unified approach to
manipulate various transformations within the 2D graphics space.

3D Geometric Transformations
Methods for geometric transformations in three dimensions are extended from two-dimensional methods by
including considerations for the z-coordinate. A three-dimensional position, expressed in homogeneous
coordinates, is represented as a four-element column vector. Thus, each geometric transformation operator is
now 4 by 4 matrix.
3D Translation
It is the movement of an object from one position to another position. Translation is done using translation
vectors. There are three vectors in 3D instead of two. These vectors are in x, y, and z directions. Translation in
the x-direction is represented using t x . The translation is y-direction is represented using t y . The translation in
the z- direction is represented using t z .

If P is a point having co-ordinates (x, y, z) is translated, then after translation its coordinates can be calculated
by using the transformation
𝑥 ′ = 𝑥 + tx
𝑇𝑝 : {𝑦 ′ = 𝑦 + t y or, 𝑇𝑝 = (𝑥 + t x , 𝑦 + t y , 𝑧 + t z )
𝑧 ′ = 𝑧 + tz
54

In order to represent this transformation as a matrix transformation, we need to use homogeneous coordinates.
The required homogeneous matrix transformation can then be expressed as
𝑥′ 1 0 0 tx 𝑥
𝑦′ 0 1 0 ty 𝑦
[ ′] = [ ]⋅[ ]
𝑧 0 0 1 tz 𝑧
1 0 0 0 1 1
Matrix for inverse translation:
𝑥′ 1 0 0 −t x 𝑥
𝑦′ 0 1 0 −t y 𝑦
[ ′] = [ ]⋅[ ]
𝑧 0 0 1 −t z 𝑧
1 0 0 0 1 1
Q. Write the transformation matrix for 3D translation.
The transformation matrix for 3D translation is
1 0 0 tx
0 1 0 ty
[ ]
0 0 1 tz
0 0 0 1
Here, t x , t y , and t z are the distances by which the object is translated in the x, y, and z directions, respectively

3D Scaling

The scaling is achieved by using the following scaling equations:


𝑥 ′ = sx ⋅ 𝑥
𝑆𝑝 : {𝑦 ′ = sy ⋅ 𝑦 or, 𝑆𝑝 = (sx ⋅ 𝑥, sy ⋅ 𝑦, sz ⋅ 𝑧)
𝑧 ′ = sz ⋅ 𝑧
In Matrix form, the above scaling equations may be represented as-
𝑥′ sx 0 0 0 𝑥
′ 0 sy 0 0 𝑦
𝑦
[ ′] = [ ]⋅[ ]
𝑧 0 0 sz 0 𝑧
1 0 0 0 1 1
Matrix for inverse scaling:
𝑥′ 1/sx 0 0 0 𝑥
𝑦′ 0 1/sy 0 0 𝑦
[ ′] = [ ]⋅[ ]
𝑧 0 0 1/sz 0 𝑧
1 0 0 0 1 1
55

Q. Write the transformation matrix for 3D scaling.


The matrix representation of scaling transformation is given below:
sx 0 0 0
0 sy 0 0
[ ]
0 0 sz 0
0 0 0 1
where, sx , sy , and sz are the scaling factors in the x, y and z directions, respectively.

3D Rotation
Rotation in three dimensions is considerably more complex than rotation in two dimensions. In two dimensions,
a rotation is prescribed by an angle of rotation 𝜃 and a center of rotation P. Three-dimensional rotations require
the prescription of an angle of rotation and an axis of rotation. The canonical rotations are defined when one of
the positive x, y, or z coordinate axes is chosen as the axis of rotation. Then the construction of the rotation
transformation proceeds just like that of a rotation in two dimensions about the origin (see Figure).

In 3 dimensions, there are 3 possible types of rotation:


1. Rotation about the X-axis
2. Rotation about the Y-axis
3. Rotation about the Z-axis
Rotation about the X-axis
In this kind of rotation, the object is rotated parallel to the x-axis, where the x coordinate remains unchanged
and the rest of the two coordinates y and z only change. Consider a point with initial coordinate P(x, y, z) in 3D
space is made to rotate parallel to the x-axis. The coordinate position would change to P'(x, y, z).
Rotation about the X-axis is achieved by using the following equations-
𝑥′ = 𝑥
𝑦 ′ = 𝑦 cos 𝜃 − 𝑧 sin 𝜃
𝑧 ′ = 𝑦 sin 𝜃 + 𝑧 cos 𝜃
In Matrix form, the above rotation equations may be represented as-
𝑥′ 1 0 0 0 𝑥
′ 𝑦
𝑦 0 cos 𝜃 −sin 𝜃 0
[ ′] = [ ]⋅[ ]
𝑧 0 sin 𝜃 cos 𝜃 0 𝑧
1 0 0 0 1 1
56

Rotation about the Y-axis


In this kind of rotation, the object is rotated parallel to the y-axis, where the y coordinate remains unchanged
and the rest of the two coordinates x and z only change.

Rotation about the Y-axis is achieved by using the following equations-


𝑥 ′ = 𝑧 sin 𝜃 + 𝑥 cos 𝜃
𝑦′ = 𝑦
𝑧 ′ = 𝑧 cos 𝜃 − 𝑥 sin 𝜃
In Matrix form, the above rotation equations may be represented as-
𝑥′ cos 𝜃 0 sin 𝜃 0 𝑥
𝑦′ 0 1 0 0 𝑦
[ ′] = [ ]⋅[ ]
𝑧 −sin 𝜃 0 cos 𝜃 0 𝑧
1 0 0 0 1 1
Rotation about the Z-axis
In this kind of rotation, the object is rotated parallel to the z-axis, where the z coordinate remains unchanged
and the rest of the two coordinates x and y only change.

This rotation is achieved by using the following rotation equations-


𝑥 ′ = 𝑥 cos 𝜃 − 𝑦 sin 𝜃
𝑦 ′ = 𝑥 sin 𝜃 + 𝑦 cos 𝜃
𝑧′ = 𝑧
In Matrix form, the above rotation equations may be represented as-
𝑥′ cos 𝜃 −sin 𝜃 0 0 𝑥
𝑦′ sin 𝜃 cos 𝜃 0 0 𝑦
[ ′] = [ ]⋅[ ]
𝑧 0 0 1 0 𝑧
1 0 0 0 1 1
57

Q. Write the matrices for 3D rotation.


3D Rotation Matrices
Rotation about X-axis:
1 0 0 0
0 cos 𝜃 −sin 𝜃 0
[ ]
0 sin 𝜃 cos 𝜃 0
0 0 0 1
Rotation about Y-axis:
cos 𝜃 0 sin 𝜃 0
0 1 0 0
[ ]
−sin 𝜃 0 cos 𝜃 0
0 0 0 1
Rotation about Z-axis:
cos 𝜃 −sin 𝜃 0 0
sin 𝜃 cos 𝜃 0 0
[ ]
0 0 1 0
0 0 0 1
3D Shear
In a three dimensional plane, the object size can be changed along X-direction, Y-direction as well as
Z-direction. So, there are three versions of shearing:
1. Shearing in X direction
2. Shearing in Y direction
3. Shearing in Z direction
Shearing in X-axis
Here, the coordinate of X remains unchanged while the coordinate of Y and Z is changed.
Shearing in X-axis is achieved by using the following shearing equations-
𝑥′ = 𝑥
𝑦 ′ = 𝑦 + 𝑠ℎ𝑦 ⋅ 𝑥
𝑧 ′ = 𝑧 + 𝑠ℎ𝑧 ⋅ 𝑥
In Matrix form, the above shearing equations may be represented as-
𝑥′ 1 0 0 0 𝑥
′ 𝑠ℎ 1 0 0 𝑦
𝑦
[ ′] = [ 𝑦 ]⋅[ ]
𝑧 𝑠ℎ𝑧 0 1 0 𝑧
1 0 0 0 1 1
Shearing in Y-axis
Here, the coordinate of Y remains unchanged while the coordinate of X and Z are changed.
Shearing in Y-axis is achieved by using the following shearing equations-
𝑥 ′ = 𝑥 + 𝑠ℎ𝑥 ⋅ 𝑦
𝑦′ = 𝑦
𝑧 ′ = 𝑧 + 𝑠ℎ𝑧 ⋅ 𝑦
In Matrix form, the above shearing equations may be represented as-
𝑥′ 1 𝑠ℎ𝑥 0 0 𝑥
′ 𝑦
𝑦 0 1 0 0
[ ′] = [ ]⋅[ ]
𝑧 0 𝑠ℎ𝑧 1 0 𝑧
1 0 0 0 1 1
58

Shearing in Z-axis
Here, the coordinate of Z remains unchanged while the coordinate of X and Y are changed
Shearing in Z-axis is achieved by using the following shearing equations-
𝑥 ′ = 𝑥 + 𝑠ℎ𝑥 ⋅ 𝑧
𝑦 ′ = 𝑦 + 𝑠ℎ𝑦 ⋅ 𝑧
𝑧′ = 𝑧
In Matrix form, the above shearing equations may be represented as-
𝑥′ 1 0 𝑠ℎ𝑥 0 𝑥
′ 0 1 𝑠ℎ𝑦 0 𝑦
𝑦
[ ′] = [ ]⋅[ ]
𝑧 0 0 1 0 𝑧
1 0 0 0 1 1

Warning: The sheet may contain errors. Read the sheet at your own discretion.

"Honesty is the first chapter in the book of wisdom."


"Never put passion before principle. Even if you win, you lose."
𝐄𝐧𝐝

Md. Nazmul Hossain (18 – 19, CSE, IU)

You might also like