0% found this document useful (0 votes)
66 views25 pages

Unit 1

This document provides an overview of computer graphics, detailing its definition, components, and types, including raster and vector graphics. It discusses the advantages of computer graphics in communication, data visualization, and animation, as well as its applications across various fields such as user interfaces, design, and education. Additionally, it covers display technologies and their respective components, emphasizing the evolution from CRT to modern display systems.

Uploaded by

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

Unit 1

This document provides an overview of computer graphics, detailing its definition, components, and types, including raster and vector graphics. It discusses the advantages of computer graphics in communication, data visualization, and animation, as well as its applications across various fields such as user interfaces, design, and education. Additionally, it covers display technologies and their respective components, emphasizing the evolution from CRT to modern display systems.

Uploaded by

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

**UNIT 1: Overview of Computer Graphics**

**What is Computer Graphics?**

Computer graphics is the art of drawing pictures, lines, charts, etc., using computers with the help of
programming. A computer graphics image is made up of a number of pixels. A pixel is the smallest
addressable graphical unit represented on the computer screen.

**Introduction**

A computer is an information processing machine. The user needs to communicate with the
computer, and computer graphics is one of the most effective and commonly used ways of
communication. It displays information in the form of graphical objects such as pictures, charts,
diagrams, and graphs. Graphical objects convey more information in less time and are easily
understandable, for example, statistical graphs shown in stock exchanges.

In computer graphics, pictures or graphics objects are presented as a collection of discrete pixels. We
can control the intensity and color of each pixel, which determines how the picture looks. A special
procedure determines which pixel will provide the best approximation to the desired picture or
graphics object. This process is known as **Rasterization**. The process of representing continuous
pictures or graphics objects as a collection of discrete pixels is called **Scan Conversion**.

Components of a Graphic System

a. Graphics Hardware

 Monitor: The display device where graphical output is shown. Common types include LCD,
LED, and OLED displays.

 Graphics Processing Unit (GPU): A specialized electronic circuit designed to accelerate the
creation and rendering of images, animations, and videos. It performs rapid mathematical
calculations, especially for rendering images from 3D models.

 Frame Buffer: A portion of memory used to store the pixel values of an image before it is
displayed on the screen. It holds color and intensity information for each pixel.

 Input Devices: Devices like a mouse, keyboard, graphic tablet, or joystick that allow users to
interact with graphical objects.

 Digital-to-Analog Converter (DAC): Converts digital data (generated by the computer) into
analog signals to drive the display screen.

b. Graphics Software
 Device Drivers: Software that allows the operating system and applications to communicate
with the graphics hardware.

 Graphics Libraries: Predefined functions or APIs (Application Programming Interfaces) used


to develop graphics applications (e.g., OpenGL, DirectX, and Vulkan).

 Rendering Software: Programs that generate images from 2D or 3D models, often used in
video games, simulations, or animations.

Types of Graphic systems

Raster Graphics

Raster graphics, also called bitmap graphics, is a type of digital image that uses tiny
rectangular pixels (picture elements) arranged in a grid to represent an image. This format
supports a wide range of colors and can depict subtle graduated tones, making it ideal for
continuous-tone images such as photographs, shaded drawings, and other detailed images.

Origins and Structure


Raster graphics have their origins in television technology, where images are constructed
similarly to how pictures are displayed on a TV screen. A raster graphic is made up of a
collection of tiny, uniformly sized pixels arranged in a two-dimensional grid, with each pixel
occupying a unique location in columns and rows.

Each pixel contains one or more bits of information, depending on the image's level of detail.
For instance:

 A black-and-white image contains only one bit per pixel (binary), meaning each pixel
represents either black or white.

 An image with shading and color typically contains 24 bits of information per pixel,
supporting 2²⁴ (over 16 million) possible color states per pixel. This is known as true color,
allowing for realistic color depiction.

Key Concepts:

 Color Depth: The number of bits stored in each pixel, which determines how many colors can
be represented.

 Resolution: The number of pixels in an image, usually expressed as the number of pixels in a
column multiplied by the number of pixels in a row (e.g., 800 × 600). Higher resolution allows
for more detailed images.

Detailed images often result in larger file sizes. However, file size can be managed through
data compression, which can be either:

 Lossy: Some data is discarded to reduce file size (e.g., JPEG, GIF).

 Lossless: No data is lost, maintaining full image quality (e.g., BMP, TIFF).

