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

02.ScanConversion MCA

Here are the key steps for the DDA line algorithm when the slope is positive and less than 1: 1. Sample at unit intervals along the x-axis (Δx = 1) 2. Calculate the corresponding y-value at each x position using the equation: yk+1 = yk + m 3. Round the calculated y-value to the nearest integer 4. Plot the pixel at the rounded x,y coordinates 5. Repeat until the end of the line is reached For the given line segment from (3,3) to (23,7), the slope m is 0.2. So at each x interval of 1, the y-value is incremented by 0

Uploaded by

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

02.ScanConversion MCA

Here are the key steps for the DDA line algorithm when the slope is positive and less than 1: 1. Sample at unit intervals along the x-axis (Δx = 1) 2. Calculate the corresponding y-value at each x position using the equation: yk+1 = yk + m 3. Round the calculated y-value to the nearest integer 4. Plot the pixel at the rounded x,y coordinates 5. Repeat until the end of the line is reached For the given line segment from (3,3) to (23,7), the slope m is 0.2. So at each x interval of 1, the y-value is incremented by 0

Uploaded by

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

Scan Conversion

Line
Circle
Representations in Graphics
➔A picture can be described in several
ways
➔Vector Graphics
➔ Image is represented by continuous
geometric objects – lines & curves
➔ Raster Graphics
➔ Image is represented as a rectangular
grid of coloured squares
Representations in Graphics
➔Vector Graphics
➔Graphics objects: geometry + colour
➔ Complexity ~ O(number of objects)
➔ Geometric transformation possible without
loss of information (zoom, rotate, …)
➔ Diagrams, schemes, …
➔ Examples: CorelDraw, inkscape...
Representations in Graphics
➔Raster Graphics
➔Generic
➔ Image processing techniques
➔ Geometric Transformation: loss of information
➔ Complexity ~ O(number of pixels)
➔ Jagged edges, anti-aliasing
➔ Realistic images, textures, ...
➔ Examples: Paint, PhotoShop, ...
Introduction:

 Picture descriptions:
 Raster:
 Completely specified by the set of intensities for the pixels positions in the
display.
 Shapes and colors are described with pixel arrays.
 Scene displayed by loading pixels array into the frame buffer.
 Vector:
 Set of complex objects positioned at specified coordinates locations within
the scene.
 Shapes and colors are described with sets of basic geometric structures.
 Scene is displayed by scan converting the geometric-structure specifications
into pixel patterns.
Output Primitives
➔We assume Raster Graphics
➔Everything can be described internally
with
➔ pixel arrays or
➔ Set of basic geometric structures
➔ Straight line segments
➔ Polygon colour areas
Output Primitives
➔A Graphic programming package must
provide output primitives
➔ Functions to describe a scene in terms
of basic geometric structures
➔Each output primitive is specified with
➔ input coordinate data and
➔ other information about the way that
object is to be displayed
Output Primitives
➔Simplest :
➔ Points and
➔ Straight lines
➔Additional output primitives :
➔ Circles, conic sections,
➔ Quadric surfaces, spline curves and
surfaces, Polygon colour areas
➔ Character Strings
Output Primitives
➔We will examine Device level algorithms
for displaying 2-dimensional output
primitives
➔Focus on : Scan-conversion methods for
Raster Graphics systems.
Introduction:

 Output Primitives:
 Basic geometric structures used to describe scenes.
 Can be grouped into more complex structures.
 Each one is specified with input coordinate data and
other information about the way that object is to be
displayed.
 Examples: point, line and circle each one with
specified coordinates.
 Construct the vector picture.
Introduction:
In digital representation:
 Display screen is divided into scan lines and columns.
 Pixels positions are referenced according to scan line number
and column number (columns across scan lines).
 Scan lines start from 0 at screen bottom, and columns start
from 0 at the screen left side.
 Screen locations (or pixels) are referenced with integer values.
 The frame buffer stores the intensities temporarily.
 Video controller reads from the frame buffer and plots the
