Top Banner
2D Transformation of Graphics Unit 2
94

2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Dec 30, 2015

Download

Documents

Silas Turner
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

2D Transformation of Graphics

Unit 2

Page 2: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• What is geometric transformation?

• Operations that are applied to the geometric description of an object to change its position, orientation, or size are called geometric transformations.

Page 3: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• So the geometric-transformation functions that are available in some system are following:

1. Translation

2. Rotation

3. Scaling

4. Other useful transforms includes: reflection and shear.

Page 4: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Translation

• Rotation

Page 5: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Scaling

• Uniform Scaling

• Un-uniform Scaling

Page 6: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Reflection

• Shear

Page 7: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Why do we need geometric transformations in CG( motivation )?

• As a viewing aid

• As a modeling tool

• As an image manipulation tool

Page 8: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Two-Dimensional(2D) Translation

We perform a translation on a single coordinate point by adding offsets to its coordinates so as to generate a new coordinate position.

Similarly, a translation is applied to an object that is defined with multiple coordinate positions by relocating all the coordinate positions by the same displacement along parallel paths.

Suppose tx and ty is the translation distances, (x, y) is the original coordinates, is the new coordinate position.

txxx y y ty

'( , ')x y

Page 9: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Express the translation use matrix equation as following:

• Translation is a rigid-body transformation that moves objects without deformation.

• Ex: Translate a polygon with coordinates

A(2, 5), B(7, 10), C(10, 2) by 3 units x direction and 4 units in y direction

(Hint : Add 3 to all x values and 4 to all values).

x x tx

y y ty

Page 10: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Write a C++ program to translate :

• A point

• A line

• A Rectangle

• A Polygon (Triangle)

Page 11: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

/* C++ program */

#include<iostream.h>

#include<graphics.h>

#include<math.h>

void main()

{

clrscr();

int x,y,tx,tx;

/* initialise graphics

------------------------ */

detectgraph(&gd,&gm);

initgraph(&gd,&gm,“c:\\tc\\bgi");

Page 12: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

cout<<“Enter x, y:”cin>>x>>y;cout<<“Enter tx,ty”cin>>tx>>ty;putpixel(x,y,15);delay(100);putpixel(x+tx,y+ty,15);getch();closegraph();}

Page 13: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Translate a line:

line(x1,y1,x2,y2);

line(x1+tx,y1+ty,x2+tx,y2+ty);

Page 14: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Translate a rectangle:

rectangle(x1,y1,x2,y2);

rectangle(x1+tx,y1+ty,x2+tx,y2+ty);

Page 15: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Two-Dimensional Rotation• We generate a rotation transformation of an object by

specifying a rotation axis and a rotation angle. All points of the object are then transformed to new positions by rotating the points through the specified angle about the rotation axis.

• A 2D rotation of an object is obtained by repositioning the object along a circular path in the xy plane, the rotation axis is perpendicular to the xy plane.

• Parameters for 2D rotation is rotation angle and a rotation point( pivot point) .

• Rotation angle define a positive values for counterclockwise rotation about the pivot point.

),( rr yx

Page 16: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• r is the constant distance of the point form the origin, angle is the original angular position of the point from the horizontal, and is the rotation angle.

• Substitute expression (1) into (2)

cos

sin

x r

y r

cossinsincos)sin('

sinsin-coscos)cos('

rrry

rrrx

( 1)

( 2)

Page 17: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.
Page 18: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Matrix form

P’=P.R

cossin'

sincos'

yxy

yxx( 3)

cos sin

sin cosx y x y

Page 19: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Example 1

• A point (4, 3) is rotated by an angle of 45 degrees. Find the rotation matrix and resultant point.

• Rotate a line from A(0,0) to B(200,100) by 45 degrees.

• Rotate a polygon with coordinates A(2, 5),

B(7, 10), C(10, 2) by an angle of 45 degrees.

Page 20: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Write a C program to Rotate :

• A point

• A line

• A Rectangle

• A Polygon (Triangle)

Page 21: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.
Page 22: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.
Page 23: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Two-Dimensional(2D) Scaling• To alter the size of an object, we apply a scaling

transformation. A simple two-dimensional scaling operation is performed by multiplying object positions (x, y) by scaling factors sx and sy to produce the transformed coordinate .

• Scaling factors sx scales an object in the x coordinate.

),( rr yx'

'x

y

x x S

y y S

0

0x

y

Sx y x y

S

Page 24: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Properties of the scaling transformation.

• Any positive values can be assigned to the scaling factors sx and sy. Values less then 1 reduce the size of object, the object will close up the original at the same time. In contrast , enlarge the size of object.

• When sx and sy are assigned to the same values, a uniform scaling is produced which maintains relative object proportions.

Page 25: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Unequal values for sx and sy result in a differential scaling that is often used in design applications.

• Negative values can also be specified for the scaling parameters, this not only resizes an object, it reflects the object one or more of the coordinate axes.

Page 26: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.
Page 27: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Write a C++ program to scale :

• A point

• A line

• A Rectangle

• A Polygon (Triangle)

Page 28: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Point:cout<<“Enter x, y:”cin>>x>>y;cout<<“Enter sx,sy”cin>>sx>>sy;Initgraph(&gd,&gm,”..\\bgi”);putpixel(x,y,15);delay(100);putpixel(x*sx,y*sy,15);getch();closegraph();}