Applications and Formats


Raster graphics gained widespread use as the graphics capabilities of personal computers
improved in the 1990s. Prior to that, raster graphics were mostly limited to expensive
graphics workstations in the 1970s and 1980s.

Common applications of raster graphics include:

 Optical Scanners: Images scanned from physical media are often stored as raster images.

 Digital Cameras: Photos taken with digital cameras are stored as raster graphics.

 Internet Images: Most images seen online are raster-based.

Popular programs for working with raster images include Adobe Photoshop, which is widely
used for image editing.

File Formats
Popular raster file formats include:

 GIF (Graphics Interchange Format): A lossy format.

 JPEG (Joint Photographic Experts Group): Another lossy format commonly used for photos.

 BMP (Windows Bitmap): A lossless format.

 TIFF (Tagged Image File Format): A lossless format often used for high-quality image storage.

Vector Graphics

Vector graphics are a type of digital image that represents images using mathematical
formulas rather than pixels. Unlike raster graphics, which rely on a grid of tiny dots (pixels),
vector graphics use points, lines, curves, and shapes based on mathematical expressions to
create images. These elements are defined by vectors, which have both direction and
magnitude, making them ideal for images that require scalability.

Structure and Features


Each object in a vector image is defined by its properties, such as position, length, curve, and
color. These images are resolution-independent, meaning they can be scaled to any size
without losing quality. This makes vector graphics especially useful for logos, illustrations,
and designs that need to be resized frequently without distortion or pixelation.

Since vector graphics store instructions on how to recreate the image using mathematical
equations, they are typically more efficient in terms of file size compared to detailed raster
images. However, they are less suitable for representing detailed images such as
photographs, where continuous tones and shading are important.

Key Concepts:

 Scalability: Vector images can be scaled infinitely without loss of clarity, making them ideal
for designs that need to be resized, such as corporate logos or graphic designs.

 Efficiency: Vector files generally have smaller sizes than high-resolution raster files, since they
store instructions for drawing objects rather than a grid of pixels.

 Editability: Objects in vector graphics are independent, meaning each element can be edited
separately without affecting other parts of the image.
Common Uses
Vector graphics are widely used in applications like:

 Logo Design: Logos need to be resized for different uses, such as business cards, billboards,
or websites, making vector graphics the preferred format.

 Illustrations: Vector graphics are commonly used in graphic design for illustrations, cartoons,
and icons.

 Computer-Aided Design (CAD): Engineers and architects use vector-based software to create
technical drawings and 3D models because of the precision and scalability it offers.

File Formats
Popular vector graphics formats include:

 SVG (Scalable Vector Graphics): A widely used web-based vector format.

 AI (Adobe Illustrator): A proprietary format used in Adobe Illustrator for professional graphic
design.

 EPS (Encapsulated PostScript): A vector format often used for printing and publishing.

 PDF (Portable Document Format): Although primarily used for documents, PDFs can contain
vector graphics, making them suitable for scalable designs.

Applications and Programs


Vector graphics are used in many professional design tools, such as Adobe Illustrator,
CorelDRAW, and Inkscape, all of which allow for creating and editing vector-based images.

**Advantages of Computer Graphics**

- **Effective Communication**: Computer graphics is one of the most effective and commonly used
ways of communication with a computer.

- **Visualization of Data**: It provides tools for producing pictures of real-world as well as synthetic
objects, such as mathematical surfaces in 4D and data that have no inherent geometry (e.g., survey
results).

- **Animation**: It allows the creation of moving pictures, making animations possible. We can
control the animation by adjusting the speed, the portion of the picture in view, the amount of detail
shown, etc.

- **Motion Dynamics**: This tool allows the movement of objects or the observer as required (e.g.,
walk-throughs created by builders to show flat interiors and surroundings).

- **Update Dynamics**: We can change the shape, color, and other properties of objects in real
time.

- **Interactive Feedback**: With the recent development of digital signal processing and audio
synthesis chips, interactive graphics can now provide audio feedback along with graphical feedback.
**Applications of Computer Graphics**

1. **User Interface**: Visual objects we observe on screens that communicate with users are one of
the most useful applications of computer graphics.

2. **Plotting of Graphics**: In industries, businesses, governments, and educational organizations,


