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

Unit Ii

The document discusses computer graphics output primitives and scan conversion algorithms. It defines output primitives as basic geometric structures like points, lines, and polygons used to describe scenes. Scan conversion is the process of representing continuous graphics objects as discrete pixels. Common line drawing algorithms discussed are the Digital Differential Analyzer (DDA) algorithm and Bresenham's line algorithm, which aims to improve on DDA by using only integer calculations.

Uploaded by

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

Unit Ii

The document discusses computer graphics output primitives and scan conversion algorithms. It defines output primitives as basic geometric structures like points, lines, and polygons used to describe scenes. Scan conversion is the process of representing continuous graphics objects as discrete pixels. Common line drawing algorithms discussed are the Digital Differential Analyzer (DDA) algorithm and Bresenham's line algorithm, which aims to improve on DDA by using only integer calculations.

Uploaded by

Lee Cang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 44

COMPUTER GRAPHICS

Unit 1I: Output Primitives and


their Attributes

Facilitator: Frank
Course code: CS 8205
Email: [email protected]
Tel:+255757050205
Introduction
 Shapes and colors of the objects can be
described internally with pixel arrays or with
sets of basic geometric structures, such as straight
line segments and polygon color areas.
 The scene is then displayed either by loading the
pixel arrays into the frame buffer or by scan
converting the basic geometric-structure
specifications into pixel patterns.
 Typically, graphics programming packages provide
functions to describe a scene in terms of these basic
geometric structures, referred to as output
primitives, and to group sets of output primitives
into more complex structure.
 Output primitive is the basic geometric
structures used to describe scenes.
 Each output primitive is specified with input
coordinate data and other information about
the way that object is to be displayed.
 Points and straight line segments are the
simplest geometric components of pictures.
 Additional output primitives that can be used
to construct a picture include circles and other
conic sections, quadric surfaces, spline
curves and surfaces, polygon color areas,
and character strings.
Scan conversion
 A procedure used to digitize or rasterize pixel data
available on frame buffer
 The process of representing continuous graphics
object as a collection of discrete pixels is called
scan conversion. For eg a line is defined by its two
end points and the line equation.

Scan-converting a Point
 We have already defined that a pixel is collection of
number of points. Thus it does not represent any
mathematical point.
 Suppose we wish to display a point C(5.4, 6.5). It
means that we wish to illuminate that pixel, which
contains this point C.
 What happens if we try to display C’(5.3, 6.4)?
 Well, it also corresponding to the same pixel as
that of C(5.4, 6.5).
 Thus we can say that point C(x, y) is
represented by an integer part of X and integer
part of Y. So, we can use the command as
Putpixel(int x, int y);
 We normally use right handed Cartesian
coordinate system.
 The origin in this system starts at the bottom.
 However in case of computer system, due to the
memory organization, the system turns out to
left handed Cartesian system.
Scan-converting a Straight Line
 A scan conversion of line locates the
coordinates of the pixels lie on or near an ideal
straight line impaired on 2D raster grid.
 A straight line may be defined by two endpoints
and an equation.
 The two endpoints are described by and

 The equation of the line is used to describe the


x, y coordinates of all the points that lie
between these two endpoints.
 Using the equation of a straight line, y = mx + c
where and c = y intercept.
 Here , m represents the slope of the line path
where by gives the deflection needed
towards horizontal and vertical direction to get
new pixel from the current pixel position.
 Slope of line also describe the nature and
characteristics of line that is going to display.

Line Drawing Algorithms


 The process of ‘turning on’ pixels for line
segment is called vector generation or line
generation, and the algorithm for them are
known as vector generation algorithm or line
drawing algorithm.
 Line drawing is achieved by calculating
intermediate points along a line path
between two specified end point positions.
 These intermediate points are calculated from
the equation of the line.
 The Cartesian slope-intercept equation for a
straight line is y = mx + c

Line path between endpoint positions and


where m - represents the slope of the line
c - represents the intercept at y-axis.

 Algorithms for displaying straight lines are


based on these equations and calculations.
 For any given x interval , we can
calculate corresponding y interval as
y  m.x
 Similarly, we can calculatex corresponding to
a specified y as
y
x 
m
 For lines with slope value |m| < 1, x is
increased and y calculated, whereas for slopes
|m| > 1, y is increased and x calculated.

Digital Differential Analyzer (DDA) algorithm


 The DDA algorithm is a line algorithm
based on calculating either or
 We know the Slope-Intercept Equation of line
is:
y = mx + c
 We sample the line at unit intervals in one
coordinate and determine corresponding integer
values nearest the line path for the other
coordinate.
Straight line segment with five sampling positions
along the x axis between x, and x
Case 1: Slope is positive and less than one:
 Consider the line with positive slope. If the
slope value is less than or equal to 1 then
and
x we
1 have to calculate value.y
y  mx  c
yk  m  x  1  c
In general yk  m  x  k   c
yk 1  m  x  k  1  c

Now write this equation in form


yk 1  yk  m  x  k  1  c  m  x  k   c 
 In above equation k takes integer values starting
from 1 and increase by 1 until the final
endpoints is reached.
 As m can be any real number between 0 and 1,
the calculated y must be rounded to the nearest
integer.

Case 2: Slope is positive and greater than one:


 We change the role of x and y that is sample at
unit y intervals y  1and calculate each
succeeding x value as
yc
x
m
x1 
 y  1  c 
m

  y  k   c xk 1 
  y  k  1  c 
In general x k & m
m

Now write this equation in form


xk 1  xk 
  y  k  1  c    y  k   c  
  
m  m 
 

Above both equations are based on the


assumption that line are to be processed from
left endpoint to right endpoint .
 If we process line from right endpoint to left
endpoint then
 If x  1 equation become
yk 1  yk  m
 If y  1 equation become
1
xk 1  xk 
m
 Above calculated equations also used to
calculate pixel position along a line with
negative slope.
Algorithm:
1. Read and (First and second
coordinate of line)
2. dx = x2 – x1;
dy = y2 – y1;
3. If absolute(dx) > absolute(dy) then
s = absolute(dx)
Else
s = absolute(dy)
End if
4. xinc = dx / s
yinc = dy / s
5. x = x1;
y = y1;
6. setpixel(round(x), round(y), color)
7. For i = 1 to s
x = x + xinc
y = y + yinc
setpixel(round(x), round(y), color)
End for
8. Exit

Disadvantages:
 In DDA line drawing algorithm we have to
perform rounding of the float value and this
rounding may cause the line to change
from original pixel position.
 Also this rounding requires more time.
Along with the rounding operation it also
involves the floating-point arithmetic
operation, which also requires more time.

Examples
1. Draw a line using DDA using algorithm
i. (2,2) and (9,2)
ii. (2,5) and (2,12)
iii. (5,4) and (12,7)
iv. (5,7) and (10,5)
2. Calculate the points between the starting point
(5, 6) and ending point (8, 12).
Bresenham's Line Algorithm
 To remove the drawbacks of DDA
algorithm, Bresenham has given new line
drawing algorithm based on integer
increment/decrement in x and y value.
 Sampling at unit x intervals in these examples,
we need to decide which of two possible pixel
positions is closer to the line path at each
sample step.

Figure a Figure b
 Starting from the left endpoint shown in Fig. a,
we need to determine at the next sample
position whether to plot the pixel at position
(11, 11) or the one at (11, 12).
 Similarly, Fig. b shows-a negative slope-line