Page 29: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Scale a line:

line(x1,y1,x2,y2);

line(x1*sx,y1*sy,x2*sx,y2*sy);

Page 30: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Scale a rectangle:

rectangle(x1,y1,x2,y2);

rectangle(x1*sx,y1*sy,x2*sx,y2*sy);

Page 31: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Page 32: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Q. Scale the polygon with coordinates A(2,5) B(7,10) and C(10,2) by two units in x-direction and two units in y-direction and plot the graph.

Q. Scale the polygon with coordinates A(2,5) B(7,10) and C(10,2) by -2 units in x-direction and 3 units in y-direction and plot the graph.

Page 33: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Matrix Representations and Homogeneous Coordinates• It is well known that many application involves

sequences of geometric transformations. For example, an animation might require an object to be translated, rotated and scaled at each increment of the motion. If you want to first rotates an object, then scales it, you can combine those two transformation to a composite transformation like the following equation:

0 cos sincos sin*

0 sin cossin cosx x x

y y y

S S SA S R

S S S

Page 34: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• However, it will be difficult to deal with the above composite transformation and translation together. Because, translation is not 2 by 2 matrix representation.

• So ,here we consider how the matrix representations discussed in the previous sections can be reformulated so that such transformation sequences can be efficiently processed.

Page 35: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• In fact, we can expressed three basic two-dimensional transformation( translation, rotation, and scaling) in the general matrix form:

• Now this equation can be reformulated to eliminate the matrix addition operation using Homogeneous Coordinates.

21' MPMP

Page 36: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• What is Homogeneous Coordinates?• A standard technique for expanding each two-

dimensional coordinate position representation (x, y) to three-element representation , called Homogeneous Coordinates, where homogeneous h is a nonzero value such that

• • For geometric transformation, we can chose the

homogeneous parameter h to be any nonzero value. Thus there are an infinite number of equivalent homogeneous representations for each coordinate point (x, y) .

( , , )h hx y h

,h hx yx y

h h

Page 37: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• A convenient choice is simply to set h=1, so each two-dimensional position is then represented with homogeneous coordinate (x,y,1).

• Expressing positions in homogenous coordinates allows us to represent all geometric transformation equations as matrix multiplications, which is the standard method used in graphics systems. Two dimensional coordinate positions are represented with three-elements column vectors, and two-dimensional transformation operations are expressed as 3X3 matrices.

Page 38: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Homogeneous coordinate representation of 2D Translation

• This translation operation can be written in the abbreviated form

1100

10

01

1

y

x

ty

tx

y

x

' ( , )x yP T t t P

Page 39: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Homogeneous coordinate representation of 2D Rotation

' ( )P R P

This translation operation can be written in the abbreviated form

1100

0cossin

0sincos

1

y

x

y

x

Page 40: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Homogeneous coordinate representation of 2D Scaling