graphics such as bar charts, pie charts, and histograms are very useful for quick and effective
decision-making.

3. **Office Automation and Desktop Publishing**: Computer graphics are used for creating and
disseminating information. It is used for in-house creation and printing of documents that contain
text, tables, graphs, and other forms of drawn or scanned images.

4. **Computer-Aided Drafting and Design (CADD)**: Graphics are used to design components and
systems such as automobile bodies and building structures.

5. **Simulation and Animation**: Graphics are used in simulation to make mathematical models and
mechanical systems more realistic and easier to study.

6. **Art and Commerce**: There are many tools provided by graphics that allow users to create
attractive and animated pictures, often used in advertising.

7. **Process Control**: In automated systems, the process is graphically displayed on screens.

8. **Cartography**: Computer graphics are used to represent geographic maps, weather maps,
oceanographic charts, etc.

9. **Education and Training**: Graphics can be used to generate models of physical, financial, and
economic systems for educational purposes.

Display Devices

a. Cathode Ray Tube (CRT)

 Older technology where electron beams are used to illuminate phosphor-coated screens to
display images. CRTs are bulky but were widely used before modern flat panels.

b. Liquid Crystal Display (LCD)


 Thin, flat display technology that uses liquid crystals to modulate light and create images.
LCDs are more energy-efficient and lightweight than CRTs.

c. Light Emitting Diode (LED)

 A type of display that uses LEDs for backlighting in LCDs or as individual light sources in OLED
displays, offering better contrast and color accuracy.

d. OLED (Organic Light Emitting Diode)

 Advanced display technology where organic compounds emit light in response to an electric
current. OLEDs provide high contrast, faster refresh rates, and are thinner than LCDs.

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. The color you view on the screen is produced by a blend of red, blue and green
light.

Components of CRT:
 Main Components of CRT are:
 1. Electron Gun: Electron gun consisting of a series of elements, primarily a heating
filament (heater) and a cathode. The electron gun creates a source of electrons which
are focused into a narrow beam directed at the face of the CRT.

 2. Control Electrode: It is used to turn the electron beam on and off.
 3. Focusing system: It is used to create a clear picture by focusing the electrons into a
narrow beam.

 4. Deflection Yoke: It is used to control the direction of the electron beam. It creates an
electric or magnetic field which will bend the electron beam as it passes through the
area. In a conventional CRT, the yoke is linked to a sweep or scan generator. The
deflection yoke which is connected to the sweep generator creates a fluctuating electric
or magnetic potential.
 5. Phosphorus-coated screen: The inside front surface of every CRT is coated with
phosphors. Phosphors glow when a high-energy electron beam hits them.
Phosphorescence is the term used to characterize the light given off by a phosphor after
it has been exposed to an electron beam.
Direct View Storage Tubes:
DVST terminals also use the random scan approach to generate the image on the CRT
screen. The term "storage tube" refers to the ability of the screen to retain the image
which has been projected against it, thus avoiding the need to rewrite the image
constantly.

DIRECT VIEW STORAGE TUBE:

Direct View Storage Tube (DVST) resembles CRT as it uses electron gun to draw picture
and phosphor coated screen to display it. The phosphor used in this is of high
persistence. DVST does not use refresh buffer or frame buffer to store picture definition.
Picture definition is stored in inside CRT in form positive charged distribution. Because of
this reason DVST is knows as Storage Type CRT. In DVST no refreshing is required as result
picture drawn on DVST will be seen for several minutes before fading.
Various components of DVST :
1. Electron guns –
Two electron guns are used in DVST : Primary Gun and Flood Gun. Primary gun is used to
store picture pattern. Flood gun is used to maintain picture display on phosphor coated
screen.
2. Phosphor Coated Screen –
In DVST the inner surface of CRT is coated with phosphor crystals is of high persistence
that emit light when beam of electrons strike them.
3. Storage Mesh –
It is thin and high quality wire that is coated with dielectric and is located just behind
phosphor coated screen. Primary gun deposits pattern of positive charge on this grid and
it is transferred to phosphor coated screen by continuous flood of electrons produced by
flood gun. Thus Storage Mesh stores picture to be displayed in form of positive charge
distribution.
4. Collector –
This grid is located just behind storage mesh and purpose of this negatively charged grid
is to smooth out flow of flood electrons.
Working principle of DVST:
In DVST similar with CRT electron gun and phosphor coated method is used. But in this
no electron beam is used to directly writing pictures on screen, but instead of this we
can used Storage mesh wire grid is used it is just located behind phosphor coated
screen. There is also another grid located just behind storage mesh is called Collector
and this purpose is to smooth out flow of flood electrons. The flood gun produce large
number of electrons, this negatively charged grid reduces speed of these electrons. Then
electrons pass through collector at low velocity and attracted by positive charged
portions of storage mesh and strike at portions of phosphor coated screen to display
picture. Some electrons get repelled by other portions of mesh that are negatively
charged.
Since the collector has slowly down electrons, in this way they not able to produce
sharpened images. So to reduce this problem, screen itself is maintained at a high
positive potential by means of voltage applied to thin aluminium coating between tube
face and phosphor.