screen pixels.
Points
➔Point plotting : conver a single
coordinate position into appropriate
operations for the output device.
➔In CRT monitor : electron beam is turned
on to illuminate the screen phosphor at
the selected location
➔In vector graphics system : the
coordinate values are converted into
horizontal and vertical deflection
voltages
Point Plotting
➔To load the specified color into the frame
buffer at the position ….
➔ Generic (low-level) function/procedure :
setPixel (x, y);
➔ OpenGL point function :
glBegin (GL_POINTS);
glVertex* (x, y, z);
glEnd();
Point Plotting
➔ Generic (low-level) function/procedure :
setPixel (x, y);
➔ OpenGL point function :
glBegin (GL_POINTS);
glVertex* (x, y, z);
glEnd();
Point Plotting
➔Sometime, we want to retrieve the current
frame-buffer intensity for a specified
location :
getPixel (x, y);
Point Drawing:
 Converting a single coordinate position furnished by
an application program into appropriate operation for
the output device in use.
 In raster system:
 Black-white: setting the bit value corresponding to a
specified screen position within the frame buffer to 1.
 RGB: loading the frame buffer with the color codes for the
intensities that are to be displayed at the screen pixel
positions.
Points and Lines
➔A line can be drawn by using points

➔A straight-line segment in a scene is


defined by the coordinate positions for the
endpoints of the segment.
Line Drawing Algorithms

y2

y1
x1 x2
Line Drawing:

 A straight line is specified by two endpoint


positions.
 Line drawing is done by:
 Calculating intermediate positions between the
endpoints.
 Directing the output device to fill in the calculated
positions as in the case of plotting single points.
Line-Drawing Algorithms
➔To display the line on a raster monitor, the
graphics system must first project the
endpoints to integer screen coordinates
and determine the nearest pixel positions
along the line path between the two
endpoints.
➔Then the line color is loaded into the
frame buffer at the corresponding pixel
coordinates.
Line-Drawing Algorithms
➔This process digitizes the line into a set of
discrete integer positions that, in general,
only approximates the actual line path.
➔For example, a computed line position of
(10.48, 20.51), is converted to pixel
position (10, 21).
➔This rounding of coordinate values to
integers causes all lines (except horizontal
and vertical lines) to be displayed with a
stair-step appearance (“the jaggies”)
Line-Drawing Algorithms
➔This rounding of coordinate values to
integers causes all but horizontal and
vertical lines to be displayed with a stair-
step appearance (“the jaggies”)
Line Drawing:
 Plotted positions may be only approximations to the
actual line positions between endpoints.
 A computed position (10.48, 20.51) is converted to pixel
(10,21).
 This rounding causes the lines to be displayed with a stairstep
appearance.
 Stairsteps are noticeable in low resolution systems, it can be
improved by:
 Displaying lines on high resolution systems.
 Adjusting intensities along line path.
Line Drawing:
 The Cartesian intercept equation for a straight line:
y= m. x +b
Where m is the line slop and b is y intercept.
 For line segment starting in (x1,y1) and ending in (x2,y2), the
slop is:
m= (y1-y2)/(x1-x2)
b= y1- m.x1
 For any given x interval x, we can compute the corresponding y
interval y:
y= m .x
 Or x interval x from a given y:
x= y/m
Line Drawing:
Sampling along x axis
 On raster systems, lines are plotted
Y2
with pixels, and step sizes in the
horizontal and vertical directions are
constrained by pixel separations. y1

X1 x2
 Scan conversion process samples a
line at discrete positions and determine Sampling along y axis
the nearest pixel to the line at each Y2
sampled position.

y1

X1 x2
Line Drawing Algorithms:

 Digital Differential Analyzer (DDA):


Samples the line at unit intervals in one coordinate
and determine corresponding integer values nearest
the line path for the other coordinate.
 Bresenham’s Line Algorithm:
Scan converts lines using only incremental integer
calculations.
Line Drawing Algorithms:

 DDA
 A scan-conversion line algorithm based on calculating either
y or x using line points calculating equations.
 In each case, choosing the sample axis depends on the slop
value.
 The unit step for the selected axis is 1.
 The other axis is calculated depending on the first axis and
the slop m.
 The next slides will show the different cases of the slop:
Line Drawing Algorithms:

 DDA
 Case 1:the slop is Positive and less than 1
 Sample at unit x interval (x=1) and compute each successive
y value as :
y k+1= yk+ m
 K takes integer values starting from 1,at the first point, and
increasing by 1 on each step until reaching the final endpoint.
 The calculated y must be rounded to the nearest integer.
 Example:
