What Is Computer Graphics?
What Is Computer Graphics?
Chapter 1
1. What is computer graphics?
Ans: Computer graphics means drawing pictures on a computer screen. Computer graphics are
pictures and films created using computers. Usually, the term refers to computer-generated image
data created with help from specialized graphical hardware and software. It is a vast and recent area
in computer science.
Algorithms for displaying straight lines are based on the line equation 3-1 and the calculations given in Eqs.
3-2 and 3-3. For any given x interval ∆x along a line, we can compute the corresponding y interval ∆y from
Eq. 3-2 as
These equations form the basis for determining deflection voltages in analog devices.
Digital differential analyzer (DDA): The digital differential analyzer (DDA) is a scan-conversion line
algorithm based on calculating either ∆y or ∆x, using Eq. 3-4 or Eq. 3-5. We sample the line at unit intervals
in one coordinate and determine corresponding integer values nearest the line path for the other coordinate.
Consider first a line with positive slope, as shown in Fig. 3-3. If the slope is less than or equal to 1, we
sample at unit x intervals (∆x = 1) and compute each successive y value as
Subscript k takes integer values starting from 1, for the first point, and increases by 1 until the final endpoint
is reached. Since m can be any real number between 0 and 1, the calculated y values must be rounded to the
nearest integer. For lines with a positive slope greater than 1, we reverse the roles of x and y. That is, we
sample at unity intervals (∆y = 1) and calculate each succeeding x value as
Equations 3-6 and 3-7 are based on the assumption that lines are to be processed from the left endpoint to
the right endpoint (Fig. 3-3).
Bresenham's algorithm for |M|<1:
(a) Input the two line endpoints and store the left endpoint in (x0, y0).
(b) Load (x0, y0) into the frame buffer; that is, plot the first point.
(c) Calculate constants ∆x, ∆y, 2∆y and 2∆y - 2∆x, and obtain the starting value for the decision
parameter as
(d) At each xk along the line, starting at k = 0, perform the following test: If p k < 0, the next point
to plot is (xk + 1, yk) and
Circle: - 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.
Cell Array: - The cell array is a primitive that allows users to display an arbitrary shape defined by as a
two-dimensional grid pattern. A predefined matrix of color values is mapped by this function onto a
specified rectangular coordinate region. The PHIGS version of this function is
cellArray (wcPoints, n, m, colorArray)
Properties of circle:
(a) Circles having equal radii are congruent.
(b) Circles having different radii are similar.
(c) The central angle which intercepts an arc is the double of any inscribed angle that intercepts the same
arc (proof).
(d) The radius perpendicular to a chord bisects the chord.
(e) The chords equidistant from the center are equal in length.
(f) A tangent to a circle is at a right angle to the radius at the point of contact.
(g) Two tangents drawn on a circle from a point outside are equal in length.
(h) The angle subtended at the center of a circle by its circumference is equal to four right angles.
(i) The circumference of two different circles is proportional to their corresponding radii.
(j) Arcs of the same circle are proportional to their corresponding angles.
(k) Radii of the same circle or equal circles are equal.
(l) Equal chords have equal circumferences.
(m)The diameter of a circle is the longest chord.
(n) Equal circles have equal circumferences.
Mid-point circle algorithm:
(a) Input radius r and circle center (xc, yc), and obtain the first point on the circumference of a circle
centered on the origin as
(x0, y0) = (0, r)
(b) Calculate the initial value of the decision parameter as
(c) At each xk position, starting at k = 0, perform the following test: If P k < 0, the next point along the
circle centered on (0, 0) is (xk+1, yk) and
A boundary-fill procedure accepts as input the coordinates of an interior point (x, y), a fill color, and a
boundary color. Starting from (x, y), the procedure tests neighboring positions to determine whether they are
of the boundary color. If not, they are painted with the fill color, and their neighbors are tested. This process
continues until all pixels up to the boundary color for the area have been tested. Both inner and outer
boundaries can be set up to specify an area, and some examples of defining regions for boundary fill are
shown in figure.
Figure shows two methods for proceeding to neighboring pixels from the current test position. In Figure four
neighboring points are tested. These are the pixel positions that are right, left, above, and below the current
pixel. Areas filled by this method are called 4-connected. The second method, shown in Fig. 3-43(b), is used
to fill more complex figures. Here the set of neighboring positions to be tested includes the four diagonal
pixels. Fill methods using this approach are called 8-connected.
Four connected with figure: In figure four neighboring points are tested. These are the pixel positions that
are right, left, above, and below the current pixel. Areas filled by this method are called 4-connected.
Eight connected with figure: Shown in figure is used to fill more complex figures. Here the set of
neighboring positions to be tested includes the four diagonal pixels. Fill methods using this approach are
called 8-connected.
Chapter- 5
Transformation: Transformations are one of the primary vehicles used in computer graphics to manipulate
objects in three-dimensional space. Their development is motivated by the process of converting coordinates
between frames, which results in the generation of a 4 x 4 matrix. We can generalize this process and
develop matrices that implement various transformations in space.
A translation is applied to an object by repositioning it along a straight-line path from one coordinate
location to another. We translate a two-dimensional point by adding translation distances, t x and ty, to the
original coordinate position (x, y) to move the point to a new position (x', y') (Fig. 5-1).
x' = x + tx, y' = y + ty ( 5 - 1)
The translation distance pair (tx,ty) is called a translation vector or shift vector. We can express the
translation equations 5-1 as a single matrix equation by using column vectors to represent coordinate
positions and the translation vector:
This allows us to write the two-dimensional translation equations in the matrix form:
P' = P + T (5 - 3)
We first determine the transformation equations for rotation of a point position P when the pivot point is at
the coordinate origin. The angular and coordinate relationships of
The original and transformed point positions are shown in Fig. 5-4. In this figure, r is the constant distance
of the point from the origin, angle ∅ is the original angular position of the point from the horizontal, and θ is
the rotation angle. Using standard trigonometric identities, we can express the trans-formed coordinates in
terms of angles θ and ∅ as
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 s x and sy to produce the
transformed coordinates (x', y')
Scaling factor s2, scales objects in the x direction, while sy scales in the y direction, The transformation
equations 5-10 can also be written in the matrix form:
Or
General pivot point rotation: We can generate rotations about any selected pivot point ( x r , y r) by
performing the following sequence of translate-rotate-translate operations:
(a) Translate the object so that the pivot-point position is moved to the coordinate origin.
(b) Rotate the object about the coordinate origin.
(c) Translate the object so that the pivot point is returned to its original position.
General fixed point scaling: Figure illustrates a transformation sequence to produce scaling with respect to
a selected fixed position (xf, yf) using a scaling function that can only scale relative to the coordinate origin.
(a) Translate object so that the fixed point coincides with the coordinate origin.
(b) Scale the object with respect to the coordinate origin.
(c) Use the inverse translation of step 1 to return the object to its original position.
Reflection: A reflection is a transformation that produces a mirror image of an object. The mirror image for
a two-dimensional reflection is generated relative to an axis of reflection by rotating the object 180° about
the reflection axis. We can choose an axis of reflection in the xy plane or perpendicular to the xy plane.
When the re-flection axis is a line in the xy plane, the rotation path about this axis is in a plane perpendicular
to the xy plane. For reflection axes that are perpendicular to the xy plane, the rotation path is in the xy plane.
Following are examples of some com-mon reflections. Reflection about the line y = 0, the x axis, is
accomplished with the transformation matrix
Shear: A transformation that distorts the shape of an object such that the transformed shape appears as if the
object were composed of internal layers that had been caused to slide over each other is called a shear. Two
common shearing transformations are those that shift coordinate x values and those that shift y values. An x-
direction shear relative to the x axis is produced with the transformation matrix
Figure illustrates a translational sweep. The periodic spline curve in Fig. 10-53(a) defines the object cross
section. We then perform a translational
Sweep by moving the control points P0 through P3 a set distance along a straight-line path perpendicular to
the plane of the cross section. At intervals along this path, we replicate the cross-sectional shape and draw a
set of connecting lines in the direction of the sweep to obtain the wireframe representation shown in figure.
with Dpk and Dpk+1 specifying the values for the parametric derivatives (slope of the curve) at control points
pk and pk+1, respectively.
We can write the vector equivalent of Eqs. 10-26 for this Hermite-curve section as
P ( u )=u3 u2 u1 ¿ (3)
[ ] [ ][ ] P k +1
DP k
DP k +1
=1 1
0 0
3
a 0 0 0 1
−1 Pk
[][ ] [ ]
b
c
d
=
1 1
0 0
3 2
1
1
1
1
0
0
P
⋅ k +1
DP k
DP k +1
Pk
[ ]
−1
0 0 0 1
P
=M H⋅ k +1
DP k
[ ]
DP k +1
Where,
M H=
1
0
3
1
0
2
1
1
1
1
0
0 (6)
Where MH, the Hermite matrix, is the inverse of the boundary constraint matrix. Equation 10-29 can thus be
written in terms of the boundary conditions as
Pk
P(u)=[ u3 u 2
P
[ ]
u 1 ]⋅M H⋅ k +1
DP k
DP k +1
Finally, we can determine expressions for the Hermite blending functions by carrying out the matrix
(7)