You are on page 1of 34

Chapter Four

2-D and 3-D Graphics


2-D Graphics
Contents
Introduction
Representation of Point and Object
Translation, Rotation, Scaling and Reflection
Homogeneous Coordinates and Combination of Transformation
Composite Transformation
Transformation of Coordinate System
Introduction
The graphics packages range from the simple Windows Paint to the
specialized AutoCAD and ANSYS.
They all have the facility to change the shape or size or position or
orientation of the displayed objects.
Animations are produced by resizing an object or moving the object
or camera along the animation path.
All these concerns operate upon the object geometry by applying
various geometric transformations like translation, rotation, and
scaling.
Introduction …
Each of these transformations is represented by specific
transformation matrices, the nature and origin of which are
demonstrated in this unit.
The 2D point object is considered as representative of any graphic
object.
Representation of point and object
A points coordinates can be expressed as elements of a matrix.
Two matrix formats are used:
1. one is row matrix and
2. other is column matrix format.
For a 2D point (x, y) the row matrix format is a 1-row, 2-column
matrix [x y].
For a 3D point (x, y, z) it is a 1-row, 3-column matrix [x y z].
Representation of point and object …
The same points in the column matrix format can be expressed as 1-
column, 2-row matrix, and 1-column 3-row matrix respectively.
Here, we will follow column matrix convention.
As all graphic objects are built with finite no. of points each such
object can be uniquely represented by an optimum no. of definition
points lying on the object.
Though there may be thousands of different adjacent points on a line
between its two end points, this particular line segment can be
uniquely expressed by the end points only.
Representation of point and object …
For example, in column matrix format, may represent one and
only one line between points (1, 2) and (3, 4).
A closer look at the line will reveal that it is basically a series of
adjacent points, maintaining the straight-line connectivity between
the definition points (1, 2) & (3, 4). Similarly, the arc segment ‘C’ is
uniquely represented by 3 points (1, 1) – (5, 2) – (6, 4) in column-
matrix format
Representation of point and object …
Representation of point and object …
Representation of point and object …
A triangle having vertices at (1, 1, 1), (3, 5, 5) and (5, 4, 6) in 3D space
in picture on previous slide can be represented uniquely by:
A 5 × 3 2D rectangle having its lower left vertex at (1, 1) in picture on
previous slide can be represented by:
The rectangular parallelopiped ABCDEFGH in 3D space in picture on
previous slide may be defined by the matrix:
Representation of point and object …
Translation
Translation is repositioning an object along a straight-line path (the
translation distances) from one coordinate location to another.
Moving an object is called a translation.
We translate an object by translating each vertex in the object.
x’ = x + tx; y’ = y + ty; Assume you are given a point at (x, y,)=(2, 1).
 Where will the point be if you move it 3 units to the right and 1 unit up
directions?
The translating distance pair( tx, ty) is called a translation vector or shift
vector.
Translation …
The translation vector in matrix format for 2D is as follows:
x’ = x + tx;
y’ = y + ty
Rotation
In 2-D, a rotation is prescribed by an angle θ & a center of rotation P.
But in 3-D rotations require the prescription of an angle of rotation &
an axis of rotation.
Unlike translation rotation brings about changes in position as well as
orientation.
The point about which an object is rotated is called pivot point or
rotation point.
Rotation …
X’ = xcos(u) – ysin(u)
Y’= xsin(u) + ycos(u)
Scaling
Changing the size of an object is called Scaling.
The scale factor s determines whether the scaling is a magnification, s
> 1, or a reduction, s < 1.
If sx=sy=sy we call uniform scaling.
Scaling with respect to the origin, where the origin remains fixed:
X’ = x.sx
Y’ = y.sy
Homogenous Coordinates
In general, when you want to perform a complex transformation, you
usually make it by combining a number of basic transformations.
Scaling is done by matrix multiplication and translation is done by
vector addition.
In order to represent all transformations in the same form, computer
scientists have devised what are called homogeneous coordinates.
Do not try to apply any exotic interpretation to them.
They are simply a mathematical trick to make the representation be
more consistent and easier to use.
Homogenous Coordinates …
Homogeneous coordinates (HC) add an extra virtual dimension.
Thus 2D HC are actually 3D and 3D HC are 4D.
Consider a 2D point p = (x, y).
 In HC, we represent p as p = (x, y, 1).