Describe the line segment which starts at (3,3) and ends at
(23,7).
Lines Drawing Algorithms: DDA
24
23
22
21
m= (7-3)/(23-3) 20
=4/20 19
18
=0.2 17
16
15
x=1 14
13
y=0.2 12
11
10
9
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Lines Drawing Algorithms: DDA
x y actual point pixel position 24
23
3 3 (3,3) (3,3) 22
4 3.2 (4,3.2) (4,3) 21
5 3.4 (5,3.4) (5,3) 20
6 3.6 (6,3.6) (6,4) 19
18
7 3.8 (7,3.8) (7,4) 17
8 4 (8,4) (8,4) 16
9 4.2 (9,4.2) (9,4) 15
10 4.4 (10,4.4) (10,4) 14
13
11 4.6 (11,4.6) (11,5) 12
12 4.8 (12,4.8) (12,5) 11
13 5 (13,5) (13,5) 10
9
14 5.2 (14,5.2) (14,5) 8
15 5.4 (15,5.4) (15,5) 7
16 5.6 (16,5.6) (16,6) 6
17 5.8 (17,5.8) (17,6) 5
4
.. .. .. .. 3
.. .. .. .. 2
22 6.8 (22,6.8) (22,7) 1
23 7 (23,7) (23,7) 0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Line Drawing Algorithms:

 DDA
 Case 2:the slop is Positive and greater than 1
 Sample at unit y interval (y=1) and compute each successive
y value as :
x k+1= xk+ (1/m)
 K takes integer values starting from 1,at the first point, and
increasing by 1 on each step until reaching the final endpoint.
 The calculated x must be rounded to the nearest integer.
 Example:
Describe the line segment which starts at (3,3) and ends at
(7,23).
Line Drawing Algorithms: DDA
24
23
22
m= (23-3)/(7-3) 21
20
= 20/4 19
=5 18
17
16
15
x =1/m 14
=1/5 13
12
=0.2 11
10
9
y =1 8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Line Drawing Algorithms: DDA
y x actual point pixel position 24
23
3 3 (3,3) (3,3) 22
4 3.2 (3.2,4) (3,4) 21
5 3.4 (3.4,5) (3,5) 20
6 3.6 (3.6,6) (4,6) 19
18
7 3.8 (3.8,7) (4,7) 17
8 4 (4,8) (4,8) 16
9 4.2 (4.2,9) (4,9) 15
10 4.4 (4.4,10) (4,10) 14
13
11 4.6 (4.6,11) (5,11) 12
12 4.8 (4.8,12) (5,12) 11
13 5 (5,13) (5,13) 10
9
14 5.2 (5.2,14) (5,14) 8
15 5.4 (5.4,15) (5,15) 7
16 5.6 (5.6,16) (6,16) 6
17 5.8 (5.8,17) (6,17) 5
4
.. .. .. .. 3
.. .. .. .. 2
22 6.8 (6.8,22) (7,22) 1
23 7 (7,23) (7,23) 0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Line Drawing Algorithms:

 DDA
 Case 3:the slop is negative and its absolute value is less than 1
 Follow the same way in case 1.
 Case 4:the slop is negative and its absolute value is greater than 1
 Follow the same way in case 2.
 In the previous 4 cases, we start from the left to the right. If
the state is reversed then:
If the absolute slop is less than 1, set x=-1 and
y k+1= yk - m
If the absolute slop is greater than 1, set y=-1 and
x k+1= xk - (1/m)
Line Drawing Algorithms:

 DDA properties
 A faster method for calculating pixel positions than the direct
use: y= m . x +b.
 Uses x or y to eliminate the multiplication in the above
equation.
 Rounding successive additions of the floating-point
increment can cause the calculated pixel positions to drift
away from the true line path for long line segment.
 Rounding and floating-point arithmetic are time-consuming
operations.
Line Drawing Algorithms:

 Bresenham’s Line Algorithm:


 Scan converts lines using only incremental integer
calculations.
 Can be adapted to display circles and other
curves.
 When sampling at unit x intervals, we need to
