Professional Documents
Culture Documents
Introduction
Graphic SW and HW provide subroutines to describe a scene in terms
of basic geometric structures called output primitives (a basic geometric
shape from which complex shapes can be constructed). Those functions in a
graphic package that we use to describe the various picture components are
called the graphic output primitives or simply primitives. Output
primitives are combined to form complex structures. Output primitives
describe the geometry of objects and – typically referred to as geometric
primitives. Examples: point, line each of the output primitives has its own set
of attributes.
Point
A point is the most basic Output primitive in the graphic package. A point
contains location using x and y coordinate and the user may also pass other
Attributes of point is size and color.
Line
A line is used to generate a straight line between any two end points. Usually a
line is provided with the location of two pixel points called the starting point and
the end point and it is up to computer to decide what pixels fall between these
two points so that a straight line is generated.
Line is a collection (set) of point.
What is Algorithms?
A line segment is a part of a line that is bounded by two distinct end points, and
contains every point on the line that is between its endpoints
DDA Algorithm is the simplest line drawing algorithm. Given the starting and ending
coordinates of a line, DDA Algorithm attempts to generate the points between the
starting and ending coordinates.
Procedure
Given-
The points generation using DDA Algorithm involves the following steps-
Step-01:
ΔX = Xn – X0
ΔY =Yn – Y0
M = ΔY / ΔX
Step-02:
Find the number of steps or points in between the starting and ending coordinates.
else
Step-03:
Suppose the current point is (Xp, Yp) and the next point is (Xp+1, Yp+1).
Keep repeating Step-03 until the end point is reached or the number of generated new
points (including the starting and ending points) equals to the steps count.
Problem-01:
Calculate the points between the starting point (5, 6) and ending point (8, 12).
Solution-
Given-
Step-01:
ΔX = Xn – X0 = 8 – 5 = 3
ΔY =Yn – Y0 = 12 – 6 = 6
M = ΔY / ΔX = 6 / 3 = 2
Step-02:
Step-03:
5 6 5.5 7 (6, 7)
6 8 (6, 8)
6.5 9 (7, 9)
7 10 (7, 10)
8 12 (8, 12)
Advantages of DDA Algorithm
It is the simplest algorithm and it does not require special skills for
implementation.
It is a faster method for calculating pixel positions than the direct use
of equation y=mx + b. It eliminates the multiplication in the equation
by making use of raster characteristics, so that appropriate increments
are applied in the x or y direction to find the pixel positions along the
line path.
Disadvantages
The points generation using Bresenham Line Drawing Algorithm involves the
following steps-
Step-01:
ΔX = Xn – X0
ΔY =Yn – Y0
Step-02:
Step-03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point depending on the value of decision parameter Pk.
Problem-01:
Calculate the points between the starting coordinates (9, 18) and ending coordinates (14,
22).
Solution-
Given-
Step-01:
ΔX = Xn – X0 = 14 – 9 = 5
ΔY =Yn – Y0 = 22 – 18 = 4
Step-02:
Pk
= 2ΔY – ΔX
=2x4–5
=3
Step-03:
Thus,
Similarly, Step-03 is executed until the end point is reached or number of iterations equals
to 4 times.
(Number of iterations = ΔX – 1 = 5 – 1 = 4)
9 18
3 1 10 19
1 -1 11 20
-1 7 12 20
7 5 13 21
5 3 14 22
Problem-02:
Calculate the points between the starting coordinates (20, 10) and ending coordinates (30,
18).
Solution-
Given-
Step-01:
ΔX = Xn – X0 = 30 – 20 = 10
ΔY =Yn – Y0 = 18 – 10 = 8
Step-02:
Pk
= 2ΔY – ΔX
= 2 x 8 – 10
=6
Thus,
Similarly, Step-03 is executed until the end point is reached or number of iterations equals
to 9 times.
(Number of iterations = ΔX – 1 = 10 – 1 = 9)
20 10
6 2 21 11
2 -2 22 12
-2 14 23 12
14 10 24 13
10 6 25 14
6 2 26 15
2 -2 27 16
-2 14 28 16
14 10 29 17
10 6 30 18
Advantages
It is easy to implement.
It is fast and incremental.
It executes fast but less faster than DDA Algorithm.
The points generated by this algorithm are more accurate than DDA
Algorithm.
It uses fixed points only.
Disadvantages
Though it improves the accuracy of generated points but still the resulted
line is not smooth.
This algorithm is for the basic line drawing.
Midpoint Circle Algorithm
The Mid-point Subdivision algorithm is the extension of the Cyrus-
Beck algorithm. The Mid-Point line plotting algorithm was introduced
by “Pitway and Van Aken.” It is an incremental line drawing algorithm. In
this algorithm, we perform incremental calculations. The calculations are
based on the previous step to find the value of the next point. We perform
the same process for each step. By using the mid-point subdivision algorithm,
we can draw a line with close approximation between two points. The mid-
point subdivision line drawing algorithm subdivides the line at its midpoints
continuously.
The Mid-point Subdivision algorithm helps to compute or calculate the visible
areas of lines that appear in the window. This line plotting algorithm follows
the bisection method to divide the line into equal partitions.
Assuming we have just plotted the pixel P(xk, yk), we next need to determine whether
the pixel N (xk + 1, yk) or S(xk + 1, yk -1) is closer to the circle. So, Our decision parameter
is the circle function evaluated at the midpoint M(xk + 1, yk -1/2 ) between these two
pixels:
pk = F(circle) = (xk + 1)2+(yk -1/2)2 – r2
Case 1
Now If pk ≥ 0 that means midpoint is outside the circle and S is closest pixel so we
will choose S (xk+1, yk-1)
Putting coordinates of S in (ii) ,we have ,
pk+1 = pk + 2(xk+1)+( yk-12 – yk2 ) – (yk-1 – yk) +1
So, by putting the values pk+1 = pk + 2(xk+1)+(( yk -1)2 – yk2 ) – ((yk-1) – yk) +1.
Further, simplifying pk+1 = pk + 2(xk+1)+yk 2+1-2yk – yk2 – yk+1 + yk +1
Then, we get pk+1 = pk + 2(xk+1)-2yk +2 + 1
1.Input radius r and circle center (x, y,), and plot first point as (0,r)
p0=1-r
3. Also, At each xk position, starting at k = 0, perform the following test:
If pk < 0. Then, the next point along the circle centered on (0,0) is
(xk + 1, yk – 1) and
5. Also, Move each calculated pixel position (x, y) onto the circular path centered on (xc,
yc) and plot the coordinate values:
x=x+xc, y=y+yc
Note:
What is required?
Show each point calculation step by step
Form table
Draw a required object.