An extra coordinate is added whose value is always 1.
This may seem odd but it allows us to now represent translations as
matrix multiplication instead of as vector addition.
Homogenous Coordinates …
2D transformation in homogeneous coordinates will be 3D:
Composite Transformation
With the matrix representations of the previous section, we can set
up a matrix for any sequence of transformations as a composite
transformation matrix by calculating the matrix product of the
individual transformations.
A Forming product of transformation matrices is often referred to as a
concatenation, or composition, of matrices.
For column-matrix representation of coordinate positions, we form
composite transformations by multiplying matrices in order from right
to left.
Composite Transformation …
That is, each successive transformation matrix pre multiplies the
product of the preceding transformation matrices. If we want to apply a
series of transformations T1, T2, and T3 to a set of points, we can do it
in two ways:
1. We can calculate P'=T1*P, P''=T2*P', P'''=T3*P‘’.
2. Calculate T=T1*T2*T3, then P'''=T*P.
Method 2 saves large number of addition and multiplications
(Computational time) needs approximately of 1/3 of as many
operations, therefore we concatenate or compose the matrix into one
final transformation matrix, the applying it to the points.
3-D Graphics
Contents
Introduction
Translation, Rotation, Scaling and Reflection
Homogeneous Coordinates
Composite Transformation
Introduction
For a graphics programmer the real challenge is to image a 3D object in a 2D
display plane with realistic effect.
It is the third dimension or depth of objects that needs to be handled properly
to produce the desired effect.
This is achieved by a suitable combination of 3D geometric transformation
and 3D viewing transformation where projection plays the key role.
3D geometric transformation is just an extension of the 2D transformation.
Though the basic transformation mathematics is easily understandable the
important aspect in 3D transformation is proper visualization of object
movement in space.
Introduction …
Even the object may remain stationary and the viewer’s point of view
might change.
All these factors taken together 3D graphics packages are developed
that model’s real-life 3D objects and allow the user to move, resize or
reorient them or even dynamically updates the object’s views while
simulating user’s movement within the scene.
This unit addresses the cases and mathematics behind the
transformation of geometry and projected views of objects from a 3D
perspective.
Introduction …
In the previous unit we confined our discussion to two-dimensional (zero
thickness) graphic objects only.
The present unit is an extension of the previous one in the sense that it now takes
z coordinates into consideration apart from the x, y and homogeneous coordinates
while the basic approach for representing and manipulating objects remains same.
As done in case of 2D we express 3D object transformation in matrix form and any
sequence of transformations is represented as a single matrix formed by
concatenating the matrices for individual transformations in the same sequence.
However, this chapter takes us closer to reality, because real objects are all three
dimensional.
Translation
In a three-dimensional homogeneous coordinate representation, a
point is translated from position P = (x, y, z) to position P' = (x', y', z')
with the matrix operation.

Parameters tx, ty, and tz, specifying translation distances for the
coordinate directions x, y, and z, are assigned any real values.
Translation …
The above matrix representation in is equivalent to the three equations x'=x
+ tx; y'=y + ty; z'=z + tz;
An object is translated in three dimensions by transforming each of the
defining points of the object.
For an object represented as a set of polygon surfaces, we translate each
vertex of each surface and redraw the polygon facets in the new position.
We obtain the inverse of the translation matrix by negating the translation
distances tx, ty, and tz.
This produces a translation in the opposite direction, and the product of a
translation matrix and its inverse produces the identity matrix.
Rotation
To generate a rotation transformation for an object, we must designate
an axis of rotation (about which the object is to be rotated) and the
amount of angular rotation.
Unlike two-dimensional applications, where all transformations are
carried out in the xy plane, a three-dimensional rotation can be
specified around any line in space.
The easiest rotation axes to handle are those that are parallel to the
coordinate axes.
Also, we can use combinations of coordinate axis rotations (along with
appropriate translations) to specify any general rotation.
Rotation …
By convention, positive rotation angles produce counterclockwise
rotations about a coordinate axis, if we are looking along the positive
ha=lf of the axis to-ward the coordinate origin.
Scaling
The matrix expression tor the scaling transformation of a position P =
(x, y, z) relative to the coordinate origin can be written as:
Where scaling parameters sx, sy, and sz, are assigned any positive
values.
Explicit expressions for the coordinate transformations for scaling
relative to the origin are:
z' = z.Sz;
x' = x.Sx;
y' = y.Sy;
Scaling …
THE END

Any questions

You might also like