decide which of two possible pixel positions is
closer to the line path at each sample step by using
a decision parameter.
Bresenham’s Line Algorithm
➔Scan converts lines using only
incremental integer calculations.
➔Can be adapted to display circles and
other curves.
➔When sampling at unit x intervals, we
need to decide which of two possible pixel
positions is closer to the line path at each
sample step by using a decision
parameter.
Bresenham’s Line Algorithm
➔The idea :
➔Avoid floating point multiplication and
addition to compute mx + b
➔Avoid computing ROUND of (mx + b) in
every step.
➔In Bresenham's algorithm, we move
across the x-axis in unit intervals.
Bresenham’s Line Algorithm
➔We always increase x by 1,
➔xk+1 = xk + 1
➔For y, there are 2 options
➔ yk+1 = yk+1 OR yk+1 = yk
Bresenham’s Line Algorithm
➔That is, the next pixel is,
➔(xk+ 1, yk) OR (xk+ 1, yk+ 1)
➔pick the y value (among Yk + 1 and Yk)
corresponding to a point that is closer to
the original line.
Bresenham’s Line Algorithm
➔At position xk+1, the vertical pixel
separation of the two pixels yk and
yk+1from the mathematical line path is d1
and d2 respectively
Bresenham’s Line Algorithm
➔We need to a decision parameter to
decide whether to pick yk + 1 or yk as next
point.
➔The idea is to keep track of slope error
from previous increment to y. If the slope
error becomes greater than 0.5, we know
that the line has moved upwards one pixel.
Line Drawing Algorithms:

 Bresenham’s Line Algorithm:


The decision parameter (pk) is an integer number
that is proportional to the difference between the
separations of the two pixel positions from the
actual line path.
Depending on the slop sign and value the decision
parameter determine which pixel coordinates would
be taken in the next step.
Line Drawing Algorithms:

 Bresenham’s Line Algorithm:


 Pk for line with positive slop less than 1:
 Sampling at unit x intervals.
 At pixel (xk,yk) we need to decide whether (xk+1,yk) or
(xk+1,yk+1) would be plotted in column xk+1.
 d1 and d2 are the vertical pixel separations from the
mathematical line path.
 y coordinate on the mathematical line at pixel xk+1 is
calculated as:
y= (x+1.m)+b
d1= y-yk
d2= yk+1-y
Pk =x(d1-d2)
Line Drawing Algorithms:

 Bresenham’s Line Algorithm:


Properties of Pk for line with positive slop less than 1:
 If the pixel at yk is closer to the line path than the
pixel at yk+l (that is, d1 < d2), then decision
parameter pk is negative and we plot the lower
pixel.
 On reverse, pk is positive and we plot the upper
pixel.
If pk is zero ,then choose either yk+l for all such
cases, or yk.
Line Drawing Algorithms:

 Bresenham’s Line Algorithm:


Properties of Pk for line with positive slop less than 1:
 Incremental integer calculations can be used to
obtain values of successive decision
parameters, because change occur on either x
or y coordinates:
pk+1=pk+2y-2x(yk+1-yk)
and p0=2y-x
Bresenham’s Line Algorithm
Line Drawing Algorithms: Bresenham’s
24
23
Drawing the line between 22
21
the endpoints (3,3) and 20
(23,13) 19
18
17
m= (13-3)/(23-3)= 0.5 16
15
14
13
x= 20 12
y=10 11
10
9
8
P0= 2(10)-20=0 7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Line Drawing Algorithms: Bresenham’s
24
K P x+1 y+1 23
22
0 0 4 4 21
1 -20 5 4 20
19
2 0 6 5 18
17
3 -20 7 5 16
4 0 8 6 15
14
5 -20 9 6 13
6 0 10 7 12
11
7 -20 11 7 10
9
8 0 12 8 8
9 -20 13 8 7
6
10 0 14 9 5
4
.. .. .. .. 3
.. .. .. .. 2
1
19 -20 23 13 0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Bresenham’s Line Algorithm
➔Some assumptions to keep algorithm simple.
1.We draw line from left to right.
2.x1 < x2 and y1< y2
3.Slope of the line is between 0 and 1. We draw a
line from lower left to upper right.
➔Cases other than above
assumptions can be handled
using reflection.
Line Drawing Algorithms:

 Bresenham’s line algorithm properties

 It is generalized to lines with arbitrary slope by considering


the symmetry between the various octants and quadrants of
the xy plane.
 The constants 2y and 2y - 2x are calculated once for
