Documente Academic
Documente Profesional
Documente Cultură
2D TRANSFORMATIONS
Unit-03/Lecture-01
BASIC TRANSFORMATIONS
Changes in orientation, size, and shape are accomplished with geometric transformations that
alter the coordinate descriptions of objects. The basic geometric transformations are
translation, rotation, and scaling. Other transformations that are often applied to objects
include reflection and shear.
TRANSLATION
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, tx and ty, to the original coordinate position (x, y) to move the point to a new position
(x', y').
x' = x + tx , y' = y + ty
The translation distance pair (tx, ty) is called a translation vector or shift vector.
We can express the translation equations 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
Sometimes matrix-transformation equations are expressed in terms of coordinate row vectors
instead of column vectors. In this case, we would write the matrix representations as P = [x y]
and T = [tx ty].
Translation is a rigid-body transformation that moves objects without deformation, i.e., every
point on the object is translated by the same amount.
Polygons are translated by adding the translation vector to the coordinate position of each
vertex and regenerating the polygon using the new set of vertex coordinates and the current
attribute settings.
Similar methods are used to translate curved objects. To change the position of a circle or
ellipse, we translate the center coordinates and redraw the figure in the new location. We
translate other curves (splines) by displacing the coordinate positions defining the objects, and
then we reconstruct the curve paths using the translated coordinate points.
we dont take any liability for the notes correctness. http://www.rgpvonline.com
1
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'):
x’ = x∙ s x , y’ = y ∙ s y
Scaling factor sx, scales objects in the x direction, while sy scales in the y direction. The
transformation equations can be written in the matrix form as,
We can control the location of a scaled object by choosing a position, called the fixed point that
is to remain unchanged after the scaling transformation.
Coordinates for the fixed point (xf , yf) can be chosen as one of the vertices, the object centroid,
or any other position. A polygon is then scaled relative to the fixed point by scaling the distance
from each vertex to the fixed point. For a vertex with coordinates (x, y), the scaled coordinates
(x', y') are calculated as,
We can rewrite these scaling transformations to separate the multiplicative and additive terms:
In this figure, r is the constant distance of the point from the origin, angle is the original angular
Using standard trigonometric identities, we can express the transformed coordinates in terms of
angles
P’= R∙P
Thus, a general homogeneous coordinate representation can also be written as (h.x, h.y, h). For
two-dimensional geometric transformations, we can choose the homogeneous parameter h to
be any nonzero value. A convenient choice is simply to set h = 1.
Each two-dimensional position is then represented with homogeneous coordinates (x, y, 1).
The term homogeneous coordinates is used in mathematics to refer to the effect of this
representation on Cartesian equations.
When a Cartesian point (x, y) is converted to a homogeneous representation (xh, yh, h)
equations containing x and y such as f (x, y) = 0, become homogeneous equations in the three
parameters xh, yh and h.
Expressing positions in homogeneous coordinates allows us to represent all geometric
transformation equations as matrix multiplications. Coordinates are represented with three-
element column vectors, and transformation operations are written as 3 by 3 matrices.
For Translation,
we have
P ' = R ( ) . P
-
A Scaling Transformation relative to the coordinate origin is now expressed as the matrix
multiplication
COMPOSITE TRANSFORMATIONS
With the matrix representations, 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. Forming products 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, i.e., each successive transformation matrix
premultiplies the product of the preceding transformation matrices.
Translations:
If two successive translation vectors (tx1, ty1) and (tx2, ty2) are applied to a coordinate position
P, the final transformed location P' is calculated as
P' = T (tx2, ty2) . {T (tx1, ty1) . P}
= {T (tx2, ty2) . T (tx1, ty1)} . P}
where P and P' are represented as homogeneous-coordinate column vectors.
Also, the composite transformation matrix for this sequence of translations is
Rotations:
Two successive rotations applied to point P produce the transformed position
so that the final rotated coordinates can be calculated with the composite rotation matrix as
Scaling:
Concatenating transformation matrices for two successive scaling operations produces
the following composite scaling matrix:
or
S (sx2, sy2) . S (sx1, s) = S (sx1 . sx2 , sy1 . sy2)
The resulting matrix in this case indicates that successive scaling operations are
multiplicative.
1. Translate the object so that the pivot-point position is moved to the coordinate origin.
2. Rotate the object about the coordinate origin.
3. Translate the object so that the pivot point is returned to its original position.
This transformation sequence is illustrated in the following diagram. The composite
transformation matrix for this sequence is obtained with the concatenation.
1. Translate object so that the fixed point coincides with the coordinate origin.
2. Scale the object with respect to the coordinate origin.
3. Use the inverse translation of step 1 to return the object to its original position.
Concatenating the matrices for these three operations produces the required scaling matrix
x-Reflection:
Reflection about the line y = 0, the x axis, is accomplished with the transformation Matrix
This transformation keeps x values the same, but "flips" the y values of coordinate positions.
The resulting orientation of an object after it has been reflected about the x axis is shown in the
diagram.
y-Reflection:
A reflection about the y axis flips x coordinates while keeping y coordinates the same. The matrix
for this transformation is,
The diagram illustrates the change in position of an object that has been reflected about the line
x = 0.
Origin-Reflection:
We flip both the x and y coordinates of a point by reflecting relative to an axis that is perpendicular
to the xy plane and that passes through the coordinate origin.
This transformation, referred to as a reflection relative to the coordinate origin, has the matrix
we dont take any liability for the notes correctness. http://www.rgpvonline.com
10
representation:
If we chose the reflection axis as the diagonal line y = x, the reflection matrix is
To obtain a transformation matrix for reflection about the diagonal y = - x, we could concatenate
matrices for the transformation sequence:
Reflections about any line y = mx + h in the xy plane can be accomplished with a combination of
translate-rotate-reflect transformations.
we dont take any liability for the notes correctness. http://www.rgpvonline.com
11
Shear:
A transformation that distorts (deform or alter) 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.
x-Shearing:
An x-direction shear relative to the x axis is produced with the transformation matrix
y-Shearing:
A y-direction shear relative to the line x = xref is generated with the transformation matrix
By changing the position of the viewport, we can view objects at different positions on the display
area of an output device. Also, by varying the size of viewports, we can change the size and
proportions of displayed objects. We achieve zooming effects by successively mapping different-sized
windows on a fixed-size viewport.
we dont take any liability for the notes correctness. http://www.rgpvonline.com
14
Panning effects are produced by moving a fixed-size window across the various objects in a scene.
When all coordinate transformations are completed, viewport clipping can be performed in
normalized coordinates or in device coordinates. This allows us to reduce computations by
concatenating the various transformation matrices.
where T is the translation matrix that takes the viewing origin point Po to the world origin, and R is the
rotation matrix that aligns the axes of the two reference frames.
A viewing-coordinate frame is moved into coincidence with the world frame in two steps:
(a) translate the viewing origin to the world origin, then
(b) rotate to align the axes of the two systems.
The Equations can also be derived with a set of transformations that converts the window area into
the viewport area.
This conversion is performed with the following sequence of transformations:
1. Perform a scaling transformation using a fixed-point position of (xwmin, ywmin) that scales the
window area to the size of the viewport.
2. Translate the scaled window area to the position of the viewport.
Relative proportions of objects are maintained if the scaling factors are the same (sx = sy). Otherwise,
world objects will be stretched or contracted in either the x or y direction when displayed on the
output device.
The mapping, called the workstation transformation, is accomplished by selecting a window area in
normalized space and a viewport area in the coordinates of the display device.
1. Parallel Projection - Here the coordinate positions are transformed to the view plane along
parallel lines. Parallel projection of an object to the view plane
2. Perspective Projection – Here, object positions are transformed to the view plane along lines
that converge to a point called the projection reference point.
Parallel Projections
Parallel projections are specified with a projection vector that defines the direction for the
projection lines.When the projection in perpendicular to the view plane, it is said to be an
Orthographic parallel projection, otherwise it said to be an Oblique. Orientation of the
projection vector Vp to produce an orthographic projection.
Parallel projections have lines of projection that are parallel both in reality and in the
projection plane. Parallel projection corresponds to a perspective projection with an infinite
focal length (the distance from the image plane to the projection point), or "zoom”. Within
parallel projection there is an ancillary category known as "pictorials". Pictorials show an image
of an object as viewed from a skew direction in order to reveal all three directions (axes) of
space in one picture. Because pictorial projections innately contain this distortion, in the rote,
drawing instrument for pictorials, some liberties may be taken for economy of effort and best
effect.
Orthographic projection
Oblique projection
Cavalier projection
Cabinet projection
Axonometric projection
Axonometric projection is a type of orthographic projection where the plane or axis of the
object depicted is not parallel to the projection plane such that multiple sides of an object are
visible in the same image. It is further subdivided into three groups: isometric, dimetric and
trimetric projection, depending on the exact angle at which the view deviates from the
orthogonal. A typical characteristic of axonometric pictorials is that one axis of space is usually
displayed as vertical.
Isometric projection
In isometric pictorials (for protocols see isometric projection), the most common form of
axonometric projection, the direction of viewing is such that the three axes of space appear
equally foreshortened. There are two commonly used standards for creating scaled isometric
drawings. An accurate drawing of a three-dimensional object projected isometrically would
have its axis-parallel edges foreshortened by a factor of approx 81.65\%, but for convenience
this is usually approximated as 3/4. That is, the length of an edge on a drawing of this type
would be 3/4 of its length on a three-dimensional object. Alternatively, "full-size" isometric
we dont take any liability for the notes correctness. http://www.rgpvonline.com
19
drawings may be made in which no foreshortening is shown: the length of an edge on a
drawing is the same as its three-dimensional length.
Dimetric projection
In dimetric pictorials (for protocols see dimetric projection), the direction of viewing is such
that two of the three axes of space appear equally foreshortened, of which the attendant scale
and angles of presentation are determined according to the angle of viewing; the scale of the
third direction (vertical) is determined separately. Approximations are common in dimetric
drawings.
Trimetric projection
In trimetric pictorials (for protocols see trimetric projection), the direction of viewing is such
that all of the three axes of space appear unequally foreshortened. The scale along each of the
three axes and the angles among them are determined separately as dictated by the angle of
viewing. Approximations in trimetric drawings are common, and trimetric perspective is
seldom used.
Oblique projection
In oblique projections the parallel projection rays are not perpendicular to the viewing plane as
with orthographic projection, but strike the projection plane at an angle other than ninety
degrees. In both orthographic and oblique projection, parallel lines in space appear parallel on
the projected image. Because of its simplicity, oblique projection is used exclusively for pictorial
purposes rather than for formal, working drawings. In an oblique pictorial drawing, the
displayed angles among the axes as well as the foreshortening factors (scale) are arbitrary. The
distortion created thereby is usually attenuated by aligning one plane of the imaged object to
be parallel with the plane of projection thereby creating a true shape, full-size image of the
chosen plane. Special types of oblique projections are cavalier projection and cabinet
projection.
PERSPECTIVE PROJECTION
Perspective foreshortening is the illusion that objects and length appear smaller as their
distance from the center of projection increases. The illusion that certain sets of parallel lines
appear to meet at a point is another feature of perspective drawings. These points
are Vanishing Points.
2. Since the region lying above and to the left of the clip rectangle, it is assigned a code of
1001. Each endpoint of the line is assigned the code of the region in which it lies. We can
now use these endpoint codes to determine whether the line segment lies completely
inside the clip rectangle or in the outside halfplane of the edge. If both 4-bit codes of the
endpoints are 0, then the line lies completely inside the clip rectangle.
Example
Consider the line segment AD in the figure. Point A has outcode 0000 and point D has outcode
1001. The line can neither be accepted nor rejected. Therefore the algorithm chooses D as an
outside point , whose outcode shows that the line crosses the top edge and left edge. By our
testing order, we first use the top edge to clip AD to AB and we compute B's outcode as 0000.
In the next iteration we apply the acceptance/rejection test to AB and it is accepted and
displayed.
Line EI requires multiple iterations. The first endpoint E, has an outcode of 0100, so the
algorithm chooses it as the outside point and tests the outcode to find that the first edge
against which the line is cut is the bottom edge, where AI is clipped to FI. In the second
we dont take any liability for the notes correctness. http://www.rgpvonline.com
23
iteration FI cannot be accepted or rejected. The outcode of the first point is 0000, so the
algorithm chooses the outside point I that has outcode 1010. The first edge clipped against is
therefore the top edge, yielding FH. H's outcode is determined to be 0010, so the third
iteration results in a clip against the right edge to FG. This is accepted in fourth and final
iteration and displayed. A different sequence of clips would have resulted if we had picked I as
the initial point.
On the basis of its outcode we would have clipped against the top edge first, then the right
edge and finally the bottom edge.
Case 2: If vertex s is inside the clipping edge and vertex p is outside of it, the intersection
point, i, is output.
Case 4: If vertex p is inside of the clipping edge and vertex s is outside of it, the intersection
point, i, and vertex p are both added to the output list.
Z Buffer
The easiest way to achieve hidden-surface removal is to use the depth buffer (sometimes called
a z-buffer). A depth buffer works by associating a depth, or distance from the viewpoint, with
each pixel on the window. Initially, the depth values for all pixels are set to the largest possible
distance, and then the objects in the scene are drawn in any order.
Graphical calculations in hardware or software convert each surface that's drawn to a set of
pixels on the window where the surface will appear if it isn't obscured by something else. In
addition, the distance from the eye is computed. With depth buffering enabled, before each
pixel is drawn, a comparison is done with the depth value already stored at the pixel.
If the new pixel is closer to the eye than what's there, the new pixel's colour and depth values
replace those that are currently written into the pixel. If the new pixel's depth is greater than
what's currently there, the new pixel would be obscured, and the colour and depth information
for the incoming pixel is discarded.
Since information is discarded rather than used for drawing, hidden-surface removal can
increase your performance.
To use depth buffering in OpenGL, you need to enable depth buffering. This has to be done only
once. Each time you draw the scene, before drawing you need to clear the depth buffer and
then draw the objects in the scene in any order.
Scan-Line Algorithm
The scan-line algorithm is another image-space algorithm. It processes the image one scan-line
at a time rather than one pixel at a time. By using area coherence of the polygon, the processing
efficiency is improved over the pixel oriented method.
Using an active edge table, the scan-line algorithm keeps track of where the projection beam is
at any given time during the scan-line sweep. When it enters the projection of a polygon, an IN
flag goes on, and the beam switches from the background colour to the colour of the polygon.
After the beam leaves the polygon's edge, the colour switches back to background colour. To
this point, no depth information need be calculated at all. However, when the scan-line beam
finds itself in two or more polygons, it becomes necessary to perform a z-depth sort and select
the colour of the nearest polygon as the painting colour.
Accurate bookkeeping is very important for the scan-line algorithm. We assume the scene is
defined by at least a polygon table containing the (A, B, C, D) coefficients of the plane of each
polygon, intensity/colour information, and pointers to an edge table specifying the bounding
lines of the polygon. The edge table contains the coordinates of the two end points, pointers to
we dont take any liability for the notes correctness. http://www.rgpvonline.com
27
the polygon table to indicate which polygons the edge bounds, and the inverse slope of the x-y
projection of the line for use with scan-line algorithms. In addition to these two standard data
structures, the scan-line algorithm requires an active edge list that keeps track of which edges a
given scan line intersects during its sweep. The active edge list should be sorted in order of
increasing x at the point of intersection with the scan line. The active edge list is dynamic,
growing and shrinking as the scan line progresses down the screen.
Painter's algorithm
The idea behind the Painter's algorithm is to draw polygons far away from the eye first, followed
by drawing those that are close to the eye. Hidden surfaces will be written over in the image as
the surfaces that obscure them are drawn.
The concept is to map the objects of our scene from the world model to the screen somewhat
like an artist creating an oil painting. First she paints the entire canvas with a background colour.
Next, she adds the more distant objects such as mountains, fields, and trees. Finally, she creates
the foreground with "near" objects to complete the painting. Our approach will be identical.
First we sort the polygons according to their z-depth and then paint them to the screen, starting
with the far faces and finishing with the near faces.
The algorithm initially sorts the faces in the object into back to front order. The faces are then
scan converted in this order onto the screen. Thus a face near the front will obscure a face at
the back by overwriting it at any points where their projections overlap. This accomplishes
hidden-surface removal without any complex intersection calculations between the two
projected faces.
The algorithm is a hybrid algorithm in that it sorts in object space and does the final rendering
in image space.
The basic algorithm :
Global illumination takes into account the light that is reflected from other surfaces to the
current surface in addition to the light source. A global illumination model is more
comprehensive, more physically correct, and produces more realistic images.
Diffuse Reflection
Diffuse reflection is uniform reflection of light with no directional dependence for the viewer,
e.g., a matte surface such as cardboard. Diffuse reflection originates from a combination of
internal scattering of light, i.e. the light is absorbed and then re-emitted, and external scattering
from the rough surface of the object. An illumination model must handle both direct diffuse
reflection, i.e., light coming directly from a source to a surface and then reflected to the viewer,
and indirect diffuse reflection (or diffuse interreflections), that is light coming from a source,
we dont take any liability for the notes correctness. http://www.rgpvonline.com
29
being reflected to a surface, then reflected to another surface, etc, and finally to the viewer.
Some local illumination models, such as those that are usually used in many scan-line rendering
and ray tracing systems, handle the diffuse inter reflection contribution by simply assuming it
has uniform intensity in all directions. This constant term is called the "ambient" contribution
and it is considered a non-directional background light. Radiosity explicitly computes the diffuse
inter reflection term.
Then Lambert's law states that the reflected light is proportional to cos q (with q <= 90 else the
light is behind the surface). Let Ip="intensity" of point light source, then the brightness is f(1/d2)
where d="distance" of light source from the surface. Some models use a d distance dependence
rather than d2, and since most light sources are not really point sources, this works. Some
models define a "distant" light source, such as the sun, which have no distance
dependence. Here is more information on lights in computer graphics.
Then I = [(kd * Ip) / (D)] * (N.L) with D = the distance function (< = 1 for a distant light source, d
or d2 for other models and kd = the diffuse coefficient of reflection with: 0.0 <= kd <= 1.0. For
colored surfaces there are three kd values, one for red, green, and blue. Some models also add a
constant term do to prevent d the denominator from going to zero. Frequently ka is set to be
the same as kd. Note that the vectors N and L are always normalized.
Then including ambient light we get a simple two term illumination model:
Phong Shading overcomes some of the disadvantages of Gouraud Shading and specular
reflection can be successfully incorporated in the scheme. The first stage in the process is the
same as for the Gouraud Shading - for any polygon we evaluate the vertex normals. For each
scan line in the polygon we evaluate by linear intrepolation the normal vectors at the end of
each line. These two vectors Na and Nb are then used to interpolate Ns. we thus derive a
normal vector for each point or pixel on the polygon that is an approximation to the real normal
on the curved surface approximated by the polygon. Ns , the interpolated normal vector, is then
used in the intensity calculation. The vector interpolation tends to restore the curvature of the
original surface that has been approximated by a polygon mesh.
The algorithm is as follows:
1).Compute a normal N for each vertex of the polygon.
2).From bi-linear interpolation compute a normal, Ni for each pixel.
3).From Ni compute an intensity Ii for each pixel of the polygon.
4).Paint pixel to shade corresponding to Ii.
We have:
Gouraud shading, computes an intensity for each vertex and then interpolates the computed
intensities across the polygons. Gouraud shading performs a bi-linear interpolation of the
intensities down and then across scan lines. It thus eliminates the sharp changes at polygon
boundaries.
The algorithm is as follows:
1).Compute a normal N for each vertex of the polygon.
2).From N compute an intensity I for each vertex of the polygon.
3).From bi-linear interpolation compute an intensity Ii for each pixel.
4).Paint pixel to shade corresponding to Ii.
Mathematically, x and y are projective coordinates and the colors of the chromaticity diagram
occupy a region of the real projective plane. Because the CIE sensitivity curves have equal areas
under the curves, light with a flat energy spectrum corresponds to the point (x,y) =
(0.333,0.333).
The values for X, Y, and Z are obtained by integrating the product of the spectrum of a light
beam and the published color-matching functions.
Le
n ,
, , .
This stands for cyan-magenta-yellow and is used for hardcopy devices. In contrast to color on
the monitor, the color in printing acts subtractive and not additive. A printed color that looks
red absorbs the other two components and and reflects . Thus its (internal) color is
G+B=CYAN. Similarly R+B=MAGENTA and R+G=YELLOW. Thus the C-M-Y coordinates are just the
complements of the R-G-B coordinates:
values of (0,1,1). Note that absorbs , similarly absorbs and hence absorbs
all but .
Black ( )
corresponds to
which should in principle absorb , and . But in practice this will appear as some dark
gray. So in order to be able to produce better contrast printers often use black as color. This
is the CMYK-model. Its coordinates are obtained from that of the CMY-model by
, , .
This is used for color TV. Here is the luminance (the only component necessary for B&W-TV).
The conversion from RGB to YIQ is given by
All color models treated so far are hardware oriented. The Hue-Saturation-Value model is
oriented towards the user/artist. The allowed coordinates fill a six sided pyramid the 3 top faces
of the color cube as base. Note that at the same height colors of different perceived brightness
are positioned. Value is given by the height, saturation is coded in the distance from the axes
and hue by the position on the boundary.