0% found this document useful (0 votes)
6 views22 pages

Chapter - 4

The document discusses output primitives in computer graphics, focusing on point plotting, line drawing algorithms, and circle generation methods. It details Bresenham's Line Drawing Algorithm for raster graphics, the Midpoint Circle Algorithm for drawing circles, and geometric transformations such as translation, rotation, and scaling. The document emphasizes the mathematical foundations and procedures for efficiently rendering graphics on output devices.

Uploaded by

Elshaday Abraham
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)
6 views22 pages

Chapter - 4

The document discusses output primitives in computer graphics, focusing on point plotting, line drawing algorithms, and circle generation methods. It details Bresenham's Line Drawing Algorithm for raster graphics, the Midpoint Circle Algorithm for drawing circles, and geometric transformations such as translation, rotation, and scaling. The document emphasizes the mathematical foundations and procedures for efficiently rendering graphics on output devices.

Uploaded by

Elshaday Abraham
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/ 22

UNIT IV: OUTPUT PRIMITIVES

4.1 Principles of Points and Lines:

Point plotting is accomplished by converting a single coordinate position


furnished by an application program into appropriate operations for the output
device in use.

Line drawing is accomplished by calculating intermediate positions along the line


path between two specified endpoint positions.

An output device is then directed to fill in these positions between the endpoints.

For analog devices, such as a vector pen plotter or a random-scan display, a


straight line can be drawn smoothly from one endpoint to the other
Con…
• Linearly varying horizontal and vertical deflection voltages are
generated that are proportional to the required changes in the x
and y directions to produce the smooth line.
4.1.1 Line-Drawing Algorithms:
• The Cartesian slope-intercept equation for a straight line is
y=m x+ c.
• with m representing the slope of the line and ‘c’ as they intercept.
• Given that the two endpoints of the segment are specified at positions
(x1, y1,) and (x2, y2), as shown in the Fig.

Fig 30. Line path between endpoint


Point position (x1, y1,) and (x2, y2),
4.1.2 Bresenham’s Line Drawing algorithm:
• It is an accurate and efficient raster line-generating algorithm, which is
developed by Bresenham.

As shown in Fig. 31, the vertical


axes show-scan-line positions,
and the horizontal axes identify
pixel columns. 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. Starting from the left Fig.31 Display of a straight line segment
endpoint we need to determine at
the next sample position whether
to plot the pixel at position (11,
11) or the one at (11, 12).
Cont…

• To illustrate, Bresenham’s approach, we- first consider the scan-


conversion process for lines with positive slope less than 1. Pixel
positions along a line path are then determined by sampling at unit x
intervals. Starting from the left end- point (xo, yo) of a given line, we
step to each successive column ( x position) and plot the pixel
whose scan-line y value is closest to the line path Figure 32.b
demonstrates the step in this process.
Fig. 32b Section of the screen grid showing a pixel in
column xk on scan line yk that is to be plotted along the
path of a
line segment with slope 0<m<l.
Assuming we have determined that the pixel at (xk, yk) is
to be displayed, we next need to decide which pixel to
plot in column xk +1, Our choices are the pixels at
positions (xk +l, yk ) and (xk +l, yk +l).

Fig33 Distances between pixel positions and the line y


coordinate at sampling position xk+ 1
• At sampling position xk+l, we label vertical pixel separations from
the mathematical line path as d1 ,and d2 (Fig. 33). The coordinate on the
mathematical line at pixel column position xk + l is calculated as
• (3.3)
• Then
• (3.4)
and

• (3.5)
• The difference between these two separation is evaluated by equation
(3.4) and (3.5) .
• (3.6)
• We accomplish this by substituting, , where Δy and Δx are the vertical
and horizontal separations of the endpoint positions, and defining:

• +c (3.7)
• The sign of p, is the same as the sign of d1-d2, since Δx > 0 for our
example.
• Perimeter c is constant and has the value 2Δy + Δx*(2b - l), which is
independent of pixel position and will be eliminated in the recursive
calculations for pk.
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.

• In that case, we plot the lower pixel; otherwise, we plot the upper
pixel. Coordinate changes along the line occur in unit steps in either
the x or y directions. Therefore, we can obtain the values of
successive decision parameters using incremental integer calculations.
At step k + 1, the decision parameter is evaluated from above
equation
• (3.8)
• Subtracting Equation (3.8) from (3.7) the resulting equation is 3.9
• (3.9)
• But xk = xk+1 , so that (3.10)
Bresenham's Line-Drawing Algorithm m< 1
• 1. Input the two line endpoints and store the left endpoint in (xo, yo)
• 2. Load (x0, y0) into the frame buffer; that is, plot the first point.
• 3. Calculate constants Δx, Δy, 2Δy, and 2Δy - 2Δy, and obtain the starting value for the decision parameter as
• p0 = 2Δy - ΔX
• 4. At each xk along the line, starting at k = 0, perform the following test:
• If pk < 0, the next point to plot is (xk+1 , yk) and
• pk+1= pk + 2Δy
• Otherwise, the next point to plot is (xk+1 , yk +1) and
• pk+1= pk + 2Δy -2Δx
• 5. Repeat step 4 Δx times.
• To illustrate the algorithm, we digitize the line with endpoints (20, 10) and (30, 18). This line has a slope of
0.8, with Δx=10, Δy=8.
• The initial decision parameter has the value p0=2Δy-Δx and the increments for calculating successive
decision parameters are 2Δy=16, 2Δy-2Δx=-4 .
• We plot the initial point (xo, yo) = (20, l0), and determine successive pixel positions along the line path from
the decision parameter as
Bresenham's Line-Drawing Algorithm m< 1