each line to be scan converted, so the arithmetic involves
only integer addition and subtraction of these two constants.
… Finally
24
23
Special cases can be 22
21
handled separately: 20
19
18
Horizontal y=0 17
Vertical x=0 16
15
Diagonal |x|=|y| 14
13
12
each can be loaded 11
10
directly into the frame 9
8
buffer without processing 7
them through the line- 6
5
plotting algorithms. 4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Mid-Point Line Algorithm
➔MidPoint Line algorithm is a different way to
represent Bresenham’s algorithm.
➔for any given/calculated previous pixel P(x p,yp),
there are two candidates for the next pixel
closest to the line,
➔ E(xp+1, yp) OR NE(xp+1, yp+1)
➔ (Estands for East and
NE stands for North-East)
Mid-Point Line Algorithm
1. Find middle of two possible next points.
➢ Middle of E(xp+1, yp) and NE(xp+1, yp+1) is
M(xp+1, yp+ ½).
2. If M is above the line, then choose E as next point.
3. If M is below the line, then choose NE as next point.
Mid-Point Line Algorithm
➔Some assumptions to keep algorithm simple.
1.We draw line from left to right.
2.x1 < x2 and y1< y2
3.Slope of the line is between 0 and 1. We draw a
line from lower left to upper right.
➔Cases other than above
assumptions can be handled
using reflection.
Mid-Point Line Algorithm
➔Let us consider a line y = mx + B.
➔We can re-write the equation as :
➔y = (dy/dx)x + B or (dy)x + B(dx) - y(dx) = 0
➔Let f(x, y) = (dy)x - y(dx) + B(dx) -----(1)
Mid-Point Line Algorithm
➔f(x, y) = (dy)x - y(dx) + B(dx)
➔ For all points (x,y) on the line, f(x, y) = 0.
➔ For all points (x,y) above the line, f(x, y) < 0.
➔ For all points (x,y) below the line, f(x, y) >= 0.
Mid-Point Line Algorithm
➔This relationship is used to determine the relative
position of M
➔M = (xp+1, yp+½)
➔So our decision parameter d is,
➔d = f(M) = f(xp+1, yp+½)
Mid-Point Line Algorithm
➔d = f(M) = f(xp+1, yp+½)
➔How to efficiently find new value of d from its old
value?
➔For simplicity, let as write f(x, y) as ax + by + c.
➔Where a = dy, b = -dx, c = B*dx
➔ We got these values from equation (1)
Mid-Point Line Algorithm
➔Case 1: If E is chosen then for next point :
➔dnew = f(xp+2, yp+½) = a(xp+2) + b(yp+½) + c

➔dold = a(xp+1) + b(yp+½) + c


➔Difference (Or delta) of two distances:
➔DELd = dnew – dold
= a(xp+2)- a(xp+1)+ b(yp+½)- b(yp+½)+ c – c
= a(xp) +2a – a(xp) – a
= a.
➔Therefore, dnew = dold + dy. (as a = dy)
Mid-Point Line Algorithm
➔Case 2: If NE is chosen then for next point :
➔dnew = f(xp+2, yp+3/2) = a(xp+2) + b(yp+3/2) + c
➔dold = a(xp+1) + b(yp+1/2) + c
➔Difference (Or delta) of two distances:
➔DELd = dnew -dold
= a(xp+2)- a(xp+1)+ b(yp+3/2)- b(yp+1/2)+ c – c
= a(xp) + 2a – a(xp) – a + b(yp) + 3/2b – b(yp) -1/2b
=a+b
➔Therefore, dnew = dold + dy – dx. (as a = dy , b = -dx)
Mid-Point Line Algorithm
➔Calculation For initial value of decision parameter d0:
➔d0 = f(x1+1 , y1+1/2)
= a(x1 + 1) + b(y1 + 1/2) + c
= ax1+ by1 + c + a + b/2
= f(x1,y1) + a + b/2
= a + b/2 ( as f(x1, y1) = 0 )

➔d0 = dy – dx/2. (as a = dy, b = -dx)


Mid-Point Line Algorithm
➔Initial Decision Parameter d0 = dy – dx/2.
➔Case 1: If E is chosen then for next point :
➔ dnew = dold + dy
➔Case 2: If NE is chosen then for next point :
➔ dnew = dold + dy – dx
Circle Generating Algorithms
Circle Properties:
 A set of points that are all at the same distance (r)
from a center point (xc,yc).
 Expressed by Pythagorean equation in Cartesian
coordinates as:
(x – xc )2 + (y - yc )2 = r2

 Any given circle can be drawn on the origin(0,0)


and then moved to its actual position by:
 Each calculated x on the circumference moved to x+xc.
 Each calculated y on the circumference is moved to y+yc.