Figure – Direct View Storage Tube


Advantages of DVST :
 For picture display it does not require refreshing.
 Display complex pictures at high resolution without any flicker.
 No use of frame buffer or refresh buffer.
Disadvantages of DVST :
 Not used for dynamic graphic such as animation.
 These systems do not display colors.
 To erase selected part of an image, entire screen needs to be erased and modified
pictures needs to be redrawn.

Random Scan and Raster Scan Display:

Random Scan Display:

Random Scan System uses an electron beam which operates like a pencil to create a line image on
the CRT screen. The picture is constructed out of a sequence of straight-line segments. Each line
segment is drawn on the screen by directing the beam to move from one point on the screen to the
next, where its x & y coordinates define each point. After drawing the picture. The system cycles back
to the first line and design all the lines of the image 30 to 60 time each second. The process is shown
in fig:

Random-scan monitors are also known as vector displays or stroke-writing displays or calligraphic
displays.

Advantages:

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

2. Produce smooth line drawings.

3. High Resolution

Disadvantages:

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

Raster Scan Display:

A Raster Scan Display is based on intensity control of pixels in the form of a rectangular box called
Raster on the screen. Information of on and off pixels is stored in refresh buffer or Frame buffer.
Televisions in our house are based on Raster Scan Method. The raster scan system can store
information of each pixel position, so it is suitable for realistic display of objects. Raster Scan provides
a refresh rate of 60 to 80 frames per second.
×

Frame Buffer is also known as Raster or bit map. In Frame Buffer the positions are called picture
elements or pixels. Beam refreshing is of two types. First is horizontal retracing and second is vertical
retracing. When the beam starts from the top left corner and reaches the bottom right scale, it will
again return to the top left side called at vertical retrace. Then it will again more horizontally from
top to bottom call as horizontal retracing shown in fig:

Types of Scanning or travelling of beam in Raster Scan

1. Interlaced Scanning

2. Non-Interlaced Scanning

In Interlaced scanning, each horizontal line of the screen is traced from top to bottom. Due to which
fading of display of object may occur. This problem can be solved by Non-Interlaced scanning. In this
first of all odd numbered lines are traced or visited by an electron beam, then in the next circle, even
number of lines are located.

For non-interlaced display refresh rate of 30 frames per second used. But it gives flickers. For
interlaced display refresh rate of 60 frames per second is used.

Advantages:

1. Realistic image

2. Million Different colors to be generated

3. Shadow Scenes are possible.

Disadvantages:

1. Low Resolution

2. Expensive
Differentiate between Random and Raster Scan Display:

Random Scan Raster Scan

1. It has high Resolution 1. Its resolution is low.

2. It is more expensive 2. It is less expensive

3. Any modification if needed is easy [Link] is tough

4. Solid pattern is tough to fill [Link] pattern is easy to fill

5. Refresh rate depends or resolution 5. Refresh rate does not depend on the picture.

6. Only screen with view on an area is displayed. 6. Whole screen is scanned.

7. Beam Penetration technology come under it. 7. Shadow mark technology came under this.

8. It does not use interlacing method. 8. It uses interlacing

9. It is restricted to line drawing applications 9. It is suitable for realistic display.

Types of Coordinate Systems

There are two main types of coordinate systems in computer graphics:

a. Cartesian Coordinate System

