Sunteți pe pagina 1din 45

Session-4 2D & 3D Scaling, Translation, Rotation, Shear, Reflection, Projection and Composite Transformations (Chap. 5.1 - 5.

3 and 5.5 - 5.8)


Course Delivery by Dr. K. Satyanarayan Reddy
Text Book Computer Graphics: Principles and Practice in C by James D. Foley, A. Van Dam, S.K. Feiner, and J.F. Hughes,, 2nd edition Pearson Education.

GEOMETRICAL TRANSFORMATIONS
The Transformations are used directly by Application Programs and within many graphics subroutine packages. 2D TRANSFORMATIONS : The points in the (x, y) plane can be translated to new positions by adding translation amounts to the coordinates of the points. For each point P(x, y) to be moved by dx units parallel to the x-axis and by dy units parallel to the y-axis to the new point P'(x', y'), which can be written as:x= x + dx , y = y + dy -------------------- (5.1)
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 2

GEOMETRICAL TRANSFORMATIONS contd.


If we define the column vectors P= P = T= ------------ (5.2) then (5. l) can be expressed more concisely as P' = P + T ----------------------------- (5.3) P =
Adjacent Figure shows the effect of Translating the outline of a house by (3, -4) i.e dx = 3 and dy = -4.
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 3

=P+T=

GEOMETRICAL TRANSFORMATIONS contd.


Points can be SCALED (stretched) by sx, along the x axis and by sy along the y axis into new points by the multiplications x' = sx x; y' = sy y ----------------------- (5.4) ln matrix form this is given by following equation = . = ------------- (5.5) Where P = S . P ; S is called the Scaling Matrix

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

GEOMETRICAL TRANSFORMATIONS contd.


In the adjacent Fig. the house is scaled by in x direction and 1/4 in y direction. Note: The scaling is about the origin; the house is smaller and is closer to the origin.

Scaling of a house: The scaling is non uniform, and the house changes position.
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 5

GEOMETRICAL TRANSFORMATIONS contd.

Here = 45o

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

GEOMETRICAL TRANSFORMATIONS contd.


Note: The Positive angles are measured counterclockwise from x toward y. For negative (clock- wise) angles, the identities cos(-) = cos and sin(-) = - sin can be used to modify Equations (5.6) and (5.7).

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

HOMOGENEOUS COORDINATES AND MATRIX REPRESENTATION OF 2D TRANSFORMATIONS

The matrix representations for Translation, Scaling, and Rotation are given respectively as follows: P' = T + P -------------------------(5.3) P' = S P -------------------------(5.5) P' = R . P -------------------------(5.7) But, Translation is treated differently (as an addition) from Scaling and Rotation (as multiplications). If points are expressed in Homogeneous Coordinates, then all the 3 transformations can be treated as multiplications.
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 8

HOMOGENEOUS COORDINATES AND MATRIX REPRESENTATION OF 2D TRANSFORMATIONS contd.