Circle Generating Algorithms:

 Standard Algorithm
 Polar Algorithm
 Symmetry Algorithm
 Mid-point Algorithm (xc, yc )
r (x, y)
Standard Algorithm:

 Uses the Pythagorean equation to find


the points along the circumference.
 Steps along x axis by unit steps from xc-r
to xc+r and calculate y for each step as:
y= yc± √r2-(xc-yc)2
 Itinvolves considerable computations at
each step.
Standard Algorithm:
 Spacing between plotted pixels is not uniform.

 Spacing can be adjusted by stepping on y instead of x


when the slop is greater than 1, but such approach
increasing computations.
Polar Algorithm:
 Uses polar coordinates r and Ө.
 Calculate points by fixed regular step size equations
as:
x= xc + r * cosӨ
y= yc + r * sinӨ
 Step size that is chosen for Ө depends on the
application.
 Larger separations can be connected by line segments
to approximate the circle path.
Polar Algorithm:
 In raster displays, step size is 1/r which plots pixel
positions that are approximately one unit apart.

x,y
r
Ө
Symmetry Algorithm:

 Reduces computations by considering the


symmetry of circles in the eight octants in the xy
plane.
 Generates all pixel positions
around a circle by calculating
only the points within the
sector from x = 0 to x = y.
Symmetry of a Circle
➔Also, we can calculate pixel positions around a circle
path centered at the coordinate origin (0, 0).
➔Then, each position (x, y) is moved to its proper screen
position by adding xc to x and yc to y.
➔ (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);
Mid-point Algorithm:
 Samples at unit intervals and uses decision parameter to
determine the closest pixel position to the specified circle path at
each step.
 Along the circle section from x = 0 to x = y in the first quadrant, the
slope of the curve varies from 0 to -1. Therefore, we can take unit
steps in the positive x direction over this octant and use a decision
parameter to determine which of the two possible y positions is
closer to the circle path at each step. Positions in the other seven
octants are then obtained by symmetry.
Mid-Point Circle Algorithm
➔For any given pixel (x, y), the next pixel to be plotted is
either (x+1, y) or (x+1, y-1).
➔This can be decided by following the steps below.
➔Find the mid-point of the two possible pixels
➔ (x+1, y-0.5)
➔If the mid-point lies inside or on the circle perimeter, we
plot the pixel (x+1, y-1), otherwise if it’s outside we plot
the pixel (x+1, y)
Midpoint Circle Algorithm

fcirc(x, y) = x2 + y2 - r2
Mid-point Algorithm:
To apply mid-point method, we define a circle function:

and determine the nearest y position from pk:


Mid-point Algorithm:
 If pk < 0, this midpoint is inside the circle and the pixel
on scan line yk is closer to the circle boundary.

Otherwise, the midposition is outside or on the circle


boundary, and we select the pixel on scan line yk – 1 .

 Successive parameters are calculated using


incremental calculations:
Mid-Point Circle Algorithm

➔Contd...
Mid-Point Circle Algorithm ➔Contd...
Mid-point Algorithm:
 Example:
For a circle radius=10 and center (12,12)

we calculate positions in the first octant only , beginning with x=0


and ending when x=y

The initial decision parameter value:


P0=1 - r = -9

Drawing on the origin (0,0) and the initial point (0,10)


2x0=0 2y0=20
Mid-point Algorithm:
24
23
K P (xk+1,yk+1) 2xk+1 2yk+1 22
21
0 -9 (1,10) 2 20 20
1 -6 (2,10) 4 20 19
18
2 -1 (3,10) 6 20 17
3 6 (4,9) 8 18 16
15
4 -3 (5,9) 10 18 14
13
5 8 (6,8) 12 16 12
6 5 (7,7) 14 14 11
10
9
8
The first octant is completed 7
and the remained seven 6
5
octants can be plotted 4
3
according to symmetry. 2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Mid-point Algorithm:
24
23
The circle after plotting all 22
21
octants and moving it to its 20
original center (12,12) 19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Bresenham’s Circle 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 p as:
➔ If p > 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.