The Cartesian coordinate system is the most commonly used system in computer graphics. It is based
on perpendicular axes, typically labeled as X, Y, and Z. These axes define positions in 2D or 3D space.

 2D Coordinate System: In 2D graphics, we use the X and Y axes to represent horizontal and
vertical directions, respectively. A point in the 2D plane is represented as a pair of
coordinates (X, Y).

Example: A point with coordinates (5, 3) represents a position that is 5 units along the X-axis and 3
units along the Y-axis.

 3D Coordinate System: In 3D graphics, we introduce the Z axis, which represents the depth
or the third dimension. A point in 3D space is represented by three coordinates (X, Y, Z).
Example: A point with coordinates (4, 2, 7) represents a position that is 4 units along the X-axis, 2
units along the Y-axis, and 7 units along the Z-axis.

b. Homogeneous Coordinate System

In computer graphics, especially when applying transformations such as translation, scaling, and
rotation, the homogeneous coordinate system is often used. It is an extension of the Cartesian
system that includes an additional dimension, W, for easier manipulation of 2D and 3D objects.

 2D Homogeneous Coordinates: A point in 2D is represented as (X, Y, W), where W is the


homogeneous coordinate. By setting W = 1, the homogeneous coordinates become the same
as Cartesian coordinates (X, Y).

Example: The point (5, 3) in Cartesian coordinates can be written as (5, 3, 1) in homogeneous
coordinates.

 3D Homogeneous Coordinates: Similarly, in 3D, a point is represented as (X, Y, Z, W). This


system simplifies the application of transformations like scaling, translation, and project.

2. Representation of Points and Objects

a. Representation of Points

A point in a coordinate system is a position defined by its coordinates along the axes. In 2D graphics,
it is represented as (X, Y), and in 3D graphics, it is represented as (X, Y, Z). Points do not have
dimensions, but they serve as the basic building blocks for more complex geometric shapes.

b. Representation of Lines

A line in computer graphics is defined by two endpoints in space. In a 2D coordinate system, a line
segment between two points P1(X1, Y1) and P2(X2, Y2) is described by its endpoints. In 3D, it is
represented as P1(X1, Y1, Z1) and P2(X2, Y2, Z2).

The equation of a line in 2D can be expressed as:

Y=mX+bY = mX + bY=mX+b

Where:

 m is the slope of the line,

 b is the Y-intercept.

c. Representation of Shapes

Shapes like triangles, rectangles, and polygons are defined by a series of connected points (vertices).
For example:

 A triangle in 2D can be represented by three points (X1, Y1), (X2, Y2), (X3, Y3).

 A rectangle can be represented by four vertices that form its corners.

In 3D graphics, shapes become polyhedra, with each face being defined by its vertices in 3D space.
For instance, a cube can be represented by eight vertices (one for each corner of the cube).
3. Coordinate Systems for Different Graphics Environments

a. 2D Coordinate System

In 2D graphics, objects are represented on a flat plane using the X and Y axes. The origin (0, 0) usually
represents the bottom-left corner of the screen, though it can vary depending on the software or
library being used.

Applications:

 User interfaces (UI) for software.

 2D games.

 Graph plotting and charting.

b. 3D Coordinate System

In 3D graphics, objects are placed in a 3D space using the X, Y, and Z axes. The Z axis adds depth,
which allows objects to appear closer or further away from the viewer.

Applications:

 3D modeling and animation.

 Virtual reality (VR) and augmented reality (AR).

 Simulation and scientific visualization.

c. Screen Coordinate System

The screen coordinate system represents positions on a display device, typically measured in pixels.
The origin (0, 0) in screen coordinates is often located at the top-left corner of the screen, with the X
axis increasing to the right and the Y axis increasing downward.

d. World Coordinate System

The world coordinate system defines the position of objects in the entire virtual world. It is an
abstract system where objects are placed relative to a fixed reference point (the origin of the world).
In 3D applications, the world coordinate system is essential for maintaining consistent object
positioning.

e. Object Coordinate System

Each object in a 3D environment has its own local or object coordinate system. The coordinates of
points on the object are relative to this local system. Before rendering, these local coordinates are
transformed into world coordinates.

Importance of Coordinate Systems in Rendering and Animation

Coordinate systems are crucial for rendering and animation. In rendering, they define how objects
are drawn on the screen, ensuring correct perspective, lighting, and texture mapping. In animation,
transformations of objects between coordinate systems control motion and interactions between
objects in a scene.

