Computer Graphics
Computer Graphics
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)
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. 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
or
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.
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.
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
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
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.
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
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
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
or
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 𝑥 ≥ 𝑦.
𝑝 = 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 𝑥 ≥ 𝑦.
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.
𝑑𝑦
* 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:
𝑥 = 𝑥 + 𝑥𝑐
𝑦 = 𝑦 + 𝑦𝑐
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.
Figure 3-16 Odd number indicates inside the polygon and even number indicates outside the polygon
36
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.
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
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-
𝑥′ 𝑥 𝑡𝑥
[ ′ ] = [𝑦] + [𝑡 ]
𝑦 𝑦
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
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
𝑃′ = 𝑅(𝜃) ⋅ 𝑃
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 (𝑥𝑟 , 𝑦𝑟 ).
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.
Reflection about the line y = 0, the x axis, is accomplished with the transformation matrix
1 0 0
[0 −1 0]
0 0 1
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 (−𝑥, −𝑦).
(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.
Y-Shear
In y shear, the x co-ordinates remain the same but the y co-ordinates changes.
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.
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
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
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).
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.