1100

00

00

1

y

x

sy

sx

y

x

' ( , )P S sx sy P

This scaling operation can be written in the abbreviatedform

Page 41: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Two-Dimensional Composite Transformation• Using matrix representations, we can set up a

sequence of transformation as a composite transformation matrix, by calculating the product of the individual transformations.

• And, since many positions in a scene are typically transformed by the same sequence, its is more efficient to first multiply the transformation matrices to form a single composite matrix.

• So the coordinate position is transformed using the composite matrix M, rather than applying the individual transformations M1 and then M2

'2 1P M M P

M P

Page 42: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

General Two-Dimensional Pivot-Point Rotation

(Rotation about an arbitrary point)

• So we can generate a 2D rotation about any other pivot point (x, y) by performing the following sequence of translate-rotate-translate operations.

(xr,yr)

(xr,yr)

(xr,yr)

(xr,yr)

Page 43: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• (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.• The composite transformation matrix for this

sequence is obtained with the concatenation:

Page 44: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

1 0 1 0 cos sin (1 cos ) sincos sin 0

0 1 sin cos 0 0 1 sin cos (1 cos ) sin

0 0 10 0 1 0 0 1 0 0 1

r r r r

r r r r

x x x y

y y y x

Page 45: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Problems:

• Perform the rotation of a point A(2,3) about point (1,1) by angle of 45 degrees.

• Perform the rotation of a point A(2,3), B(5,5), C(4,3) about point (1,1) by angle of 45 degrees.

Page 46: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Other 2D transformations:

• Reflection with respect to the axis

• • X axis • y axis

100

010

001

100

010

001

x

y 1

32

1’

3’2’x

y1

32

1’

3’ 2’

Page 47: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Reflection with respect to a line y=x

100

001

010

x

y

Page 48: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Shear• Two common shearing transformations are those

that shift coordinate x values and those that shift y values.

• An x-direction shear relative to the x axis is produced with the transformation matrix

100

010

01 xsh

x’ = x + shx · y, y’ = y

x

y

x

y

(0,0) (1,0)

(1,1)(0,1)

(0,0) (1,0)

(3,1)(2,1)

Page 49: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Y-Shear

100

01

001

Shy

x’ = x , y’ = y + shy*x

Page 50: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Thank You!!

Page 51: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

General 3D Rotations

(1) Rotating about an axis that is parallel to one of the coordinates axes.

• Step1, Translate the object so that the rotation axis coincides with the parallel coordinate axis.

• Step2, Perform the specified rotation about that axis.

• Step3, Translate the object so that rotation axis is moved back to its original.

Page 52: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• A coordinate position P is transformed with the sequence

' 1 ( )xP T R T P

Page 53: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• (2) Rotated about an axis that is not parallel to one of the coordinate axes.

• In this case, we also need rotation to align the rotation axis with a selected coordinate axis and then to bring the rotation axis back to its original orientation.

• A rotation axis can be defined with two coordinate position, or one position and direction angles (direction cosines ).

• Now we assume that the rotation axis is defined by two points, and that the direction of rotation is to be counter clockwise when looking along the axis from p2 to p1.

Page 54: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• The components of the rotation axis vector are then computed as:

• And the unit rotation-axis vector u is

• Where

2 1

2 1 2 1 2 1( , , )

V P P

x x y y z z

( , , )V

u a b cV

2 1 2 1 2 1, ,x x y y z z

a b cV V V

Page 55: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Step1. Translate the object so that the rotation axis passes through the coordinate origin

• Step2, Rotate the object so that the axis of rotation coincides with one of the coordinate axes.

• Step3, Perform the specified rotation about the selected coordinate axis

• Step4, Apply inverse rotations to bring the rotation axis back to its original orientation.

• Step5 ,Apply the inverse translation to bring the rotation axis to its original spatial position.

• we can transform the rotation axis onto any one of the three coordinate axes. But the z axis is often a convenient choice.

Page 56: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Page 57: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.
Page 58: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• 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. We move p1 to the origin.

Page 59: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• The next step we will put the rotation axis onto the z axis. We can use the coordinate-axis rotations to accomplish this alignment in two steps. For this example, we first rotate about the x axis, then rotate about y axis. The x axis rotation gets vector u into the x-z plane, and the y-axis rotation swings u around to the z axis.

x

z

yu

Page 60: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Since rotation calculations involve sine and cosine functions, so we can use standard vector operation 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.

• Firstly, we establish the transformation matrix for rotation around the x axis by determining the values for the sine and cosine of the rotation angle necessary to get u into the x-z plane.

Page 61: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Inverse Transformation

• To undo the applied transformation Inverse Transformation is applied.

• Inverse of T is T-1.

• T T-1=I (Identity Matrix)

Page 62: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Thank you !!!

Page 63: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Not required

Page 64: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Question 1: • If the rotation point is an arbitrary pivot position ,

can you give the correct rotation expression?

• How to rotate a line segment or a polygon?

),( rr yx

' ( ) cos ( )sin

' ( )sin ( )cosr r r

r r r

x x x x y y

y y x x y y

( 3)

Page 65: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Similarly, we can obtain the matrix representation of General 2D Fixed-Point Scaling.( question ).

• (1) Translate the object to so that the fixed point coincides with the coordinate origin.

• (2) Scale the object with respect to the coordinate origin.

• (3) Use the inverse of the translation in step (1) to return the object to its original position.

Page 66: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

100

)1(0

)1(0

100

10

01

100

00

00

100

10

01

yfy

xfx

f

fx

f

f

sys

sxs

y

x

s

s

y

x

y

Translate Scale Translate

(xr,y

r)(xr,yr)

(xr,yr)

(xr,yr)

yxffffyxff ssyxSyxTssSyxT ,,,, ,,

Page 67: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• We also obtain General 2D Scaling Directions.• Suppose we want to apply scaling factors with

values specified by parameters s1 and s2 in the directions shown in the following fig.

Page 68: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• To accomplish the scaling without changing the orientation of the object.(1) we perform a rotation so that the directions for s1 and s2 coincide with the x and y axes, respectively.

(2) Then the scaling transformation S(s1,s2) is applied.

(3) An opposite rotation to return points to their original orientations.

Page 69: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

100

0cossinsincos)(

0sincos)(sincos

)(),()( 22

2112

122

22

1

211

ssss

ssss

RssSR

Page 70: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• For example, we turn a unit square into a parallelogram by stretching it along the diagonal from (0,0) to (1,1).

x

y

(0,0)

(3/2,1/2)

(1/2,3/2)

(2,2)

x

y

(0,0) (1,0)

(0,1) (1,1)

Scale

Page 71: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• We first rotate the diagonal onto the y axis using angle 45 degree. Then we double its length with the scaling values s1=1 and s2=2, and then we rotate again to return the diagonal to its original orientation.

Page 72: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Matrix Concatenation Properties

• (1) Multiplication of matrices is associative.

• (2) Transformation products, on the other hand, may not be commutative.

Page 73: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Other 2D transformations:

• Reflection with respect to the axis

• • X axis • y axis • original point

100

010

001

100

010

001

100

010

001

x

y 1

32

1’

3’2’x

y1

32

1’

3’ 2

x

y

3

1’

3’ 2

1

2

Page 74: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Reflection with respect to a line

100

001

010

x

y

Page 75: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Shear• Two common shearing transformations are those

that shift coordinate x values and those that shift y values.

• An x-direction shear relative to the x axis is produced with the transformation matrix

100

010

01 xsh

x’ = x + shx · y, y’ = y

x

y

x

y

(0,0) (1,0)

(1,1)(0,1)

(0,0) (1,0)

(3,1)(2,1)

Page 76: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Any real number can be assigned to the shear parameter shx. A coordinate position (x, y) is then shifted horizontally by an amount proportional to its perpendicular distance ( y value ) from the x axis.

• We can generate x-direction shears relative to other reference lines with yref=-1.

• Now, coordinate positions are transformed as

x’ = x + shx · (y-yref), y’ = y

(3,1)

Page 77: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• The following Fig. illustrates the conversion of a square into a parallelogram with shy=0.5 and yref=-1.

100

010

1 refxx yshsh

x

y

x

y

(0,0) (1,0)

(1,1)(0,1)(1/2,0)

(3/2,0)

(2,1)(1,1)

(0,-1)

Page 78: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Shearing operations can be expressed as a sequences of basic transformations. Such as a series of rotation and scaling matrices

Page 79: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

General 3D Rotations

(1) Rotating about an axis that is parallel to one of the coordinates axes.

• Step1, Translate the object so that the rotation axis coincides with the parallel coordinate axis.

• Step2, Perform the specified rotation about that axis.

• Step3, Translate the object so that rotation axis is moved back to its original.

Page 80: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• A coordinate position P is transformed with the sequence

' 1 ( )xP T R T P

Page 81: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• (2) Rotated about an axis that is not parallel to one of the coordinate axes.

• In this case, we also need rotation to align the rotation axis with a selected coordinate axis and then to bring the rotation axis back to its original orientation.

• A rotation axis can be defined with two coordinate position, or one position and direction angles (direction cosines ).

• Now we assume that the rotation axis is defined by two points, and that the direction of rotation is to be counter clockwise when looking along the axis from p2 to p1.

Page 82: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• The components of the rotation axis vector are then computed as:

• And the unit rotation-axis vector u is

• Where

2 1

2 1 2 1 2 1( , , )

V P P

x x y y z z

( , , )V

u a b cV

2 1 2 1 2 1, ,x x y y z z

a b cV V V

Page 83: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Step1. Translate the object so that the rotation axis passes through the coordinate origin

• Step2, Rotate the object so that the axis of rotation coincides with one of the coordinate axes.

• Step3, Perform the specified rotation about the selected coordinate axis

• Step4, Apply inverse rotations to bring the rotation axis back to its original orientation.

• Step5 ,Apply the inverse translation to bring the rotation axis to its original spatial position.

• we can transform the rotation axis onto any one of the three coordinate axes. But the z axis is often a convenient choice.

Page 84: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Page 85: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.
Page 86: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• 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. We move p1 to the origin.

Page 87: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• The next step we will put the rotation axis onto the z axis. We can use the coordinate-axis rotations to accomplish this alignment in two steps. For this example, we first rotate about the x axis, then rotate about y axis. The x axis rotation gets vector u into the x-z plane, and the y-axis rotation swings u around to the z axis.

x

z

yu

Page 88: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• Since rotation calculations involve sine and cosine functions, so we can use standard vector operation 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.

• Firstly, we establish the transformation matrix for rotation around the x axis by determining the values for the sine and cosine of the rotation angle necessary to get u into the x-z plane.

Page 89: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• We need the angle between vector u and x-z plane .

• We directly calculate cosine and sine values of .

• If we represent the projection of u in the zoy plane as the vector

• Then the cosine of the rotation angle can be determined from the dot product of and then

unit vector along the z axis.

zz

xx

yy

' (0, , )u b c

'u

zu

'2 2

'cos ( )z

z

u u cd b c

du u

Page 90: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

Similarly, we can determine the sine of from the cross product of

So

' ' sinz x zu u u u u

'z xu u u b

' sinx z xu u u u b

sinb

d

Page 91: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• So the matrix elements for rotation of this vector about the x axis and into the xz plane:

1 0 0 01 0 0 0

0 00 cos sin 0

0 sin cos 00 0

0 0 0 10 0 0 1

x

c b

d dRb c

d d

Page 92: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• The rotation matrix about y axis is

cos 0 sin 0 0 0

0 1 0 0 0 1 0 0

sin 0 cos 0 0 0

0 0 0 1 0 0 0 1

y

d a

Ra d

Page 93: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

• The third step we have aligned the rotation axis with the positive z axis. The specified rotation angle we can now be applied as a rotation about the z axis

cos sin 0 0

sin cos 0 0

0 0 1 0

0 0 0 1

zR

zz

xx

yy

Page 94: 2D Transformation of Graphics Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change.

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

TRRRRRTR xyzyx )()()()()()( 111