0% found this document useful (0 votes)
2 views

module2b_cg

This document covers 3D geometric transformations, including translation, rotation, scaling, and composite transformations, as well as affine transformations and OpenGL geometric transformation functions. It explains the mathematical representations and coding implementations for these transformations in computer graphics. The document also discusses quaternion methods for rotations and various types of transformations such as reflections and shears.

Uploaded by

deekshitha222025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

module2b_cg

This document covers 3D geometric transformations, including translation, rotation, scaling, and composite transformations, as well as affine transformations and OpenGL geometric transformation functions. It explains the mathematical representations and coding implementations for these transformations in computer graphics. The document also discusses quaternion methods for rotations and various types of transformations such as reflections and shears.

Uploaded by

deekshitha222025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 2 - b
Module 2 - b

2 -b: 3DGeometric Transformations:


3.2.1
3.2.2 3D Translation,
3.2.3 Rotation,
3.2.4 Scaling,
3.2.5 Composite 3D Transformations,
3.2.6 Other 3D Transformations,
3.2.7 Affine Transformations,
3.2.8 Opengl Geometric Transformations

3.2.1 Three-Dimensional Geometric Transformations


 Methods for geometric transformations in three dimensions are extended from two
dimensional methods by including considerations for the z coordinate.

 A three-dimensional position, expressed in homogeneous coordinates, is represented as a
four-element column vector

3.2.2 Three-Dimensional Translation


 A position P = (x, y, z) in three-dimensional space is translated to a location P’= (x’, y’,
z’) by adding translation distances tx, ty, and tz to the Cartesian coordinates of P:


 We can express these three-dimensional translation operations in matrix form

or

 Moving a coordinate position with translation vector T = (tx , ty , tz ) .


Computer Graphics and Fundamentals for Image Processing (21CS63)

1
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

 Shifting the position of a three-dimensional object using translation vector T.

CODE:
typedef GLfloat Matrix4x4 [4][4];
/* Construct the 4 x 4 identity matrix. */
void matrix4x4SetIdentity (Matrix4x4 matIdent4x4)
{
GLint row, col;
for (row = 0; row < 4; row++)
for (col = 0; col < 4 ; col++)
matIdent4x4 [row][col] = (row == col);
}
void translate3D (GLfloat tx, GLfloat ty, GLfloat tz)
{
Matrix4x4 matTransl3D;
/* Initialize translation matrix to identity. */
matrix4x4SetIdentity (matTransl3D);

2
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

matTransl3D [0][3] = tx;


matTransl3D [1][3] = ty;
matTransl3D [2][3] = tz;
}

 An inverse of a three-dimensional translation matrix is obtained by negating the


translation distances tx, ty, and tz

3.2.3 Three-Dimensional Rotation


 By convention, positive rotation angles produce counterclockwise rotations about a
coordinate axis.

 Positive rotations about a coordinate axis are counterclockwise, when looking along the
positive half of the axis toward the origin.

Three-Dimensional Coordinate-Axis Rotations


Along z axis:

 In homogeneous-coordinate form, the three-dimensional z-axis rotation equations are

3
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

 Transformation equations for rotations about the other two coordinate axes can be
obtained with a cyclic permutation of the coordinate parameters x, y, and z

x → y→ z→ x
Along x axis

Along y axis

 An inverse three-dimensional rotation matrix is obtained in the same by replacing θ with



−θ.

General Three-Dimensional Rotations


 A rotation matrix for any axis that does not coincide with a coordinate axis can be set up
as a composite transformation involving combinations of translations and the coordinate-
axis rotations the following transformation sequence is used:

1. Translate the object so that the rotation axis coincides with the parallel coordinate axis.

4
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

2. Perform the specified rotation about that axis.


3. Translate the object so that the rotation axis is moved back to its original position.

 A coordinate position P is transformed with the sequence shown in this figure as

Where the composite rotation matrix for the transformation is

 When an object is to be rotated about an axis that is not parallel to one of the coordinate
axes, we must perform some additional transformations we can accomplish the required
rotation in five steps:

1. Translate the object so that the rotation axis passes through the coordinate origin.
2. Rotate the object so that the axis of rotation coincides with one of the coordinate axes.
3. Perform the specified rotation about the selected coordinate axis.
4. Apply inverse rotations to bring the rotation axis back to its original orientation.
5. Apply the inverse translation to bring the rotation axis back to its original spatial position.