Bresenham’s Circle Algorithm
➔p = 3 - (2 * r)
➔x = 0
➔y = r
Bresenham’s Circle Algorithm
void circleBres(int xc, int yc, int r)
{
    int x = 0, y = r, p = 3 ­ 2 * r;
 circlePlotPoints(xc, yc, x, y);  // draw 8 points
    while (y >= x)
    {        
        x++;
        if (p > 0)
          p = p + 4 * x + 6;            
        else
        {
 y­­; 
            p = p + 4 * (x ­ y) + 10;
}        
   circlePlotPoints(xc, yc, x, y); //draw 8 points 
    }
}
Ellipse Generating Algorithm
➔An elongated circle.
➔A set of points having an equal sum distances from two
fixed positions (foci F1,F2).
➔ d1+d2=constant

ry
F2 rx F1

d2 d1

P=(x,y)
Ellipse Generating Algorithm
➔The major axis is the straight line segment extending from
one side of the ellipse to the other through the foci.
➔The minor axis spans the shorter dimension of the ellipse,

bisecting the major axis at the halfway position (ellipse


center) between the two foci.
➔The two foci and point coordinates on the circumference

are enough information to plot an ellipse with arbitrary


orientation.
Ellipse Generating Algorithm
➔The equation of the ellipse can be written in terms
of the ellipse center coordinates and parameters rx,
and ry, as:
Ellipse Generating Algorithm
➔The equation of the ellipse can be written in terms of the
ellipse center coordinates and parameters rx, and ry, as:

➔Using polar coordinates r and Ө. we can also describe the


ellipse in standard position with the parametric equations:
➔ x= x + r * cosӨ
c x
➔ y= y + r * sinӨ
c y

➔Symmetry considerations can be used to reduce


computations, the four quadrants are similar ( not the eight
octants).
Midpoint Ellipse Algorithm
➔ Similar to displaying a raster circle.
➔ Given parameters r , r , and (x ,y ), we determine
x y c c
points ( x , y) for an ellipse in standard position centered
on the origin, and then we shift the points so the ellipse is
centered at ( xc,yc).
➔ To display the ellipse in nonstandard position, we could

then rotate the ellipse about its center coordinates to


reorient the major and minor axes.
➔ This method is applied throughout the first quadrant in two

parts:
➔ Stepping on x when the slop is less than 1.

➔ Stepping on y when the slop is greater than 1.


Midpoint Ellipse Algorithm
➔ The decision parameter considered by:

➔ It has the following properties:

➔The next position to be selected depends on the sign of


this parameter.
➔The same way followed in circle we can use to choose the

start point and depending on the slop and Pk calculate the


next nearest pixel on the ellipse path.
Midpoint Ellipse Algorithm
➔The midpoint ellipse method is applied throughout the
first quadrant in two parts.
➔We divide the first quadrant according to the slope of
an ellipse with rx < ry .
Midpoint Ellipse Algorithm
➔Region 1: We process this quadrant by taking unit
steps in the x direction where the slope of the curve
has a magnitude less than 1.0.
➔Region 2: We take unit steps in the y direction where
the slope has a magnitude greater than 1.0.

➔The ellipse slope is :

➔At boundary between region 1 & 2 :


Midpoint Ellipse Algorithm
➔This means, we need 2 decision parameters :
➔ p1 and p2
Midpoint Ellipse Algorithm
➔Region 1 : At the next sampling position
(xk+1+ 1 = xk + 2), the decision parameter is evaluated
as :


➔where yk+1 is either yk or yk−1, depending on the sign of
p1k .
➔Decision parameters are incremented by the following
amounts:
Midpoint Ellipse Algorithm
➔Region 2 : Over region 2, we sample at unit intervals in
the negative y direction, and the midpoint is now taken
between horizontal pixels at each step.
➔The next decision parameter is :

➔with xk+1 set either to xk or to xk + 1, depending on the


sign of p2k .
Midpoint Ellipse Algorithm
➔Region 1
➔ If p1k < 0, the midpoint is inside the ellipse and the
pixel on scan line yk is closer to the ellipse boundary.
Otherwise, the midposition is outside or on the
ellipse boundary, and we select the pixel on scan
line yk − 1.
➔Region 2
➔ Ifp2k > 0, the midposition is outside the ellipse
boundary, and we select the pixel at x k . If p2k ≤ 0,
the midpoint is inside or on the ellipse boundary, and
we select pixel position xk+1 .
Midpoint Ellipse Algorithm
➔The 2 initial decision parameters are calculated as
follows :
Midpoint Ellipse Algorithm
Midpoint Ellipse Algorithm
Midpoint Ellipse Algorithm

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy