Chapter - 4
Chapter - 4
An output device is then directed to fill in these positions between the endpoints.
• (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
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
• 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
• 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