5
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

 Components of the rotation-axis vector are then computed as


V = P2 − P1

= (x2 − x1, y2 − y1, z2 − z1)
 The unit rotation-axis vector u is

Where the components a, b, and c are the direction cosines for the rotation axis

 The first step in the rotation sequence is to set up the translation matrix that repositions
the rotation axis so that it passes through the coordinate origin.

 Translation matrix is given by

 Because rotation calculations involve sine and cosine functions, we can use standard
vector operations to obtain elements of the two rotation matrices.

 A vector dot product can be used to determine the cosine term, and a vector cross product
can be used to calculate the sine term.

 Rotation of u around the x axis into the x z plane is accomplished by rotating u’ (the
projection of u in the y z plane) through angle α onto the z axis.

 If we represent the projection of u in the yz plane as the vector u’= (0, b, c), then the
cosine of the rotation angle α can be determined from the dot product of u’ and the unit
vector uz along the z axis:

6
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

where d is the magnitude of u’

 The coordinate-independent form of this cross-product is





 and the Cartesian form for the cross-product gives us



 Equating the above two equations

or
 We have determined the values for cos α and sin α in terms of the components of vector
u, the matrix elements for rotation of this vector about the x axis and into the xz plane










 Rotation of unit vector u” (vector u after rotation into the x z plane) about the y axis.
Positive rotation angle β aligns u” with vector uz .

 We can determine the cosine of rotation angle β from the dot product of unit vectors u’’
and uz. Thus,

7
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

 Comparing the coordinate-independent form of the cross-product






with the Cartesian form




 we find that




 The transformation matrix for rotation of u” about the y axis is

 The specified rotation angle θ can now be applied as a rotation about the z axis as
follows:

 The transformation matrix for rotation about an arbitrary axis can then be expressed as
the composition of these seven individual transformations:



 The composite matrix for any sequence of three-dimensional rotations is of the form

 The upper-left 3 × 3 submatrix of this matrix is orthogonal

8
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

 Assuming that the rotation axis is not parallel to any coordinate axis, we could form the
following set of local unit vectors

 If we express the elements of the unit local vectors for the rotation axis as






 Then the required composite matrix, which is equal to the product Ry(β) · Rx(α), is

Quaternion Methods for Three-Dimensional Rotations


 A more efficient method for generating a rotation about an arbitrarily selected axis is to
use a quaternion representation for the rotation transformation.

 Quaternions, which are extensions of two-dimensional complex numbers, are useful in a
number of computer-graphics procedures, including the generation of fractal objects.

 One way to characterize a quaternion is as an ordered pair, consisting of a scalar part and
a vector part:

q = (s, v)

 A rotation about any axis passing through the coordinate origin is accomplished by first
setting up a unit quaternion with the scalar and vector parts as follows:

9
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

 Any point position P that is to be rotated by this quaternion can be represented in


quaternion notation as



 Rotation of the point is then carried out with the quaternion operation

where q−1 = (s, −v) is the inverse of the unit quaternion q


 This transformation produces the following new quaternion:




 The second term in this ordered pair is the rotated point position p’, which is evaluated
with vector dot and cross-products as



 Designating the components of the vector part of q as v = (a, b, c) , we obtain the
elements for the composite rotation matrix






 Using the following trigonometric identities to simplify the terms

we can rewrite Matrix as

3.2.4 Three-Dimensional Scaling


 The matrix expression for the three-dimensional scaling transformation of a position P =
(x, y, z) is given by

10
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

 The three-dimensional scaling transformation for a point position can be represented as

where scaling parameters sx, sy, and sz are assigned any positive values.
 Explicit expressions for the scaling transformation relative to the origin are




 Because some graphics packages provide only a routine that scales relative to the
coordinate origin, we can always construct a scaling transformation with respect to any
selected fixed position (xf , yf , zf ) using the following transformation sequence:

1. Translate the fixed point to the origin.
2. Apply the scaling transformation relative to the coordinate origin
3. Translate the fixed point back to its original position.
 This sequence of transformations is demonstrated

11
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