For example:
 In a 2D game, the movement of characters across the screen relies on translating their
coordinates.

 In a 3D animation, rotating a model to simulate movement (e.g., spinning a wheel) uses


transformations in the 3D coordinate system.

Graphics output primitives


Graphics output primitives are the basic geometric elements used to create complex images
in computer graphics. They are the foundation of drawing and rendering processes. Common
graphics output primitives include:

1. *Point*: A single location in space.

2. *Line*: A straight connection between two points.

3. *Polyline*: A series of connected lines.

4. *Polygon*: A closed shape made of multiple lines.

5. *Circle*: A round shape defined by a center and radius.

6. *Ellipse*: A stretched circle.

7. *Curve*: A smooth, flowing line.

8. *Text*: Characters or words displayed on the screen.

Attributes of output primitives:


Attributes – defines how these primitives appear such as color, line style, thickness etc.

1. PointDefinition: A point is the simplest graphics primitive, representing a location in space.


Attributes:

Position (x, y): The coordinates that define the point's location.

Color: The color of the point.

Size: The diameter or size of the point, which affects how large it appears.

2. LineDefinition: A line connects two points in space.


Attributes:

Start and End Points (x1, y1, x2, y2): Defines the line's position.

Line Style: Solid, dashed, or dotted styles.

Line Width: The thickness of the line.

Color: The color of the line.

3. PolygonDefinition: A polygon is a closed shape made up of several connected lines (edges) and
vertices.
Attributes:

Vertices: The (x, y) coordinates of the polygon's corners.

Fill Style: Solid, patterned, or textured filling of the shape.

Edge Style: Solid or dashed outlines of the polygon.

Edge Width: Thickness of the polygon's [Link] (Fill and Border): Separate colors for the
border and the fill.

[Link] / EllipseDefinition: A circle is defined by its center and radius, while an ellipse is defined
by two radii (semi-major and semi-minor axes).

Attributes:

Center (x, y): The coordinates of the center of the circle or ellipse.

Radius / Radii: The radius (circle) or semi-major and semi-minor axes (ellipse).

Fill Style: Solid or patterned interior of the shape.

Edge Style: Solid or dashed borders.

Edge Width: Thickness of the border.

Color (Fill and Border): Colors for both the interior and the boundary.

[Link]: Curves can be represented by a variety of methods, such as Bézier curves or


splines.

Attributes:

Control Points: Points that influence the curve’s shape.

Curve Type: Linear, quadratic, cubic, or higher-order curves.

Line Style: Solid, dashed, or [Link] Width: The thickness of the curve.

Color: The color of the curve.

[Link]: Text is used to display alphanumeric characters as part of the graphic.


Attributes:

Position (x, y): The coordinates where the text is placed.

Font: The typeface or font style of the text.

Size: The size of the text.

Color: The color of the text.

Alignment: Horizontal and vertical alignment of the text relative to its position.

Implementation Algorithms for Graphics Primitives:


 Line Drawing Algorithm
1. Digital Differential Analyzer [DDA] Algorithm
2. Bresenham’s line drawing algorithm
 Circle Drawing Algorithm
1. Bresenham circle drawing algorithm
2. Midpoint Circle Drawing algorithm

Line Drawing Algorithm


Primary Design criteria:

1) Line should appear straight

2) Line should start and end accurately

3) Line should have constant brightness along their length

4) Displayed lines should be independent of line length and orientation

5) Line should be drawn rapidly

[Link] Differential Analyzer [DDA] Algorithm

Algorithm:
1. Input: Two endpoints of the line, (x0, y0) and (x1, y1).

2. Calculate the differences:

dx = x1 - x0 (difference in the x-coordinates)

dy = y1 - y0 (difference in the y-coordinates)

3. Calculate the steps /length:

Steps or length = max(|dx|, |dy|)

(This is the number of pixels that need to be drawn. We take the larger value between dx and dy to
determine how many steps to take.)

4. Calculate the increment for each step:

Xinc = dx / steps (This gives the incremental change in the x-coordinate for each step.)

Yinc = dy / steps (This gives the incremental change in the y-coordinate for each step.)

5. Set the initial point: Start plotting from (x0, y0).

6. For each step:

Plot the current point.

Increment the x and y coordinates by Xinc and Yinc, respectively.

Round the new coordinates to the nearest integer and plot them as pixels.

7. Repeat this process until the line is drawn.


Example

Consider end points of a line are (0,0) and (4,4). Use DDA to rasterize the line.

Solu:

X1 = 0 ; y1= 0; x2= 4; y2 = 4

abs(x2 –x1) => abs(4-0) =4

abs(y2-y1) => abs(4-0) = 4

so, steps = 4

Xinc = dx/steps

= (4-0)/4

=1

Yinc = dy/steps

= (4-0)/4

=1

X = X + Xinc => X= 0+0.5

= 0.5

Y= Y+ Yinc => Y=0+0.5

=0.5
Advantages:
 Simple and easy to implement.
 Works well for lines with any slope (positive, negative, or zero).

Disadvantages:
 Involves floating-point arithmetic, which can be slower on systems that do not have
hardware support for floating-point operations.
 Less efficient compared to Bresenham's algorithm for drawing lines, especially in systems
with limited floating-point computation.

[Link]’s line drawing algorithm


Algorithm:

[Link] the algorithm.

2. Declare Variables:

x1, y1, x2, y2, d, i1, i2, dx, dy

3. Enter values for (x1, y1) and (x2, y2)

4. Calculate Differences:

dx = x2 - x1

dy = y2 - y1

i1 = 2 * dy

i2 = 2 * (dy - dx)

d = i1 * dx

5. Starting Point:
Set the initial point (x, y) to (x1, y1). And Xend as possible maximum values of x

i) dx < 0 then x=x2 ,y= y2 , Xend = X1


ii) dx >= then x=x1, y=y1, Xend =X2

6. Generate points at coordinates (x, y).

7. Line Completion Check:

Check if the whole line has been generated. If so, terminate.

8. Calculate coordinates of the next pixel

If d < 0 then d=d+i1

If d > 0 then d=d+i2

Then increment y=y+1

9. Increment x:

x = x + 1.

10. Draw a point of latest (x,y) coordinates

11. Then go to step 7.

12. End the Algorithm.

Example

The end points of line are(1,1) and (8,5). Use Bresenham algorithm to rasterize the line.
Circle Drawing Algorithm
[Link] circle drawing algorithm
The key feature of circle that it is highly symmetric. So, for whole 360 degree of circle we will divide
it in 8-parts each octant of 45 degree. In order to do that we will use Bresenham’s Circle Algorithm
for calculation of the locations of the pixels in the first octant of 45 degrees. It assumes that the circle
is centered on the origin. So for every pixel (x, y) it calculates, we draw a pixel in each of the 8 octants
of the circle as shown below :
In Bresenham’s algorithm at any point (x, y) we have two option either to choose the next pixel in
the east i.e. (x+1, y) or in the south east i.e. (x+1, y-1).

And this can be decided by using the decision parameter d as:

•If d > 0, then (x+1, y-1) is to be chosen as the next pixel as it will be closer to the arc.

•else (x+1, y) is to be chosen as next pixel.

Now to draw the circle for a given radius ‘r’ and centre (xc, yc) We will start from (0, r) and move in
first quadrant till x=y (i.e. 45 degree). We should start from listed initial condition:

d = 3 - (2 * r)

x=0

y=r

Algorithm:
Now for each pixel, we will do the following operations:

[Link] initial values of (xc, yc) and (x, y).

[Link] the decision parameter d to d = 3 – (2 * r).

[Link] the drawCircle(int xc, int yc, int x, int y) function.

[Link] the following steps until x <= y:

•If d < 0, set d = d + (4 * x) + 6.

•Else, set d = d + 4 * (x – y) + 10 and decrement y by 1.

•Increment the value of x.

•Call the drawCircle(int xc, int yc, int x, int y) function.

void drawCircle(int xc, int yc, int x, int y){

putpixel(xc+x, yc+y, RED);

putpixel(xc-x, yc+y, RED);

putpixel(xc+x, yc-y, RED);

putpixel(xc-x, yc-y, RED);

putpixel(xc+y, yc+x, RED);

putpixel(xc-y, yc+x, RED);

putpixel(xc+y, yc-x, RED);

putpixel(xc-y, yc-x, RED);

}
Introduction to OpenGL

 OpenGL (Open Graphics Library): A cross-language, cross-platform API for


