You are on page 1of 8

Overview

Geometric Transformations 2D Translation


Repositioning an object along a straight line path from one coordinate location to another. Adding translation distances, tx and ty, to the original coordinate position. x' = x + t x y' = y + t y Rigid-body transformation: Moves object without deformation.
y y

2D and 3D

Translation Rotation Scaling

Homogeneous Coordinates Coordinate Systems

Matrix form: x ' x t x y' = y + t , y

Before translation x

After translation x

P' = P + T

Geometric Transformations 2D Rotation


Repositioning an object along a circular path. Need a rotation angle and the position (xr, yr) of the pivot point which the object is to be rotated about. Positive rotation angles give counterclockwise rotation and negative angles give clockwise rotation.
y y

Geometric Transformations 2D Rotation


Rotation about origin: Original polar coordinates:
x = r cos y = r sin

After substitution: x' = x cos y sin y ' = x sin + y cos Matrix form: x' cos sin x , = y' sin cos y P' = R P

Rotation equation about origin: x' = r cos( + ) = r cos cos r sin sin y ' = r sin( + ) = r cos sin + r sin cos

Before rotation

After rotation

Geometric Transformations 2D Rotation

Geometric Transformations 2D Rotation

Rotation about an arbitrary pivot point: After substitution: x' = xr + ( x xr ) cos ( y yr ) sin y ' = yr + ( x xr ) sin + ( y yr ) cos

Rigid-body transformation A line is rotated by applying the rotation equation to each of the line endpoints and redrawing the line between the tow endpoints. Polygons are rotated by moving each vertex through the specified rotation angle and then redraw. Curves are rotated by repositioning the defining points and redrawing the curve.

Geometric Transformations 2D Scaling


Alters the size of an object. An object is scaled by multiplying the coordinates (x,y) of each vertex by a scaling factor sx and sy. x' = x s x y' = y s y sx and sy can be any positive value.
Values < 1 reduces the size of the object. Values > 1 produces and enlargement. If sx and sy is 1, then the size is unchanged.
y y

Geometric Transformations 2D Scaling


Uniform scaling:
sx and sy have the same value.

Differential scaling:
Unequal values of sx and sy.

Scaling values < 1 moves the object closer to the origin. Scaling values > 1 moves the object further away from the origin. Fixed point:

Matrix form: x ' s x 0 x y ' = 0 s y , y

To control the location after scaling. Coordinates for the fixed point (xf, yf) can be any vertices, centroids or any other position. xf(1-sx) and yf(1-sy) are constants for all x' = points in the object.

x s x + x f (1 s x )

Before scaling

After scaling

P' = S P

y ' = y s y + y f (1 s y )

Homogeneous Coordinates
Problem:

Homogeneous Coordinates
A 2D coordinate P1(x1,y1) lying in 3D can be represented as P(x,y,z) = P(hx1,hy1,h). Given P(m,n,h) in homogeneous coordinates the cartesian coordinates can be found by P(m/h,n/h,1). Each point can have many different homogeneous coordinate representations.

Translation is addition and scaling and rotation are multiplication of matrices.


P' = P + T P' = R P P' = S P

Solved by:

Using homogeneous coordinates instead of cartesian coordinates. Then translation, scaling and rotation can be expressed in a general matrix form (multiplication).

2D Translation Homogeneous Coordinates


x' 1 0 t x x Matrix representation: y' = 0 1 t y , y 1 0 0 1 1

2D Rotation Homogeneous Coordinates


x' cos sin 0 x Matrix representation: y' = sin cos 0 y , 0 1 1 1 0

P' = T(tx,ty) P

P' = R() P

The inverse translation matrix is obtained by replacing tx and ty with -tx and -ty.
1 0 t x2 1 0 t x1 1 0 t x1 + t x2 Translating from P to P' to P'':0 1 t y 0 1 t y = 0 1 t y + t y 2 1 1 2 1 0 0 1 0 0 1 0 0

The inverse rotation matrix is obtained by replacing by -. Two successive rotations:


cos 2 sin 2 0 cos1 sin 1 0 cos(1 + 2 ) sin (1 + 2 ) 0 sin cos 2 0 sin 1 cos 1 0 = sin (1 + 2 ) cos(1 + 2 ) 0 2 0 1 0 0 1 0 0 1 0

2D Scaling Homogeneous Coordinates


x' s x 0 0 x Matrix representation: y' = 0 s 0 y , y 1 0 0 1 1

Composition of 2D Transformations

P' = S(sx,sy) P

The inverse scaling matrix is obtained by replacing sx and sy with 1/sx and 1/sy. Scaling from P to P' to P'':
s x2 0 0 0 s y2 0 0 s x1 0 0 1 0 0 s y1 0 0 s x1 s x2 0 = 0 1 0 0 s x1 s x2 0 0 0 1

OpenGL provides a rotation function only about the origin. To rotate an object about an arbitrary point (pivot point) we need to do a sequence of three fundamental transformations. 1. Translate the pivot point to origin. 2. Rotate about the origin. 3. Translate the pivot point back to the original position.
T(x1, y1) R() T(-x1, -y1) =

