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

Computer Graphics algorithms

The document outlines four algorithms for rasterizing geometric shapes in computer graphics: the Digital Differential Analyzer (DDA) for lines, Bresenham's Line Drawing Algorithm, the Midpoint Circle Drawing Algorithm, and the Midpoint Ellipse Drawing Algorithm. Each algorithm is described with its steps, advantages, and disadvantages, highlighting their efficiency and computational methods. The DDA uses floating-point calculations, while Bresenham's and the Midpoint algorithms utilize integer operations for improved speed and accuracy.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Computer Graphics algorithms

The document outlines four algorithms for rasterizing geometric shapes in computer graphics: the Digital Differential Analyzer (DDA) for lines, Bresenham's Line Drawing Algorithm, the Midpoint Circle Drawing Algorithm, and the Midpoint Ellipse Drawing Algorithm. Each algorithm is described with its steps, advantages, and disadvantages, highlighting their efficiency and computational methods. The DDA uses floating-point calculations, while Bresenham's and the Midpoint algorithms utilize integer operations for improved speed and accuracy.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1) Digital Differential Analyzer (DDA) Algorithm

The Digital Differential Analyzer (DDA) Algorithm is a simple and efficient method used for
rasterizing lines in computer graphics. It is an incremental scan conversion method that calculates
intermediate points between two given endpoints to approximate a straight line.

DDA Algorithm Steps:

1. Input: Start and end coordinates of the line: (X0,Y0)(X0,Y0) and (X1,Y1)(X1,Y1).

2. Calculate Differences:

ΔX=X1−X0

ΔY=Y1−Y0

3. Determine Steps:

Steps=max(∣ΔX∣,∣ΔY∣)

4. Calculate Increment Values:

Xinc=ΔX/Steps

Yinc=ΔY/Steps

5. Initialize and Plot Points:

• Start from (X0,Y0)

• For each step, update:

X=X+Xinc

• Y=Y+Yinc

• Round (X,Y) and plot it.

Advantages:

• Simple to implement.

• Works well for arbitrary slopes.

Disadvantages:

• Involves floating-point calculations, which are computationally expensive.

• Rounding errors can accumulate, leading to inaccuracies.

2) Bresenham’s Line Drawing Algorithm


Bresenham’s algorithm is an efficient way to rasterize a line between two points in a grid. Unlike
the DDA algorithm, which uses floating-point operations, Bresenham’s algorithm uses only integer
calculations, making it faster.

Algorithm Steps:

1. Input: Start and end coordinates (X0,Y0) and (X1,Y1)

2. Calculate Differences:

ΔX=X1−X0

ΔY=Y1−Y0

3. Compute Decision Parameter:

P=2ΔY−ΔX

4. Initialize Starting Point: Set X=X0, Y=Y0

5. Loop Over X Values:

• If P<0, the next point is (X+1,Y), and update:

P=P+2ΔY

• If P≥0P≥0, the next point is (X+1,Y+1), and update:

P=P+2ΔY−2ΔX

• Repeat until X=X1

Advantages of Bresenham’s Algorithm:

• Uses only integer operations (faster than DDA).


• More accurate than DDA as it avoids rounding errors.
• Efficient for embedded systems and low-power devices.

3) Midpoint Circle Drawing Algorithm


The Midpoint Circle Algorithm (Bresenham’s Circle Algorithm) is an efficient rasterization technique
used to draw circles using only integer operations. It is based on the symmetry of a circle and
calculates pixel positions using incremental calculations.

Algorithm Steps:

1. Input: The center of the circle (Xc,Yc) and the radius rr.

2. Initialize:

• Start at the topmost point (X0,Y0)=(0,r)


• Compute the initial decision parameter:

P=1−r

3. Plot Symmetric Points:

• Because a circle has 8-way symmetry, plot:

(Xc+x,Yc+y),(Xc−x,Yc+y),(Xc+x,Yc−y),(Xc−x,Yc−y)

(Xc+y,Yc+x),(Xc−y,Yc+x),(Xc+y,Yc−x),(Xc−y,Yc−x)

4. Iterate Until x>y:

• If P<0, the next point is (x + 1, y), and update:

P=P+2x+1

• Else, the next point is (x + 1, y - 1), and update:

P=P+2x−2y++1

Advantages of the Midpoint Circle Algorithm:

Uses only integer calculations (fast execution).


Efficient due to decision-based movement.
Takes advantage of 8-way symmetry, reducing computations.

4) Midpoint Ellipse Drawing Algorithm


The Midpoint Ellipse Algorithm is used to draw ellipses efficiently using only integer calculations. It
works by exploiting the symmetry of ellipses and using incremental calculations to determine pixel
positions. The algorithm is divided into two regions based on the ellipse equation.

Ellipse Equation:

The equation of an ellipse centered at (0,0) is:

x2/a2+y2/b2=1

Where:

• a = Semi-major axis (horizontal radius)

• b = Semi-minor axis (vertical radius)

The algorithm uses midpoint decision parameters to decide whether the next pixel should be
placed horizontally or diagonally.

Algorithm Steps:

1. Input: Semi-major axis a, semi-minor axis b, and center (Xc,Yc).


2. Initialize Region 1 (First Quadrant Until Slope = -1):

• Start at (0,b)

• Compute the initial decision parameter:

P1=b2−a2b+(1/4)a

• If P1<0, move right; otherwise, move diagonally down-right.

• Stop when 2b2x≥2a2y2b2x≥2a2y (i.e., slope becomes -1).

3. Switch to Region 2 (After Slope = -1):

• Start where Region 1 ended.

• Compute new decision parameter:P2=b2(x+0.5)2+a2(y−1)2−a2b2P2


=b2(x+0.5)2+a2(y−1)2−a2b2

• If P2>0P2>0, move down; otherwise, move diagonally down-right.

4. Plot 4 Symmetric Points in Each Step:

• Because of ellipse symmetry, plot:(Xc+x,Yc+y),(Xc−x,Yc+y)(Xc+x,Yc+y),(Xc−x,Yc


+y)(Xc+x,Yc−y),(Xc−x,Yc−y)(Xc+x,Yc−y),(Xc−x,Yc−y)

You might also like