You are on page 1of 8

Overview Geometric Transformations

2D Translation
Repositioning an object along a straight line path from one coordinate
2D and 3D location to another.
Translation Adding translation distances, tx and ty, to the original coordinate
Rotation position.
Scaling
Rigid-body transformation: x' = x + t x y' = y + t y
Moves object without deformation.
Homogeneous Coordinates
Coordinate Systems y y
Matrix form:

x ' x t x
y' = y + t ,
y
P' = P + T
Before translation x After translation x

Geometric Transformations Geometric Transformations


2D Rotation 2D Rotation
Repositioning an object along a circular path. Rotation about origin: Original polar coordinates:
Need a rotation angle and the position (xr, yr) of the pivot point which
the object is to be rotated about. x = r cos y = r sin
Positive rotation angles give counterclockwise rotation and negative
angles give clockwise rotation. After substitution:
x' = x cos y sin
Rotation equation about origin:
y y
y ' = x sin + y cos
x' = r cos( + ) =
Matrix form:
r cos cos r sin sin
x' cos sin x
y ' = r sin( + ) = = ,
r cos sin + r sin cos y' sin cos y
Before rotation x After rotation x
P' = R P
Geometric Transformations Geometric Transformations
2D Rotation 2D Rotation

Rotation about an arbitrary pivot point:


Rigid-body transformation
A line is rotated by applying the rotation equation to
After substitution: each of the line endpoints and redrawing the line
between the tow endpoints.
x' = xr + ( x xr ) cos ( y yr ) sin Polygons are rotated by moving each vertex through
y ' = yr + ( x xr ) sin + ( y yr ) cos the specified rotation angle and then redraw.
Curves are rotated by repositioning the defining
points and redrawing the curve.

Geometric Transformations Geometric Transformations


2D Scaling 2D Scaling
Alters the size of an object. Uniform scaling:
An object is scaled by multiplying the coordinates (x,y) of each vertex sx and sy have the same value.
by a scaling factor sx and sy. Differential scaling:
sx and sy can be any positive value. x' = x s x y' = y s y Unequal values of sx and sy.
Values < 1 reduces the size of the object. Scaling values < 1 moves the object closer to the origin.
Values > 1 produces and enlargement. Scaling values > 1 moves the object further away from the origin.
If sx and sy is 1, then the size is unchanged. Fixed point:
y y To control the location after scaling.
Matrix form: Coordinates for the fixed point (xf, yf) can be any vertices,

x ' s x 0 x
centroids or any other position.

y ' = 0 s y , x' = x s x + x f (1 s x )
xf(1-sx) and yf(1-sy) are constants for all
y points in the object.
y ' = y s y + y f (1 s y )
Before scaling x After scaling x P' = S P
Homogeneous Coordinates Homogeneous Coordinates
A 2D coordinate P1(x1,y1) lying in 3D can be represented as
Problem: P(x,y,z) = P(hx1,hy1,h).
Translation is addition and scaling and rotation are
multiplication of matrices. Given P(m,n,h) in homogeneous coordinates the cartesian coordinates
P' = P + T can be found by P(m/h,n/h,1).
P' = R P
Solved by: P' = S P Each point can have many
Using homogeneous coordinates instead of cartesian different homogeneous
coordinates. Then translation, scaling and rotation can be coordinate representations.
expressed in a general matrix form (multiplication).

2D Translation 2D Rotation
Homogeneous Coordinates Homogeneous Coordinates
x' 1 0 t x x x' cos sin 0 x
Matrix representation: y' = 0 1 t y , P' = T(tx,ty) P Matrix representation: y' = sin cos 0 y ,
y P' = R() P

1 0 0 1 1 1 0 0 1 1

The inverse translation matrix is obtained by replacing


The inverse rotation matrix is obtained by replacing by -.
tx and ty with -tx and -ty.

Two successive rotations:


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 cos 2 sin 2 0 cos1 sin 1 0 cos(1 + 2 ) sin (1 + 2 ) 0
2 1 2
sin cos 2 0 sin 1 cos 1 0 = sin (1 + 2 ) cos(1 + 2 ) 0
1

0 0 1 0 0 1 0 0 1 2
0 0 1 0 0 1 0 0 1
2D Scaling Composition of 2D
Homogeneous Coordinates Transformations
x' s x 0 0 x OpenGL provides a rotation function only about the origin.
Matrix representation: y' = 0 s 0 y , P' = S(sx,sy) P
y
To rotate an object about an arbitrary point (pivot point) we
1 0 0 1 1 need to do a sequence of three fundamental transformations.
1. Translate the pivot point to origin.
The inverse scaling matrix is obtained by replacing 2. Rotate about the origin.
sx and sy with 1/sx and 1/sy. 3. Translate the pivot point back to the original position.
Scaling from P to P' to P'': T(x1, y1) R() T(-x1, -y1) =
s x2 0 0 s x1 0 0 s x1 s x2 0 0 x1 (1 cos ) + y1 sin
1 0 x1 cos sin 0 1 0 x1 cos sin
0 0 0 0 = 0 s x1 s x2 0 0 1 y sin cos 0 0 1 y = sin cos

