Docsity

2D Transformation using C++, Slides of Computer science

Partial preview of the text

Download 2D Transformation using C++ and more Slides Computer science in PDF only on Docsity!

2D GEOMETRIC

TRANSFORMATI

ONS

Basic Transformation

BASIC TRANSFORMATION  We can reposition and resize two- dimensional objects by applying :  (^) Translation  (^) Rotation  (^) Scaling

TRANSLATION  We can express the translation equations as a single matrix equation by using column vectors to represent coordinate positions and the translation vector :  Also: P' = P + T

 ty

y

y'

T 

tx^ 

P 

x

, P ' 

x'

ROTATION  (^) A two-dimension rotation is applied to an object by repositioning it along a circular path in the xy plane.  To generate a rotation, we specify a rotation angle θ and the position (xr, yr) of the rotation point (or pivot point) about which the object is to be rotated.  Positive values for the rotation angle define counterclockwise rotations about the pivot point.  (^) Negative values rotate objects in the clock direction.

SCALING  A scaling transformation alters the size of an objects.  (^) This operation can be carried out for polygons by multiplying the coordinate values (x, y) of each vertex by scaling factors sx and sy to produce the transformed coordinates (x', y'): x' = x * sx, y' = y * sy  Scaling factor sx scales objects in the x direction, and sy in the y direction.

SCALING  Any positive numeric values can be assigned to the scaling factor sx and sy. Values <1, reduce the size of object. Values >1, enlarge the size of object. Both values = 1, unchanged size.  When sx and sy are assigned the same value, it is uniform scaling.  (^) Unequal values for sx and sy is, differential scaling.

MATRIX REPRESENTATION & HOMOGENEOUS COORDINATES  The basic transformations can be expressed in the general matrix form: P '  M 1  PM 2

  • (^) With coordinate positions P and P' represented as column vector.
  • (^) M1 is a 2x2 array matrix containing multiplicative factor,
  • (^) M2 is two-element column matrix containing translational terms.
  • (^) For translation, M1 is the identity matrix.
  • (^) For rotation or scaling, M2 contains the translational terms associated with the pivot point or scaling fixed point.

CONTINUED...  It produce a sequence of transformations with equation, such as scaling followed by rotation then translation.  A more efficient approach would be to combine the transformations so that the final coordinate position are obtained directly from the initial coordinates. It eliminates intermediate coordinates.  We can combine the multiplicate and translational terms for 2D geometric transformations into a single matrix representation by expanding 2x2 matrix to 3x3.

CONTINUED...  Expressing positions in homogeneous coordinates allow us to represent all geometric transformation equations as matrix multiplications.  Coordinates are represented with three- element column vector, and transformation operations are written as 3x3 matrices.

FOR TRANSLATION P '  T ( t (^) x , t (^) y )  P  (^) The inverse of the translation matrix is obtained by replacing the translation parameters tx and ty with –tx and –ty.  y y (^)    x      x^      1   1    ^0  1 0 t   0 1 t 0   1   y 1  (^) x 1 

FOR SCALING P '  S ( s (^) x , s (^) y )  P  The inverse scaling matrix is replacing sx and sy by 1/sx and 1/sy. y x        s     0   0 1   1   0 s 0  y (^0)   x (^)  0   1   y 1   (^) x 1 

THANK

YOU