path starting from the left endpoint at pixel
position (50, 50). In this one, do we select the
next pixel position as (51,501 or as (51,49)?
 These questions are answered with Bresenham's
line algorithm by testing the sign of an integer
parameter, whose value is proportional to the
difference between the separations of the two
pixel positions from the actual line path.
 Consider the line having positive slope and
slope value is less than 1.
 First the pixel is plotted at co-ordinates
 Then the x value is always increased by 1 and
find out whether the y value is incremented by 1 or
not.
 So the next pixel position is either
 From the line equation we get the original y value
at
as under:

 As shown in figure, the distance between and


y is and distance between and y is
Bresenham Line Drawing method
The difference between these two separations is

 A decision parameter for the kth step in the


line algorithm can be obtained by rearranging
Eq above so that it involves only integer
calculations.
 We accomplish this by substituting,
where and are the vertical and horizontal
separations of the endpoint positions, and
defining:
from,

 In eq above, last three terms are constant so we


can put some constant b in place of them.
 Also we put as decision
parameter.
 As like eq. above we can find the value as
under:

 By subtracting eqns. we get:

But,
 Here from eq. above we can take the decision
whether we have to increase y value or not.
 If decision parameter p is < 0 then that
means y is more closer to so we have to
plot
 If decision parameter p is > 0 then that
means y is more closer to so we have to
plot

 Here we are calculating the decision parameter


value from previous value but for initial point we
can determine decision parameter by:
 Here we have only considered the case of positive
slope with less than or equal to 1. Similarly we
can derive the equation for the slope greater
than 1 but for that purpose the action of x and y is
interchanged.
Examples
Calculate the point between the following starting
coordinate and ending coordinate.
(1,1) and (8,5)
(9,8) and (14,22)
(20, 10) and (30, 18)
(35,40) and (43,45)
Circle-generating Algorithms
 A circle is a closed shape formed by tracing a point
that moves in a plane such that its distance from a
given point is constant.
 Important terms related to Circles
 Center: The fixed point in the circle is called
the center. So, the set of points are at a fixed
distance from the center of the circle.
 Radius: Radius is the fixed distance between
the center and the set of points. It is denoted by
“r”.
 Diameter: Diameter is a line segment, having
boundary points of circles as the endpoints and
passing through the center.
8 segments of octants for a circle:
 The shape of the circle is similar in each quadrant.
We can generate the circle section in (the second
quadrant of the xy plane by noting that the two
circle sections are symmetric with respect to the y-
axis.
 And circle sections in the third and fourth
quadrants can be obtained from sections in the first
and second quadrants by considering symmetry
about the x-axis. We can take this one step further
and note that there is also symmetry between
octants.
 Circle sections in adjacent octants within one
quadrant are symmetric with respect to the 45' line
dividing the two octants.
Midpoint Circle Algorithm
 The mid point circle algorithm is used to determine
the pixels needed for rasterizing a circle while
drawing a circle on a pixel screen.
 In this technique algorithm determines the mid
point between the next 2 possible consecutive
pixels and then checks whether the mid point in
inside or outside the circle and illuminates the pixel
accordingly.
 A circle is highly symmetrical and can be divided
into 8 Octets on graph. Lets take center of circle at
Origin i.e (0,0)
Next pixel= Next pixel=

 We have chosen octet 1 where circle is moving


forward and downwards so y can never be
increased, either it can be same or decremented.
 Similarly x will always be increasing as circle is
moving forward too.
Let m is the midpoint
 As is the next most pixel of therefore we
can write,

Midpoint =

From

The above equation is our decision parameter


 To find out our next decision parameter we need to
get

Now
 Now let us conclude the initial parameter
 For that we have to choose coordinate of starting
point (0,r) put this in (i)
If pk<0 that means midpoint is inside the circle

Now put coordinate in (ii)

If pk>0 that means midpoint is outside the circle


Example
1. Given a circle radius = 10, determine the circle
octant in the first quadrant from x=0 to x=y.
2. Given a circle radius = 8, determine the circle
octant in the first quadrant from x=0 to x=y.
ELLIPSE-GENERATING ALGORITHMS
 An ellipse is an elongated circle.
 An ellipse is defined as the set of points such that
the sum of the distances from two fixed
positions(foci) is same for all points.
 We can say ellipse is in standard position if their
major and minor axes are parallel to x-axis and y-
axis as shown in figure below.
 It is important to note that while processing first
quadrant we have to take steps in the x direction
where the slope of the curve has a magnitude less
than 1(for region 1) and to take steps in the y
direction where the slope has a magnitude greater
than 1 (for region 2).
Mid-point Ellipse algorithms
 Midpoint ellipse algorithm is a method for drawing
ellipse in computer graphics.
 This method is modified from bresenham’s
algorithm
 Given parameters rx , ry and we determine
points so that ( x , y) for an ellipse in standard
position centered on the origin, and then we shift
the points so the ellipse is centered at
 In this method we divide first quadrant into two
parts according to the slope of an ellipse as shown
in the figure above.

fellipse  x, y   ry2 x 2  rx2 y 2  ry2rx2


 Which have the following properties

 The ellipse slope is calculated using following


equation 2
dy 2ry x
 2
dx 2rx y
 At boundary between region 1 and 2 slope = -1 and
equation
2r x  2r y
y
2
x
2
GOODBYE

frank

You might also like