cit 416 - bowen universityby the following transformation matrix m wc,vc =rt where t is the...
TRANSCRIPT
1
CIT 416
LECTURE NOTE
COMPILED BY DR. A.O. AKINWUNMI
2
Module Two
Unit One: Two Dimensional Transformations
In many applications, changes in orientations, size, and shape are accomplished with geometric
transformations that alter the coordinate descriptions of objects.
The basic geometric transformations are:
Translation
Rotation
Scaling
Other forms of transformations are:
Reflection
Shear
Basic Transformations
Translation
We translate a 2D point by adding translation distances, tx and ty, to the original coordinate position
(x,y):
x' = x + tx, y' = y + ty
Alternatively, translation can also be specified by the following transformation matrix:
Then we can re-express the formula as:
For example, to translate a triangle with vertices at original coordinates (10,20), (10,10), (20,10) by tx=5,
ty=10, we compute as followings:
Translation of vertex (10,20):
Translation of vertex (10,10):
3
Translation of vertex (20,10):
The resultant coordinates of the triangle vertices are (15,30), (15,20), and (25,20) respectively.
Exercise: translate a triangle with vertices at original coordinates (10,25), (5,10), (20,10) by tx=15,
ty=5. Roughly plot the original and resultant triangles.
Rotation About the Origin
To rotate an object about the origin (0,0), we specify the rotation angle ?. Positive and negative values
for the rotation angle define counterclockwise and clockwise rotations respectively. The followings is
the computation of this rotation for a point:
x' = x cos ? - y sin ?
y' = x sin ? + y cos ?
Alternatively, this rotation can also be specified by the following transformation matrix:
Then we can rewrite the formula as:
For example, to rotate a triange about the origin with vertices at original coordinates (10,20), (10,10),
(20,10) by 30 degrees, we compute as followings:
4
Rotation of vertex (10,20):
Rotation of vertex (10,10):
Rotation of vertex (20,10):
The resultant coordinates of the triangle vertices are (-1.34,22.32), (3.6,13.66), and (12.32,18.66)
respectively.
Exercise: Rotate a triangle with vertices at original coordinates (10,20), (5,10), (20,10) by 45 degrees.
Roughly plot the original and resultant triangles.
Scaling With Respect to the Origin
We scale a 2D object with respect to the origin by setting the scaling factors sx and sy, which are
multiplied to the original vertex coordinate positions (x,y):
x' = x * sx, y' = y * sy
Alternatively, this scaling can also be specified by the following transformation matrix:
Then we can rewrite the formula as:
5
For example, to scale a triange with respect to the origin, with vertices at original coordinates (10,20),
(10,10), (20,10) by sx=2, sy=1.5, we compute as followings:
Scaling of vertex (10,20):
Scaling of vertex (10,10):
Scaling of vertex (20,10):
The resultant coordinates of the triangle vertices are (20,30), (20,15), and (40,15) respectively.
Exercise: Scale a triangle with vertices at original coordinates (10,25), (5,10), (20,10) by sx=1.5, sy=2,
with respect to the origin. Roughly plot the original and resultant triangles.
Concatenation Properties of Composite Matrix
I. Matrix multiplication is associative:
A·B·C = (A·B) ·C = A·(B·C)
Therefore, we can evaluate matrix products using these associative grouping.
For example, we have a triangle, we want to rotate it with the matrix B, then we translate it with
matrix A.
Then, for a vertex of that triangle represented as C, we compute its transformation as:
C'=A·(B·C)
But we can also change the computation method as:
6
C' = (A·B)·C
The advantage of computing it using C' = (A·B)·C instead of C'=A·(B·C) is that, for computing
the 3 vertices of the triangle, C1, C2, C3, the computation time is shortened:
Using C'=A·(B·C):
1. compute B · C1 and put the result into I1
2. compute A · I1 and put the result into C1
'
3. compute B · C2 and put the result into I2
4. compute A · I2 and put the result into C2
'
5. compute B · C3 and put the result into I3
6. compute A · I3 and put the result into C3
'
Using C' = (A·B)·C:
1. compute A · B and put the result into M
2. compute M · C1 and put the result into C1
'
3. compute M · C2 and put the result into C2
4. compute M · C3 and put the result into C3
Example: Rotate a triangle with vertices (10,20), (10,10), (20,10) about the origin by 30 degrees and then
translate it by tx=5, ty=10,
We compute the rotation matrix:
And we compute the translation matrix:
Then, we compute M=A·B
7
Then, we compute the transformations of the 3 vertices:
Transformation of vertex (10,20):
Transformation of vertex (10,10):
Transformation of vertex (20,10):
The resultant coordinates of the triangle vertices are (3.66,32.32), (8.66,23.66), and (17.32,28.66)
respectively.
Matrix multiplication may not be commutative:
A·B may not equal to B·A
This means that if we want to translate and rotate an object, we must be careful about the order in which
the composite matrix is evaluated. Using the previous example, if you compute C' = (A·B)·C, you are
rotating the triangle with B first, then translate it with A, but if you compute C' = (B·A)·C, you are
translating it with A first, then rotate it with B. The result is different.
Exercise: Translate a triangle with vertices (10,20), (10,10), (20,10) by tx=5, ty=10 and then rotate it about
the origin by 30 degrees. Compare the result with the one obtained previously: (3.66,32.32), (8.66,23.66),
and (17.32,28.66) by plotting the original triangle together with these 2 results.
8
Composite Transformation Matrix
Translations
By common sense, if we translate a shape with 2 successive translation vectors: (tx1, ty1) and (tx2, ty2),
it is equal to a single translation of (tx1+ tx2, ty1+ ty2).
This additive property can be demonstrated by composite transformation matrix:
This demonstrates that 2 successive translations are additive.
Rotations
By common sense, if we rotate a shape with 2 successive rotation angles: ? and a, about the origin, it
is equal to rotating the shape once by an angle ? + a about the origin.
Similarly, this additive property can be demonstrated by composite transformation matrix:
9
This demonstrates that 2 successive rotations are additive.
Scalings With Respect to the Origin
By common sense, if we scale a shape with 2 successive scaling factor: (sx1, sy1) and (sx2, sy2), with
respect to the origin, it is equal to a single scaling of (sx1* sx2, sy1* sy2) with respect to the origin.
This multiplicative property can be demonstrated by composite transformation matrix:
This demonstrates that 2 successive scalings with respect to the origin are multiplicative.
Other Transformations
Reflection
10
Shear
Exercise: Think of a y-direction shear, with a shearing parameter shy, relative to the y-axis.
Transformation Between 2 Cartesian Systems
For modelling and design applications, individual objects may be defined in their own local Cartesian
References. The local coordinates must then be transformed to position the objects within the overall
scene coordinate system.
Suppose we want to transform object descriptions from the xy system to the x'y' system:
11
Other forms of transformation
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 180o about the reflection axis.
Reflection gives image based on position of axis of reflection. Transformation for some positions are discussed.
Transformation Matrix for reflection about the line y=0, the x axis
Reflection about x axis
This transformation keeps x values the same but flips (change the sign) y values of coordinate positions
Transformation matrix for reflection about the line x=0, the y axis
Figure Reflection about y axis
12
This transformation keeps y values are same, but flips (change the sign) x values of coordinate position.
Figure Reflection about origin
The transformation flips (Change the sign) x and y both values of coordinate positions
Transformation matrix for reflection about the line x= y.
Figure Reflection about x=y line
This transformation interchange x and y values of coordinate positions
Transformation matrix for reflection about the line x= -y.
Reflection about x=-y line
13
This transformation interchange x and y values of coordinate positions
Example:- Find the coordinates after reflection of the triangle [A(10,10), B(15,15), C(20,10)] about x axis
The final coordinate after reflection are [A’(10,-10), B’(15,-15), C’(20,-10)]
Shear
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 shear.
Two common shearing transformations are those that shift coordinates x values and those that shift y values.
Shear in x – direction
Shear in x – direction
14
Shear in y – direction
Shear in y – direction
Shear relative to y – axis that is x =0 line can be produced by the following equation: x’=x, y’=y+shy . x
15
Transformation matrix for that is:
Here shy is shear parameter. We can assign any real values to shy.
We can generate y – direction shear relative to other reference line x =xref with the following equation:
Final coordinate after shear are [A’(0,0.5), B’(1,1), C’(1,2), D’(0,1.5)]
The Viewing Pipeline
Window: Area selected in world-coordinate for display is called window. It defines what is to be viewed.
Viewport: Area on a display device in which window image is displayed (mapped) is called viewport. It defines where
to display.
In many cases window and viewport are rectangles, also other shape may be used as window and viewport.
In general finding device coordinates of viewport from the world coordinates of window is called viewing
transformation. Sometimes we consider viewing transformation as window-to-viewport transformation but generally
it involves more steps.
16
A viewing transformation using standard rectangles for the window and viewport
Now we see steps involved in viewing pipeline.
2D Viewing pipeline
17
Viewing Coordinate Reference Frame
A viewing-coordinate frame is moved into coincidence with the world frame in two steps: (a) translate the viewing
origin to the world origin, and then (b) rotate to align the axes of the two systems
We can obtain reference frame in any direction and at any position.
For handling such condition first of all we translate reference frame origin to standard reference frame origin and then
we rotate it to align it to standard axis. In this way we can adjust any window in any reference frame. This is illustrated
by the following transformation matrix
MWC,VC =RT
Where T is the translation matrix and R is the rotation matrix
Window-To-Viewport Coordinate Transformation
Mapping of window coordinate to viewport is called window to viewport transformation.
We do this using transformation that maintains relative position of window coordinate into viewport. That means
center coordinates in window must remain at the center position in viewport. We find relative position by equation as
follow:
18
We can also map window to view port with the set of transformation, which include the following sequence of
transformation:
1. Perform a sclaing transformation using fixed-point position of (xwmin, ywmin) that scale the window area to the
size of the viewpoint.
2. Translate the scaled window area to the position of the viewport.
For maintaing relative proportions we take (sx=sy), in case if bothe are not equal then we get stretched or contracted
in either the x or y direction when displayed on the output device.
Characters are handle in two different ways one way is simply maintain relative position like other primitive and the
other is to maintain standard character size even though viewport size is enlarged or reduced. Number of displ;ay
device can be used in application and for each we can use different window-to-viewport transformation. This mapping
is called the workstation transformation.
Workstation transformation
19
Line clipping against a rectangular window
20
Line which is completely inside is displayed completely. Line which is completely outside is eliminated from display.
And for partially inside line we need to calculate intersection with window boundary and find which part inn inside
the clipping boundary and which part is eliminated.