rendering 2D and 3D vector graphics.

 Graphics Primitives: Basic elements used to create more complex graphical scenes.
In OpenGL, these include points, lines, and polygons.

We use 3 sets of libraries in our OpenGL programs:

1. Core OpenGL (GL) : consists of hundreds of commands, which begin with


a prefix "gl" (e.g., glColor, glVertex, glTranslate, glRotate). The Core
OpenGL models an object via a set of geometric primitives such as point, line
and polygon.
2. OpenGL Utility Library (GLU) : built on-top of the core OpenGL to
provide important utilities (such as setting camera view and projection) and
more building models (such as qradric surfaces and polygon tessellation). GLU
commands start with a prefix "glu" (e.g., gluLookAt, gluPerspective).
3. OpenGL Utilities Toolkit (GLUT) : OpenGL is designed to be
independent of the windowing system or operating system. GLUT is needed to
interact with the Operating System (such as creating a window, handling key
and mouse inputs); it also provides more building models (such as sphere and
torus). GLUT commands start with a prefix of "glut"
(e.g., glutCreatewindow, glutMouseFunc). GLUT is platform independent,
which is built on top of platform-specific OpenGL extension such as GLX for X
Window System, WGL for Microsoft Window, and AGL, CGL or Cocoa for Mac
OS.

Basic OpenGL Functions

1. Initialization:
o glutInit(): Initializes the GLUT (OpenGL Utility Toolkit) library.
o glutCreateWindow(): Creates a window with an OpenGL context.
2. Setting Up the Display Mode:
o glutInitDisplayMode(): Sets the display mode (e.g., RGBA color, double
buffering).
3. Setting the Viewport:
o glViewport(): Sets the viewport, which maps normalized device coordinates
to window coordinates.

Drawing Primitives

1. Points:

 glBegin(GL_POINTS): Starts specifying points.


 glVertex2f(x, y): Specifies a point in 2D space.
 glEnd(): Ends the specification of points.

2. Lines:

 glBegin(GL_LINES): Starts specifying lines.


 glVertex2f(x1, y1): Specifies the first endpoint of a line.
 glVertex2f(x2, y2): Specifies the second endpoint of a line.
 glEnd(): Ends the specification of lines.

3. Line Strips and Loops:

 glBegin(GL_LINE_STRIP): Starts specifying a connected group of line segments.


 glBegin(GL_LINE_LOOP): Similar to GL_LINE_STRIP, but connects the last
vertex back to the first.

4. Triangles:

 glBegin(GL_TRIANGLES): Starts specifying triangles.


 glVertex2f(x1, y1), glVertex2f(x2, y2), glVertex2f(x3, y3): Specifies the three
vertices of a triangle.
 glEnd(): Ends the specification of triangles.

5. Quads:

 glBegin(GL_QUADS): Starts specifying quadrilaterals.


 glVertex2f(x1, y1), glVertex2f(x2, y2), glVertex2f(x3, y3), glVertex2f(x4, y4):
Specifies the four vertices of a quadrilateral.
 glEnd(): Ends the specification of quads.

6. Polygon:

 glBegin(GL_POLYGON): Starts specifying a polygon with an arbitrary number of


vertices.
 glVertex2f(x, y): Specifies each vertex of the polygon.
 glEnd(): Ends the specification of the polygon.

7. Color and Attributes

 glColor3f(r, g, b): Sets the current color using red, green, and blue components.
 glPointSize(size): Sets the diameter of points.
 glLineWidth(width): Sets the width of lines.
Example Code
#include <GL/glut.h>

void display() {

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_TRIANGLES);

glColor3f(1.0, 0.0, 0.0); // Red

glVertex2f(-0.5, -0.5);

glColor3f(0.0, 1.0, 0.0); // Green

glVertex2f(0.5, -0.5);

glColor3f(0.0, 0.0, 1.0); // Blue

glVertex2f(0.0, 0.5);

glEnd();

glFlush();

int main(int argc, char** argv) {

glutInit(&argc, argv);

glutCreateWindow("OpenGL Triangle");

glutDisplayFunc(display);

glutMainLoop();

return 0;

}
OUTPUT

(0.0, 0.5)

Blue

/\

/ \

/ \

Red *-------* Green

(-0.5, -0.5) (0.5, -0.5)

You might also like