s y2

s y1
y1 (1 cos ) x1 sin
1 1
0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1

Composition of 2D Composition of 2D Transformation


Transformation Examples
Affine Transformation Shear Transformation
Distorts the shape of an object such that the transformed
Preserves parallelism of lines, but not lengths
shape appears as if the object were composed of internal
and angles. layer that had been caused to slide over each other.
Rotation, translation and reflection preserves
angles and lengths as well.
Shear and scaling preserves only parallelism.
These properties also applies to 3D.
x-direction shear of unit cube. y-direction shear of unit cube.

1 shx 0 1 0 0

SH x = 0 1 0, SH y = shy 1 0

0 0 1 0 0 1

3D Transformations
Reflection Transformation
3D Translation
Produces a mirror image of an object.
y
x-axis (y = 0) y
xy-plane x' 1 0 0 tx x
1 0 0 Original
1 0 0 y' 0 1 0 t y y P' = T P
0 1 0 0 1 0 A 4 by 4 homogenized matrix = ,
x

x z ' 0 0 1 tz z
0 0 1 1
0 0 1 Reflected 0 0 1 1 0

y-axis (x = 0) y xy-plane y

The inverse translation matrix is obtained by replacing


1 0 0 0 1 0
0 1 0 1 0 0 tx, ty and tz with -tx,-ty and -tz.

0 0 1 0 0 1
x x
3D Transformation 3D Transformations
3D Translation 3D Scaling
Each of the defining points are translated. x' s x 0 0 0 x
If the object is a polygon, each vertex of the y ' 0 sy 0 0 y P' = S P
polygon is translated. A 4 by 4 homogenized matrix = ,
z' 0 0 sz 0 z
1 1
1 0 0 0

(x',y',z')

T = (tx, ty, tz) The inverse scaling matrix is obtained by replacing


T = (tx, ty, tz)
(x,y,z) sx, sy and sz with 1/sx,1/sy and 1/sz.

3D Transformation 3D Transformation
3D Scaling 3D Rotation
Scaling with respect to a fixed position Rotation about z-axis Rotation about x-axis
sx 0 0 (1 s x )x f y
cos sin 0 1 0
(1 sy )y f
0 0 0
0 0 cos sin
T( x f , y f , z f ) S( s x , s y , s z ) T( x f , y f , z f ) =
sy 0 sin cos 0 0 0

0 0 sz (1 s z )z f 0 0 1 0 0 sin cos 0
0 0 1 1
0 0 1 0 0 z x 0 0 0

P' = Rz() P P' = Rx() P


y y y y Rotation about y-axis
y y
cos 0 sin 0
0 1 0 0
(xf,yf,zf) (xf,yf,zf)
(xf,yf,zf) (xf,yf,zf)
sin 0 cos 0
0 1
z x z x z x z x 0 0
z x z x
P' = Ry() P
Composition of 3D
Geometric Transformation Transformation
A transformation matrix of the form: (translation and rotation) Initial position y y
P3 Final position
r11 r12 r13 t x
r11 r12 t x r r P2
r r t or 21 22 r23 t y is called special orthogonal.
P3
P1 P1
21 22 y r31 r32 r33 t z
0 0 1
P2
0 0 0 1 It preserves angles and length. x x
The inverse is the transpose. z z

Each row vector in the matrix has 3 properties: Two ways to achieve the transformation:

1. Each is a unit vector 1. Compose the transformation T, Rx, Ry, Rz.


2. Each is perpendicular to the other 2. Using the properties of the orthogonal matrix.
3. The first and second vector will be rotated by R()
to lie on the positive x and y axes, respectively.

Composition of 3D Composition of 3D
Transformation Transformation
Create the rotation matrix by using cross product.
R = [r r r ] = 1 2
Done the same way as 2D composition. Rz will rotate into z-axis. T PP
z 1z 2z 3z
P1P2
1. Translate P1 to the origin PP PP
Rx = [r1x r2 x r 3 x ]
Rx will rotate into x-axis.
= 13 1 2
T
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) P1P3 P1P2
Ry will rotate into y-axis.
Rz Rx
R y = [r1 y r2 y r3 y ] =
4. Rotate about the z-axis (P1,P3 lies in the (y,z) plane) T
Rz Rx
The composite matrix will be r1x r2 x r3 x 0
Composite r1 y r2 y r3 y 0
T ( x1 , y1 , z1 ) = R T
Matrix r1z 0
Rz ( ) Rx ( ) R y ( 90 ) T ( x1 , y1 , z1 )
r2 z r3 z
0 0 0 1
Coordinate Systems

Right handed: Left handed:

y y

x x
z
Positive rotation is clockwise
Positive rotation gives
counterclockwise rotation

You might also like