In homogeneous coordinates, a 3rd coordinate is added to a point. Thus a pair of numbers (x, y), is represented by a triple (x, y, W). Also, two sets of homogeneous coordinates (x, y, W) and (x', y', W') represent the same point if and only if one is a multiple of the other. e.g.: Thus, (2, 3, 6) and (4, 6, 12) are the same points represented by different coordinate Triples. Also, at least one of the homogeneous coordinates must be nonzero: (0, 0, 0) is not allowed. If the coordinate W 0, then (x, y, W) can be divided through by W representing the same point as (x/W, y/W, 1), and the numbers x/ W and y/W are called the Cartesian coordinates of the homogeneous point. The points with W = 0 are called points at infinity.
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 9

HOMOGENEOUS COORDINATES AND MATRIX REPRESENTATION OF 2D TRANSFORMATIONS contd.

Triples of coordinates represent points in 3D-space, but here Triples are being used to represent points in 2D-space. lf all the triples are taken, representing the same point i.e. all triples of the form (tx, ty, tW), with t 0 then a line in 3D-space is obtained. Thus, each homogeneous point represents a line in 3D-space. If the point is homogenized (divide by W), a point of the form (x, y, 1) is obtained. Thus, the homogenized points form the plane defined by the equation W = 1 in (x, y, W)-space. The adjacent Figure shows this relationship.
The XYW homogeneous coordinate space, with the W = 1 plane and point P(X, Y, W) projected onto the W = 1 plane.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

10

HOMOGENEOUS COORDINATES AND MATRIX REPRESENTATION OF 2D TRANSFORMATIONS contd.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

11

HOMOGENEOUS COORDINATES AND MATRIX REPRESENTATION OF 2D TRANSFORMATIONS contd.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

12

HOMOGENEOUS COORDINATES AND MATRIX REPRESENTATION OF 2D TRANSFORMATIONS contd.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

13

HOMOGENEOUS COORDINATES AND MATRIX REPRESENTATION OF 2D TRANSFORMATIONS contd.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

14

HOMOGENEOUS COORDINATES AND MATRIX REPRESENTATION OF 2D TRANSFORMATIONS contd.

When the product of an arbitrary sequence of Rotation, Translation, and Scale matrices are considered then such transformations are called Affine Transformations(AT), and ATs have the property of preserving parallelism of lines but not lengths and angles. Figure 5.6 shows the results of applying a - 45 rotation and then a non uniform scaling to the unit cube.
In the adjacent figure a unit cube is rotated by 45 and is non uniformly scaled. The result is an Affine Transformation of the unit cube, in which parallelism of lines is maintained, but neither angles nor lengths are maintained.
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 15

HOMOGENEOUS COORDINATES AND MATRIX REPRESENTATION OF 2D TRANSFORMATIONS contd.

Another type of primitive Transformation, shear Transformations, are also affine. 2D Shear transformations are of two kinds: a Shear along the x axis and a Shear along the y axis. Figure 5.7 shows the effect of shearing the unit cube along each axis. The operation is represented by the matrix

The term a in the shear matrix is the proportionality constant. Note: The product SHx.[x y 1]T is [x+ay y 1]T, clearly demonstrating the proportional change in x as a function of y.
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 16

HOMOGENEOUS COORDINATES AND MATRIX REPRESENTATION OF 2D TRANSFORMATIONS contd.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

17

COMPOSITION OF 2D TRANSFORMATIONS
Consider the rotation of an object about some arbitrary point P1. As it is known, how to rotate only about the origin, the original (difficult) problem is converted into three separate (easy) problems. Thus, to rotate about P1, a sequence of three fundamental transformations are needed: Z. Translate such that P1, is at the origin 2. Rotate 3. Translate such that the point at the origin returns to P1. This sequence is illustrated in Fig. 5.8, in which our house is rotated about P1(x1, y1). The first translation is by (-x1, - y1), whereas the later translation is by the inverse (x1, y1).

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

18

COMPOSITION OF 2D TRANSFORMATIONS contd.

Example

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

19

COMPOSITION OF 2D TRANSFORMATIONS contd.


Suppose we wish to scale, rotate, and position the house shown in the following Figure with P, as the center for the rotation and scaling. The sequence is to translate P, to the origin, to perform the scaling and rotation, and then to translate from the origin to the new position P2 where the house is to be placed.
Direction of Application of Transformation

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

20

EFFICIENCY
The most general composition of R, S, and T operations produces a matrix of the form:

The upper 2 x2 sub matrix is a composite Rotation and Scale matrix, whereas tx and ty, are composite Translations. Calculating M P as a vector multiplied by a 3 X 3 matrix takes nine multiplies and six adds. The fixed structure of the last row of Eq. (5.35), simplifies the actual operations to reducing the process to four multiplies and four adds which is a significant speedup.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

21

EFFICIENCY contd.
Another area where efficiency is important is creating successive views of an object, such as a molecule or airplane, rotated a few degrees between each successive view. If each view can be created and displayed quickly enough (30 to 100 milliseconds each), then the object will appear to be rotating dynamically. To achieve this speed, each individual point and line of the object must be transformed as quickly as possible. The rotation equations (Eq. 5.6) require four multiplies and two adds, this operation count can be decreased by observing that cos is very close to 1, because is small (just a few degrees). In this approximation, Eq. (5.6) becomes x' = x - y sin, y' = x sin + y (5.37) which requires just two multiplies and two adds.
The savings of two multiplies can be significant on computers lacking hardware multipliers.
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 22

EFFICIENCY contd.
Equation (5.37), however, is only an approximation to the correct values of x and y; but a small error is built in.

This is a better approximation than is Eq. (5.37) because the determinant of the corresponding 2 X 2 matrix is 1, which means that the areas transformed by Eq. (5.38) are unchanged. Note: Cumulative errors can also arise when using the correct rotation equations repeatedly .
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 23

MATRIX REPRESENTATION OF 3D TRANSFORMATIONS


As 2D transformations can be represented by 3 x 3 matrices using homogeneous coordinates, similarly 3D transformations can be represented by 4x4 matrices, provided homogeneous coordinate representations of points are used in 3D space.
Thus the point (x, y, z) is represented as (x, y, z, W), where two of these quadruples represent the same point if one is a nonzero multiple of the other; the quadruple (0, 0, 0, 0) is not allowed.

As in 2D, a standard representation of a point (x, y, z, W) with W 0 is given by (x/W, y/W, z/W, 1). Transforming the point to this form is called homogenizing.
Also, points whose W coordinate is zero are called Points at Infinity.
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 24

MATRIX REPRESENTATION OF 3D TRANSFORMATIONS contd.


The 3D coordinate system is right-handed, as shown in Figure below. The Positive Rotations in a Right Handed System are such that, when looking from a positive axis toward the origin, a 90 Anticlockwise rotation will transform one positive axis into the other. This table follows from this convention: If Axis of Rotation is Direction of Positive Rotation is x y to z y z to x z x to y

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

25

MATRIX REPRESENTATION OF 3D TRANSFORMATIONS contd.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

26

MATRIX REPRESENTATION OF 3D TRANSFORMATIONS contd.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

27

MATRIX REPRESENTATION OF 3D TRANSFORMATIONS contd.

Rotation about z-axis

The columns (and the rows] of the upper left 3 X 3 submatrix of Rz(), Rx(), and Ry() are mutually perpendicular unit vectors and the submatrix has a determinant of 1, which means the three matrices are special orthogonal. Also, the upper-left 3 X 3 submatrix formed by an arbitrary sequence of rotations is special orthogonal. Note: The Orthogonal Transformations preserve Distances and Angles. All these transformation matrices have inverses. The inverse for T is Obtained by negating dx, dy, and dz for S, by replacing sx, sy, and sz by their reciprocals; and also each of the three rotation matrices is obtained by negating the angle of rotation.
NOTE:
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 28

MATRIX REPRESENTATION OF 3D TRANSFORMATIONS contd.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

29

COMPOSITION OF 3D TRANSFORMATIONS
To compose 3D Transformation Matrices, using an example. The objective is to transform the directed line segments P1P2 and P1P3 in following Figure from their starting position in part (a) to their ending position in part (b). Thus, point P1 is to be translated to the origin, P1P2 is to lie on the positive z axis, and P1P3 is to lie in the positive y axis half of the (y, z) plane. The lengths of the lines are to be unaffected by the transformation.
Transforming P1, P2, and P3 from their (a) Initial Position to their (b) Final Position.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

30

COMPOSITION OF 3D TRANSFORMATIONS contd.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

31

COMPOSITION OF 3D TRANSFORMATIONS contd.

Rotation about the y axis; The projection of P1P2, which has length D1, is rotated into the z axis. The angle shows the Positive direction of rotation about the y axis; The actual angle used is (9O ).
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 32

COMPOSITION OF 3D TRANSFORMATIONS contd.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

33

COMPOSITION OF 3D TRANSFORMATIONS contd.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

34

COMPOSITION OF 3D TRANSFORMATIONS contd.

The adjacent Figure which depicts Rotation about the z axis. The protection of P1'P3, whose length is D3, is rotated by the positive angle into the y-axis, bringing the line itself into the (y, z) plane. D3 is the length of the projection.
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 35

COMPOSITION OF 3D TRANSFORMATIONS contd.


Method 2: The second way to obtain the matrix R is to use the properties of orthogonal matrices as discussed in Homogeneous coordinate system. Recall that the unit row vectors of R rotate into the principal axes. Replacing the second subscripts of Eq. (5.45) with x, y, and z for notational convenience

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

36

COMPOSITION OF 3D TRANSFORMATIONS contd.

The unit vectors Rx , Ry and Rz which are transformed into the Principal Axes.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

37

COMPOSITION OF 3D TRANSFORMATIONS contd.


Example: the Figure 1 below shows an airplane defined in the xp, yp, zp coordinate system and centered at the origin. To transform the airplane such that it heads in the direction given by the vector DOF (Direction Of Flight), is centered at P, and is not banked, as shown in Figure 2. To do this operation the transformation consists of a rotation to head the airplane in the proper direction, followed by a translation from the origin to P.
Figure 1 Figure 2

Fig. 2 The airplane of Fig. 1 positioned at point P and headed in direction DOF.
3 October 2013 BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy 38

COMPOSITION OF 3D TRANSFORMATIONS contd.


Then to find the rotation matrix; It must be determined that in what direction each of the xp, yp, and zp axes is heading in Fig. 2, Also make sure the directions are normalized, and use them as column vectors in a rotation matrix. The zp axis must be transformed to the DOF direction, and the xp axis must be transformed into a horizontal vector perpendicular to DOF i.e. in the direction of y x DOF. The yp direction is given by zp x xp = DOF x (y x DOF)

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

39

TRANSFORMATIONS AS A CHANGE IN COORDINATE SYSTEM


This view is useful when multiple Objects, each defined in its own local coordinate system, are combined and these objects coordinates are to be expressed in a single, global coordinate system. Define Mij as the transformation which converts the representation of a point in Coordinate system j into its representation in coordinate system i'. We define P(i) as the representation of a point in coordinate system i', P(j) as the representation of the point in system j and P(k) as the representation of the point in coordinate system k then P(i) = Mij P(i) and P(j) = Mjk P(k) (5.68) P(i) = Mij Mjk P(k) = Mik P(k) (5.69) Where
3 October 2013

Mij Mjk = Mik


BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

(5.70)
40

TRANSFORMATIONS AS A CHANGE IN COORDINATE SYSTEM contd.

Figure below shows four different coordinate systems. The transformation from coordinate system 2 to 1 is Similarly

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

41

TRANSFORMATIONS AS A CHANGE IN COORDINATE SYSTEM contd.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

42

TRANSFORMATIONS AS A CHANGE IN COORDINATE SYSTEM contd.

Consider the simple case of translating the Set of points that define the house shown in Fig. A below to the origin. This transformation is T(-x1, -y1). Labeling the two coordinate systems as in Fig. B, we see that the transformation that maps coordinate system 1 into 2 i.e. M2 1 is T(x1, y1), which is just T(-x1, -y1)-1.

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

43

TRANSFORMATIONS AS A CHANGE IN COORDINATE SYSTEM contd.


The transformation for the points represented in a single coordinate system is just

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

44

THANK YOU

3 October 2013

BITS-WASE: Computer Graphics by Dr. K. Satyanarayan Reddy

45

S-ar putea să vă placă și