k pk (xk+1, yk+1 ) k pk (xk+1, yk+1 )

0 6 (21,11) 5 6 (26,15)

1 2 (22,12) 6 2 (27,16)

2 -2 (23,12) 7 -2 (28,16)

3 14 (24,13) 8 14 (29,17)

4 10 (25,14) 9 10 (30,18)
4.1.2 Line Function:
• It is used to draw a line.
• Declaration
• void far line(int x1, int y1, int x2, int y2);
• Remarks
• The functionality is to draw a line from (x1,y1) to (x2,y2). Here also the coordinates are
taking the pixel (0,0) at the top left hand corner of the screen as the origin. And also one
must note that the line formed is by using number of pixels placed near each other.
• 4.2 Circle: Since, the circle is a frequently used component in pictures and graphs, a
procedure for generating either full circles or circular arcs is included in most graphics
packages. More generally, a single procedure can be provided to display either circular or
elliptical curves.
• Properties of Circles
• A circle is defined as the set of points that are all at a given distance ‘r’ from a center
position (x, y,) (Fig. 34). This distance relationship is expressed by the Pythagorean
theorem in Cartesian coordinates as
• Midpoint Circle Algorithm:
• As in the raster line algorithm, we sample at unit intervals and determine the
closest pixel position to the specified circle path at each step. For a given
radius r and screen center position ( x , y), we can first set up our
algorithm to calculate pixel positions around a circle path centered at the
coordinate origin (0,0). Then each calculated position (x, y) is moved to its
proper screen position by adding x, to x and y, to y. 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 ith , the
other seven octants are then obtained by symmetry.
• (3.11)
{
¿0,∧𝑖𝑓 ( 𝑥,𝑦 ) 𝑖𝑠𝑖𝑛𝑠𝑖𝑑𝑒 𝑡h𝑒𝑐𝑖𝑟𝑐𝑙𝑒𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
𝑓 𝑐𝑖𝑟𝑐𝑙𝑒 ( 𝑥,𝑦 )= ¿0,∧ 𝑖𝑓 ( 𝑥 ,𝑦 ) 𝑖𝑠𝑜𝑛( 𝑡h𝑒𝑐𝑖𝑟𝑐𝑙𝑒𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
)
2
2 1 2
𝑝 𝑥 =( 𝑥 𝑘+ 1 ) + 𝑦 𝑘 − −𝑟
2

¿0𝑖𝑓 ( 𝑥,𝑦 ) 𝑖𝑠𝑜𝑢𝑡𝑠𝑖𝑑𝑒 𝑡h𝑒𝑐𝑖𝑟𝑐𝑙𝑒𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦


If pk < 0, this midpoint is inside the circle and the pixel on scan line y k is closer to
the circle boundary. Otherwise, the mid position is outside or on the circle boundary,
and we select the pixel on scan line yk -1.
Example of Midpoint Circle-Drawing:
• Given a circle radius r = 10, we demonstrate the midpoint circle
algorithm by determining positions along the circle octant in the first
quadrant hum x = 0 to x = y. The initial value of the decision
parameter is

• For the circle centered on the coordinate origin, the initial point
is (xo, yo) = (0, 0), and initial increment terms for calculating the
decision parameters are
4.3 Two-dimensional geometric transformation
• Here we discuss general procedures for applying translation,
rotation, and scaling parameters to reposition and resize two-
dimensional objects.
• Transformation equations can be expressed in a more convenient
matrix formulation that allows efficient combination of object
transformations.

• This allows us to write the two-dimensional translation equations in
the matrix form:
• P’=P+T
4.3.1 Translation
Translation is of a rigid-body transformation that moves objects without
deformation. That is, every point on the object is translated by the same
amount. A straight Line segment is translated by applying the
transformation equation P’=P+T to each of the line end points and
redrawing the line between the new endpoint positions
4.3.2 Rotation
A two-dimensional rotation is applied to an object by repositioning it along a circular path in
the xy plane.
To, generate a rotation, we specify a rotation angle θ and the position (x1, y1,) of the
rotation point (or pivot point) about which the object is to be rotated

Fig. 39 Rotation of an object through angle θ about the pivot


point (x,, y,).
4.3.3 Scaling
• A scaling transformation alters the size of an object. This operation can
be carried out for polygons by multiplying the coordinate values ( x , y)
of each vertex by scaling factors Sx, and Sy, to produce the transformed
coordinates (x', y'):

• Scaling factor Sx, scales objects in the x direction, while Sy scales in the y
direction. The transformation equations can also be written in the matrix
form:
• (3.20)
• P’=P*S (3.21)
• where S is the 2 by 2 scaling matrix,
Cont.….
• Any positive numeric values can be assigned to the scaling factors Sx,
and Sy. Values less than 1 reduce the size of objects; values greater than
1 produce an enlargement. Specifying a value of 1 for both Sx, and Sy,
leaves the size of objects unchanged. When s, and s, are assigned the
same value, a uniform scaling is produced that maintains relative object
proportions. Unequal values for Sx, and Sy, result in a differential scaling
that is often used in design applications, where pictures are constructed
from a few basic shapes that can be adjusted by scaling and positioning
transformations
Cont.…
• Matrix representations and homogeneous coordinates
• We can combine the multiplicative and translational terms for two-
dimensional geometric transformations into a single matrix
representation by expanding the 2 by 2 matrix representations to 3
by 3 matrices.
• For translation. we have:
• or
• Similarly, rotation transformation relative to the coordinate origin

You might also like