Unit-2 Cgip
Unit-2 Cgip
Unit-2 Cgip
Operations that are applied to the geometric description of an object to change its position,
orientation, or size are called geometric transformations.
The basic geometric-transformation functions available are
1. Translation,
2. Rotation, and
3. Scaling.
Other useful transformations are Reflection and Shearing.
To introduce the general concepts associated with geometric transformations, we first consider
operations in two dimensions.
2-Dimensional Translation
- The transformation that changes the position from one point to other
along the straight line path is called Translation.
- To translate a two-dimensional position, we add translation
distances dx and dy to the original coordinates (x, y) to obtain the new
coordinate position (xn, yn) as shown in Figure below.
- From Figure we have,
𝒙𝒏 = 𝒙 + 𝒅𝒙
𝒚𝒏 = 𝒚 + 𝒅𝒚
The translation distance pair (dx, dy) is called a translation vector or shift vector.
We can express the above equations as a single matrix equation by using the following column
vectors to represent coordinate positions and the translation vector:
Example:
Consider a triangle with 3 vertices A(20,0), B(60,0), (40,100), being translated 100 units to the
right & 10 units up.. Find the new Vertices.
Solution:
To find Anew, Given A (20,0) To find Bnew Given B (60,0) To find Cnew, Given C(40,100)
Yn = y + dy =0 + 10 = 10 Yn = y + dy =0 + 10 = 10 Yn=y+dy
y+dy = 100+10 =110
Note:
1. Translation is a rigid body that moves objects without deformation.
2. Polygons are translated by adding translation distances for every vertex of the polygon.
3. Circles or ellipse are translated by adding the translation distance to the center.
2-Dimensional Rotation
A 2D rotation is applied to an object by repositioning it along a circular path in the xy plane.
Rotation can be generated by specifying the rotation angle ‘θ’. By default the equations we have
is for the rotation about an origin.
Positive values of θ specify anticlockwise rotation.
Negative values of θ specify clockwise rotation.
Transformation equation for rotation of a point P with center of rotation is origin is as shown
in the figure.
Example:
Consider a triangle with 3 vertices A(0,0), B(60,0), (40,100), being translated 100 units to the
right & 10 units up. Find the new Vertices.
Solution:
Θ= - 45o
To find Anew, Given A (0,0) To find Bnew Given B (60,0) To find Cnew, Given C(40,100)
Xn= 0*cos(-45) -0*sin(-45)=0 Xn= 60*cos(-45) -0*sin(-45)=42 Xn=40*cos(-45)-100*sin(-45)=99
Yn = 0*sin(-45)+0*cos(-45)=0 Yn=60*sin(-45)+0*cos(-45)=-42 Yn=40*sin(-45)+100*cos(-45)=42
Anew (0,0) Bnew (42,-42) Cnew (99,42)
2-Dimensional Scaling
A Scaling transformation is used to alter the size of an object.
Scaling of a polygon is done by computing the product of (x, y) of each vertex with scaling
factors (Sx, Sy) to product the transformed co-ordinates (xn , yn).
The equations are:
Note:
1. If (Sx, Sy) < 1, reduces the size of the object.
2. If (Sx, Sy) > 1, produce an enlargement.
3. If (Sx, Sy) = 1, No change in the size of the object.
4. If (Sx ≠ Sy), distort the picture.
In the 3x3 matrix form for homogeneous coordinates, the transformation equations are:
Reflection
A reflection is a transformation that produces a minor image of an object relative to an axis of
reflection.
Scaling transformation with negative scaling factors gives us reflection.
Shear:
A transformation that slants the shape of an object is called shear transformation.
Two common shearing transformations are:
1. X-shear(Shifts X coordinate values)
2. Y-shear(Shifts Y coordinate values)
X-Shear
Y-Shear
Inverse Transformation:
It refers to the process of undoing the transformation that has been applied to an object or set of
vertices.
1. For translation,weobtain the inverse matrix by negating the translation distances. Thus, for
inverse translation we have, T (-dx, -dy)
2. An inverse rotation is accomplished by replacing the rotation angle by its negative. Thus, for
inverse rotation we have, R(-ϴ)
3. An inverse scaling transformation is accomplished by replacing the scaling parameters with
𝟏 𝟏
their reciprocals. Thus, for inverse scaling we have, S ,
𝑺𝒙 𝑺𝒚
Composition (Concatenation) of 2D transformation:
The basic purpose of composing transformation is to gain efficiency by applying a single
composed transformation to a point, rather than applying a series of transformations, one
after the other.
Thus, if we want to apply two transformations to point position P, the transformed location
would be calculated as
Pn= M2 ·M1 · P
= M· P
The coordinate position is transformed using the composite matrix M, rather than applying
the individual transformations M1 and then M2.
Case 1: Rotation about arbitrary point
We know that how to do rotation only about the origin. To rotate an object about an arbitrary
point (xr, yr) we have to carry out the following 3 steps
1. Translate such that (xr, yr) is at origin. i. e, T (-xr,- yr)
2. Rotate i.e, R(ϴ)
3. Apply inverse translations such that (xr, yr), is shifted to its from origin to its original
position i.e, T(xr, yr).
Therefore the net transformation matrix is:
T(xr, yr)* R(ϴ) * T (-xr,- yr)
From Figure,
P’= T(dx1,dy1) • P(1)
P”= T(dx2,dy2) · P’(2)
Put (1) in (2), we get,
P”= T(dx2,dy2) ·T(dx1,dy1) · P
Composite Two-Dimensional
Dimensional Rotations
(Prove that 2 successive rotations are additive.)
Let two successive rotations are applied to a point P as shown in figure:
From Figure,
P’= R(ϴ1) · P(1)
P”= R(ϴ2) · P’(2)
Put (1) in (2), we get,
P”= R(ϴ2) ·R(ϴ1) · P
Composite Two-Dimensional
Dimensional Scalings
(Prove that 2 successive scalings are multiplicative)
Composition (Concatenation
oncatenation) of 3D transformation:
1. CT //Translation
2. CR //Rotation
3. CS //Scaling
Most systems allow us to load the CTM with an arbitrary matrix M,
CM //M is Transformation Matrix
(or) to post-multiply by an arbitrary Matrix M
CCM //M is Transformation Matrix
-We Can alter the CTM selected matrix with the Function
glMultMatrixf(m)
m is one dimension array of 16 elements
-Rotation, translation & scaling are provided through the following 3 functions
glRotatef(angle, Vx, Vy, Vz)
-angle in degrees.
- (Vx, Vy, VZ) define axis of rotation
Other Functions
glPushMatrix();
– Save the state.
– Push a copy of the CTM onto the stack.
– The CTM itself is unchanged.
glPopMatrix();
– Restore the state, as it was at the last Push.
– Overwrite the CTM with the matrix at the top of the stack.
glLoadIdentity();
– Overwrite the CTM with the identity matrix.
Questions on Unit-2