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

Lecture 6 Geometric transformations

The document discusses 2D geometric transformations, which are operations that modify an object's position, orientation, or size without redrawing it. It covers basic transformations such as translation, rotation, scaling, reflection, and shear, along with their mathematical representations and properties. Additionally, it introduces homogeneous coordinates for efficient transformation handling and emphasizes the importance of transformation order in composite transformations.

Uploaded by

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

Lecture 6 Geometric transformations

The document discusses 2D geometric transformations, which are operations that modify an object's position, orientation, or size without redrawing it. It covers basic transformations such as translation, rotation, scaling, reflection, and shear, along with their mathematical representations and properties. Additionally, it introduces homogeneous coordinates for efficient transformation handling and emphasizes the importance of transformation order in composite transformations.

Uploaded by

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

GEOMETRIC

TRANSFORMATIONS
CCS 2208 COMPUTER GRAPHICS
2D Geometric Transformations
• What are geometric transformations?
• Operations that are applied to the geometric description of an
object to change its position, orientation, or size.
• Why the transformation is needed?
• To manipulate the initially created object and to display the
modified object without having to redraw it.
• 2 ways
• Object Transformation
• Alter the coordinates descriptions of an object
• Translation, rotation, scaling etc.
• Coordinate system unchanged
• Coordinate transformation
• Produce a different coordinate system
2D Geometric Transformations
• Basic Transformations
• Translation
• Rotation
• Scaling
• Other transformations
• Reflection
• Shear
Translation
• A translation moves all points in
an object along the same
straight-line path to new
positions.
• The path is represented by a ?
vector, called the translation or
shift vector.
ty=4
• We can write the components:
p'x = px + tx tx = 6
(2, 2)
p'y = py + ty
• or in matrix form:
P' = P + T Adding or subtracting a value to or
x’ x tx from a coordinate translates it in
y’ = y + ty space.
Translation (55,60)
x x  tx
y y  t y
(20,35)

(45,30)
(65,30)

x’ 10 35 45
y’ = 5 + 25 = 30
(10,5) (30,5)

Specifying a 2D-Translation in OpenGL:


glTranslatef(tx, ty, 0.0);
(The z component is set to 0 in 2D translation
Rotation
• A rotation repositions all
points in an object along a
circular path in the plane
centered at the pivot point.

• Parameters for the 2D rotation


are the rotation angle θ and a
position (xr , yr ), called the
rotation point (or pivot point.
Rotation
• Review Trigonometry
=> cos  = x/r , sin = y/r
• x = r. cos , y = r.sin 
=> cos (+ ) = x’/r
• x’ = r. cos (+ )
• x’ = r.coscos - r.sinsin y’
• x’ = x.cos  – y.sin 

y
=>sin (+ ) = y’/r
y’ = r. sin (+ ) x
• y’ = r.cossin + r.sincos x’  -Phi
• y’ = x.sin  + y.cos   -Theta
Rotation
• We can write the components:
p'x = px cos  – py sin 
p'y = px sin  + py cos 
• or in matrix form:
P' = R • P
• A positive value for the angle θ defines a counterclockwise
rotation about the pivot point, as in our example, and a
negative value rotates objects in the clockwise direction

• Rotation matrix
 cos   sin  
R 
 sin  cos  
Rotation
• Example
• Find the transformed point, P’, caused by rotating
P= (5, 1) about the origin through an angle of 90.
 cos   sin    x   x cos   y sin  
 sin     
 cos    y   x sin   y cos  

 5 cos 90  1 sin 90


 
 5 sin 90  1 cos 90 
 5 0  1 1
 
 5 1  1 0 
  1
 
 5
Scaling
• Scaling changes the size of an
object and involves two scale
factors, Sx and Sy for the x and y P’

coordinates respectively.
• Scales are about the origin.
• We can write the components:
p'x = sx • px P
p'y = sy • py

or in matrix form: P' = S • P


 sx 0
Scale matrix as: S  
0 sy 
Scaling
• If the scale factors are in P’
between 0 and 1, the points will
be moved closer to the origin 
the object will be smaller.
• Example : P(2, 5)
• P(2, 5), Sx = 0.5, Sy = 0.5
• Find P’ ?
• If the scale factors are larger than
1, the points will be moved away P’
from the origin  the object will be
larger.
• Example :
• P(2, 5), Sx = 2, Sy = 2
• Find P’ ?
Scaling
• If the scale factors are the same, Sx = Sy  uniform
scaling which maintains relative object proportions. Only
change in size.
• If Sx  Sy  differential scaling. Change in size and
shape

• Example : square  rectangle


• P(1, 3), Sx = 2, Sy = 5 , P’ ?

• In some systems, negative values can also be specified for


the scaling parameters. This not only resizes an object, it
reflects it about one or more of the coordinate axes
Homogenous Coordinates
y y
w
x 
x

• Let’s move our problem into 3D.


• Let point (x, y) in 2D be represented by point (x, y, 1) in the
new space.
• Scaling our new point by any value a puts us somewhere
along a particular line: (ax, ay, a).
• A point in 2D can be represented in many ways in the new
space.
• (2, 4) ---------- (8, 16, 4) or (6, 12, 3) or (2, 4, 1) or etc.
Homogenous Coordinates
• We can always map back to the original 2D point by dividing by
the last coordinate
• (15, 6, 3) --- (5, 2).
• (60, 40, 10) - ?.
• The fact that all the points along each line can be mapped back to
the same point in 2D gives this coordinate system its name –
homogeneous coordinates.
• In this way a point in 2D space is expressed in three-dimensional
homogeneous coordinates.
• This technique of representing a point in a space whose dimension
is one greater than that of the point is called homogeneous
representation.
• It provides a consistent, uniform way of handling affine
transformations.
Homogeneous Coordinates
•If we use homogeneous coordinates, the geometric
transformations given above can be represented using only a
matrix pre-multiplication.
•A convenient choice is simply to set h = 1

Cartesian Homogeneous Point in column-vector:


( x, y ) 
  ( xh, yh, h), h 0 x
y
 a b 1
 ,    ( a, b, c), c 0
 c c
Examples: (5, 8) (15, 24, 3)
(x, y) (x, y, 1)
Homogeneous Coordinates
Matrix Representation

 x  1 0 t x   x 
 y  0 1 t   y  , P T t , t P
2D Translation
   y    x y
 1   0 0 1   1 

 x  cos   sin  0  x 


2D Rotation  y  sin  cos  0   y  , P R   P
  
 1   0 0 1   1 

 x  S x 0 0  x 
2D Scaling  y  0 S y 0   y  , P S Sx , S y  P
 
 1   0 0 1   1 
Homogeneous Transform Advantages
• Unified view of transformation as matrix multiplication
• Easier in hardware and software

• To compose transformations, simply multiply matrices


• Order matters: AB is generally not the same as BA

• Allows for non-affine transformations:


• Perspective projections!
• Bends, tapers, many others
Reflection
• A transformation that produces a mirror image of an object.
• Axis of reflection
• A line in the xy plane
• A line perpendicular to the xy plane
• The mirror image is obtained by rotating the object 1800
about the reflection axis.
• Rotation path
• Axis in xy plane: the rotation path about this axis is in a
plane perpendicular to the xy plane.
• Axis perpendicular to xy plane:the rotation path about
this axis is in the xy plane.
Reflection
• Reflection about the x axis
• Reflection about the line y = 0
• It retains x values, but “flips” the y values of coordinate
positions

y =  y
Reflection
• Reflection about the y axis
• A reflection about the line x = 0 (the y axis)
• It flips x coordinates while keeping y coordinates the same

x =  x
Reflection
• Reflection relative to the coordinate origin
• We flip both the x and y coordinates of a point by reflecting
relative to an axis that is perpendicular to the xy plane and
that passes through the coordinate origin

x =  x
y =  y
Reflection
• Reflection of an object relative to an axis
perpendicular to the xy plane through Preflect
Reflection
• Reflection about the line y = x
Reflections

Reflection about x: glScalef(1, -1, 1);


Reflection about y: glScalef(-1, 1, 1);
Reflection about origin: glScalef(-1, -1, 1);
Shear

x   x  hx y
y y

•A shear transformation in the x-direction (along x) shifts the


points in the x-direction proportional to the y-coordinate.

•The y-coordinate of each point is unaffected.


Shear
• The x-direction shear relative to x axis

 1 shx 0 x '  x  shx y


0 1 0
  y'  y
 0 0 1
If shx = 2:
General Properties
Preserved Attributes
Line Angle Distance Area

Translation Yes Yes Yes Yes

Rotation Yes Yes Yes Yes

Scaling Yes No No No

Reflection Yes Yes Yes Yes

Shear Yes No No Yes


Concatenation
• Using matrix representations, we can set up a sequence of
transformations as a composite transformation matrix by
calculating the product of the individual transformations.
• Forming products of transformation matrices is referred to
as a concatenation, or composition, of matrices.
• Because a coordinate position is represented with a
homogeneous column matrix, we must premultiply the
column matrix by the matrices representing any
transformation sequence.
• Many positions in a scene are typically transformed by the
same sequence, it is more efficient to first multiply the
transformation matrices to form a single composite matrix
Concatenation Properties
• Matrix multiplication is associative.
A·B ·C = (A·B )·C = A·(B ·C)

• Transformation products may not be commutative


• Be careful about the order in which the composite matrix
is evaluated.
• Except for some special cases:
• Two successive rotations
• Two successive translations
• Two successive scalings
• rotation and uniform scaling
Order of Transformations
In composite transformations, the order of transformations
is very important.
Rotation followed by Translation:

Translation followed by Rotation:


Affine Transformations
• A coordinate transformation of the form
x’=axxx+axyy+bx, y’=ayxx+ayyy+by

• x’ and y’ is a linear function of the original coordinates x


and y.
• aij and bk are constants determined by the transformation
type.

• Translation, rotation, scaling, reflection, and shear are


two-dimensional affine transformations.
• An affine transformation involving only rotation,
translation, and reflection preserves angles and lengths.
Affine Transformation
A general invertible, linear, transformation.

x  a1 x  b1 y  c1
y  a 2 x  b2 y  c2
(a1b2  a 2 b1 0)

Transformation Matrix:

 a1 b1 c1 
a b2 c 2 
 2
 0 0 1 
Affine Transformation: Properties
• Product of affine transformations is affine.

• Affine transformations preserve linearity of segments.

• Affine transformations preserve parallelism between


lines.

• Affine transformations are invertible.


Why Affine Transformations?
• Affine transformations are linear
• Transforming all the individual points on a line gives the
same set of points as transforming the endpoints and
joining them

• Interpolation is the same in either space: Find the


halfway point in one space, and transform it. Will get the
same result if the endpoints are transformed and then
find the halfway point
Geometric Transformations by Rasterization
• The transformed shape needs to be filled.
• A whole scan-line filling is usually in order.

• However, simple transformations can save new filling by


manipulating blocks in the frame buffer.

Pmax

Pmin
P0

Translation:
Move block of pixels of frame buffer into new destination.
90° counterclockwise rotation

 1 2 3   12 11 10 
 4 5 6   3 6 9 12   9 8 7 
  2 5 8 11 
 7 8 9     6 5 4 
   1 4 7 10   
 10 11 12   3 2 1 

180° rotation

Rotated pixel block


Destination pixel array

RGB of destination pixel can


be determined by averaging
rotated ones (as antialiasing)

You might also like