1 0 x1 cos sin 0 1 0 x1 cos sin 0 1 y sin cos 0 0 1 y = sin cos 1 1 0 1 0 0 1 0 0 0 0 1 0

x1 (1 cos ) + y1 sin y1 (1 cos ) x1 sin 1

Composition of 2D Transformation

Composition of 2D Transformation Examples

Affine Transformation

Shear Transformation

Preserves parallelism of lines, but not lengths and angles. Rotation, translation and reflection preserves angles and lengths as well. Shear and scaling preserves only parallelism. These properties also applies to 3D.

Distorts the shape of an object such that the transformed shape appears as if the object were composed of internal layer that had been caused to slide over each other.

x-direction shear of unit cube.

y-direction shear of unit cube.

1 shx 0 0 1 0, SH x = 0 0 1

1 0 0 SH y = shy 1 0 0 0 1

Reflection Transformation

3D Transformations 3D Translation
x' 1 y' 0 A 4 by 4 homogenized matrix = z ' 0 1 0 0 0 tx x 1 0 t y y P' = T P , 0 1 tz z 0 0 1 1

Produces a mirror image of an object.


y

x-axis (y = 0) 1 0 0 0 1 0 0 0 1 y-axis (x = 0) 1 0 0 0 1 0 0 0 1

Original
x

Reflected

xy-plane 1 0 0 0 1 0 0 0 1 xy-plane
0 1 0 1 0 0 0 0 1
y

The inverse translation matrix is obtained by replacing tx, ty and tz with -tx,-ty and -tz.

3D Transformation 3D Translation

3D Transformations 3D Scaling
x' s x y ' 0 A 4 by 4 homogenized matrix = z' 0 1 0 0 sy 0 0 0 0 sz 0 0 x 0 y P' = S P , 0 z 1 1

Each of the defining points are translated. If the object is a polygon, each vertex of the polygon is translated.

(x',y',z') (x,y,z)

T = (tx, ty, tz)

T = (tx, ty, tz)

The inverse scaling matrix is obtained by replacing sx, sy and sz with 1/sx,1/sy and 1/sz.

3D Transformation 3D Scaling
Scaling with respect to a fixed position sx 0 T( x f , y f , z f ) S( s x , s y , s z ) T( x f , y f , z f ) = 0 0 0 sy 0 0 0 0 sz 0

3D Transformation 3D Rotation
(1 s x )x f
Rotation about z-axis

(1 sy )y f
(1 s z )z f
1

cos sin sin cos 0 0 0 0

Rotation about x-axis

0 0 1 0

0 0 0 1

0 0 1 0 cos sin 0 sin cos 0 0 0

0 0 0 1

P' = Rz() P
y y y y

P' = Rx() P
y y

Rotation about y-axis

(xf,yf,zf)

(xf,yf,zf)

(xf,yf,zf) z x z

(xf,yf,zf) x

cos 0 sin 0

0 sin 0 1 0 0 0 cos 0 0 0 1

P' = Ry() P

Geometric Transformation
A transformation matrix of the form: (translation and rotation) r11 r12 r13 t x r11 r12 t x r r r r t or 21 22 r23 t y is called special orthogonal. 21 22 y r31 r32 r33 t z 0 0 1 0 0 0 1 It preserves angles and length. The inverse is the transpose. Each row vector in the matrix has 3 properties: 1. Each is a unit vector 2. Each is perpendicular to the other 3. The first and second vector will be rotated by R() to lie on the positive x and y axes, respectively. Initial position

Composition of 3D Transformation
y
P3 P2 P1

y
P3 P1 P2

Final position

x z

Two ways to achieve the transformation: 1. Compose the transformation T, Rx, Ry, Rz. 2. Using the properties of the orthogonal matrix.

Composition of 3D Transformation
Done the same way as 2D composition. 1. Translate P1 to the origin 2. Rotate about the y-axis (P1,P2 lies in the (y,z) plane) 3. Rotate about the x-axis (P1,P2 lies on the z-axis) 4. Rotate about the z-axis (P1,P3 lies in the (y,z) plane) The composite matrix will be

Composition of 3D Transformation
Create the rotation matrix by using cross product. PP T Rz will rotate into z-axis. R = [r r r ] = 1 2
z 1z 2z 3z T

Rx will rotate into x-axis. Ry will rotate into y-axis.


r1x Composite r1 y Matrix r1z 0 r2 x r2 y r2 z 0 r3 x r3 y r3 z 0

Rx = [r1x r2 x r 3 x ]

P1P2 PP PP = 13 1 2 P1P3 P P2 1 Rz Rx Rz Rx

R y = [r1 y r2 y r3 y ] =
T

Rz ( ) Rx ( ) R y ( 90 ) T ( x1 , y1 , z1 )

0 0 T ( x1 , y1 , z1 ) = R T 0 1

Coordinate Systems
Right handed:
y

Left handed:
y z

x z

Positive rotation is clockwise

Positive rotation gives counterclockwise rotation

You might also like