CODE:
class wcPt3D
{
private:
GLfloat x, y, z;
public:
/* Default Constructor:

* Initialize position as (0.0, 0.0, 0.0).


*/
wcPt3D ( ) {
x = y = z = 0.0;
}
setCoords (GLfloat xCoord, GLfloat yCoord, GLfloat zCoord)
{ x = xCoord;
y = yCoord;
z = zCoord;
}
GLfloat getx ( ) const {
return x;
}
GLfloat gety ( ) const {
return y;
}
GLfloat getz ( ) const {
return z;
}
};
typedef float Matrix4x4 [4][4];
void scale3D (GLfloat sx, GLfloat sy, GLfloat sz, wcPt3D fixedPt)
{
Matrix4x4 matScale3D;

12
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

/* Initialize scaling matrix to identity. */


matrix4x4SetIdentity (matScale3D);
matScale3D [0][0] = sx;
matScale3D [0][3] = (1 - sx) * fixedPt.getx ( );
matScale3D [1][1] = sy;
matScale3D [1][3] = (1 - sy) * fixedPt.gety ( );
matScale3D [2][2] = sz;
matScale3D [2][3] = (1 - sz) * fixedPt.getz ( );
}

3.2.5 Composite Three-Dimensional Transformations


 We form a composite threedimensional transformation by multiplying the matrix
representations for the individual operations in the transformation sequence.

 We can implement a transformation sequence by concatenating the individual matrices
from right to left or from left to right, depending on the order in which the matrix
representations are specified

3.2.6 Other Three-Dimensional Transformations


Three-Dimensional Reflections
 A reflection in a three-dimensional space can be performed relative to a selected
reflection axis or with respect to a reflection plane.

 Reflections with respect to a plane are similar; when the reflection plane is a coordinate
plane (xy, xz, or yz), we can think of the transformation as a 180◦ rotation in four-

dimensional space with a conversion between a left-handed frame and a right-handed
frame

 An example of a reflection that converts coordinate specifications froma right handed
system to a left-handed system is shown below

13
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

 The matrix representation for this reflection relative to the xy plane is

Three-Dimensional Shears
 These transformations can be used to modify object shapes.

 For three-dimensional we can also generate shears relative to the z axis.

 A general z-axis shearing transformation relative to a selected reference position is
produced with the following matrix:

 The Below figure shows the shear transformation of a cube

A unit cube (a) is sheared relative to the origin (b) by Matrix 46, with shzx = shzy = 1.

3.2.7 Affine Transformations


 A coordinate transformation of the form

is called an affine transformation

14
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

 Affine transformations (in two dimensions, three dimensions, or higher dimensions) have
the general properties that parallel lines are transformed into parallel lines, and finite
points map to finite points.

 Translation, rotation, scaling, reflection,andshear are examples of affine transformations.

 Another example of an affine transformation is the conversion of coordinate descriptions
for a scene from one reference system to another because this transformation can be
described as a combination of translation and rotation

3.2.8 OpenGL Geometric-Transformation Functions


OpenGL Matrix Stacks
glMatrixMode:
 used to select the modelview composite transformation matrix as the target of
subsequent OpenGL transformation calls

 four modes: modelview, projection, texture, and color

 the top matrix on each stack is called the “current matrix”.

 for that mode. the modelview matrix stack is the 4 × 4 composite matrix that
combines the viewing transformations and the various geometric transformations
that we want to apply to a scene.

 OpenGL supports a modelview stack depth of at least 32,

glGetIntegerv (GL_MAX_MODELVIEW_STACK_DEPTH, stackSize);


 determine the number of positions available in the modelview stack for a particular
implementation of OpenGL.

 It returns a single integer value to array stackSize

 other OpenGL symbolic constants: GL_MAX_PROJECTION_STACK_DEPTH,
GL_MAX_TEXTURE_STACK_DEPTH, or GL_MAX_COLOR_STACK_DEPTH.

 We can also find out how many matrices are currently in the stack with
glGetIntegerv (GL_MODELVIEW_STACK_DEPTH, numMats);

15
Computer Graphics and Fundamentals for Image Processing (21CS63)

Module 3

We have two functions available in OpenGL for processing the matrices in a stack
glPushMatrix ( );
Copy the current matrix at the top of the active stack and store that copy in the second
stack position

glPopMatrix ( );
which destroys the matrix at the top of the stack, and the second matrix in the stack
becomes the current matrix

16
Module 3
Computer Graphics and Fundamentals for Image Processing (21CS63)

You might also like