Lecture05 Transformation

download Lecture05 Transformation

of 62

Transcript of Lecture05 Transformation

  • 8/12/2019 Lecture05 Transformation

    1/62

    Com uter Gra hics

    Chapter 5

    Geometric Transformations

    Somsak Walairacht, Computer Engineering, KMITL 1

  • 8/12/2019 Lecture05 Transformation

    2/62

    Outline

    Basic Two-Dimensional Geometric Transformations Matrix Representations and Homogeneous

    Inverse Transformations

    wo-Dimensional Composite ransformations

    Other Two-Dimensional Transformations

    Raster Methods for Geometric Transformations

    pen as er rans orma ons Transformations between Two-Dimensional

    Coordinate Systems

    201074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    3/62

    Outline (2)

    Geometric Transformations in Three-DimensionalSpace

    Rotation

    Scaling -

    Other Three-Dimensional Transformations

    ransformations between hree-DimensionalCoordinate Systems

    Affine Transformations

    301074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    4/62

    Introduction

    Operations that are applied to the geometricdescription of an object to change its position,orientation, or size are called geometrictransformations

    Sometimes geometric-transformation operations arealso referred to as modeling transformations

    A distinction between the two Modeling transformations are used to construct a scene or to

    give the hierarchical description of a complex object that is

    Geometric transformations describe how objects might movearound in a scene during an animation sequence or simplyto view them from another angle

    401074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    5/62

    Basic Two-DimensionalGeometric ransformations

    Available in all graphics packages are

    Rotation

    Other useful transformation routines are

    e ec on Shearing

    501074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    6/62

    wo-Dimensional Translation

    To translate a two-dimensional position, we add translationdistances tx and ty to the original coordinates (x, y) to obtain thenew coordinate position (x, y)

    Translation is a rigid-body transformation that moves objects

    6

    w ou e orma on

    01074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    7/62

    Polygon Translation

    A polygon is translated similarly Adding a translation vector to the coordinate

    position of each vertex and then regenerate

    the polygon using the new set of vertex

    701074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    8/62

    wo-Dimensional Rotation

    A rotation transformation is generated by specifying arotation axis and a rotation angle

    (xr, yr) called the rotation point (or pivot point),about which the object is to be rotated

    A ositive value for the an le defines a

    counterclockwise rotation about the pivot point

    801074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    9/62

    wo-Dimensional Rotation (2)

    Let r is the constant distance of the pointfrom the origin, angle is the original angular,

    is the rotation angle

    901074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    10/62

    Rotation about Arbitrary Point

    Transformation equations for rotation of a pointabout any specified rotation position (xr, yr)

    Rotations are ri id bod transformations that move

    10

    objects without deformation

    01074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    11/62

    wo-Dimensional Scaling

    A simple two-dimensional scaling operation is performed bymultiplying object positions (x, y) by scaling factors sx and sy toproduce the transformed coordinates (x, y)

    ,

    1101074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    12/62

    Scaling by a Fixed Point

    Coordinates for the fixed point, (xf, y

    f), are often chosen at

    some object position, such as its centroid Objects are now resized by scaling the distances between object

    where the additive terms xf(1sx) andyf(1sy) are constants for all points in the object

    1201074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    13/62

    Matrix Representations andHomogeneous Coordinates

    Many graphics applications involve sequencesof geometric transformations

    An animation might require an object to be

    translated and rotated at each increment of the

    The viewing transformations involve sequences oftranslations and rotations to take us from the

    original scene specification to the display on anoutput device

    1301074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    14/62

    Matrix Representations andHomogeneous Coordinates

    Matrix M1 is a 2x2 array containing multiplicative, 2 -

    containing translational terms

    Multiplicative and translational terms can becom ne nto a s ng e matr x we expan t erepresentations to 3x3

    A three-element re resentation x , , h , called

    homogeneous coordinates, where the homogeneousparameter h is a nonzero value such that

    1401074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    15/62

    Matrix Representations andHomogeneous Coordinates

    Two-Dimensional Translation Matrix

    Rotation Matrix

    1501074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    16/62

    Inverse Transformations

    Inverse translation matrix Translate in the opposite direction

    Inverse rotation matrix

    Inverse scaling matrix

    1601074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    17/62

    Two-Dimensional Compositeransformations

    Forming products of transformation matrices is oftenreferred to as a concatenation, or composition, of

    We do premultiply the column matrix by the matrices

    representing any transformation sequence nce many pos t ons n a scene are typ ca y

    transformed by the same sequence, it is moreefficient to first multiply the transformation matrices

    to orm a sing e composite matrix

    1701074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    18/62

    Composite Two-Dimensionalranslations

    If two successive translation vectors (t1x

    , t1y

    ) and (t2x

    , t2y

    ) areapplied to a 2-D coordinate position P, the final transformedlocation P is

    The composite transformation matrix for this sequence oftranslations is

    1801074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    19/62

    Composite Two-DimensionalRotations

    Two successive rotations applied to a point P

    We can verify that two successive rotations are

    additive:

    e compos on ma r x

    1901074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    20/62

    Composite Two-DimensionalScalings

    For two successive scaling operations in-

    scaling matrix

    2001074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    21/62

    General Two-DimensionalPivot-Point Rotation

    Graphics package provides only a rotatefunction with respect to the coordinate

    To generate a 2-D rotation about any other

    pivot point (xr, yr), follows the sequence ofrans a e-ro a e- rans a e opera ons1. Translate the object so that the pivot-point

    position is moved to the coordinate origin

    2. Rotate the object about the coordinate origin3. Translate the object so that the pivot point is

    returned to its original position

    2101074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    22/62

    General Two-DimensionalPivot-Point Rotation (2)

    2201074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    23/62

    General Two-DimensionalFixed-Point Scaling

    1. Translate the object so that the fixed point coincides with thecoordinate origin

    2. Scale the object with respect to the coordinate origin3. se e nverse o e rans a on n s ep o re urn e

    object to its original position

    2301074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    24/62

    General Two-DimensionalScaling Directions

    To accomplish the scaling without changing theorientation of the object1. Performs a rotation so that the directions for s and s

    coincide with the x and y axes2. Scaling transformation S(s1, s2) is applied

    3. An opposite rotation to return points to their original

    2401074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    25/62

    Example of Scalingransformation

    Turn a unit square into a parallelogram by stretchingit along the diagonal from (0, 0) to (1, 1)

    Double its length with the scaling values s1=1 and s2=2

    Rotate again to return the diagonal to its original orientation

    2501074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    26/62

    Matrix ConcatenationProperties

    Multiplication of matrices is associative

    Depending upon the order in which the transformations

    by multiplying from left-to-right (premultiplying) - -

    In OpenGL's convention: V'=B*(A*V), V'=(B*A)*V, C=B*A; V'=C*V;

    In DX's convention: V'=(V*A)*B, C=A*B; V'=V*C;

    2601074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    27/62

  • 8/12/2019 Lecture05 Transformation

    28/62

    General Two-Dimensional Composite

    Efficiency

    . ,additions

    Actually, only 4 multiplications and 4 additions

    Once matrix is concatenated, it is maximum number of

    Without concatenation, individual transformations would beapplied one at a time, and the number of calculations couldbe significantly increased

    2801074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    29/62

    Computational Efficiency (2)

    Rotation calculations require trigonometricevaluations and several multiplications

    consideration in rotation transformations

    For small enough angles (less than 10), cosisapprox mate y . an s n as a va ue very c ose tothe value of in radians

    2901074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    30/62

    Computational Efficiency (3)

    Composite transformations ofteninvolve inverse matrices

    Operations are much simpler than direct

    inverse matrix calculations Inverse translation matrix is obtained by

    changing the signs of the translation

    Inverse rotation matrix is obtained by

    30

    01074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    31/62

    Two-Dimensional Rigid-Bodyransformation

    All angles and distances between coordinatepositions are unchanged by therans orma on

    Upper-left 2x2 submatrix is an orthogonal

    Two row vectors (rxx, rxy) and (ryx, ryy) (or the twocolumn vectors) form an orthogonal set of unit

    vec ors Set of vectors is also referred to as an

    orthonormal vector set

    3101074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    32/62

    Two-Dimensional Rigid-Bodyransformation (2)

    Each vector has unit length

    If these unit vectors are transformed by the rotation sub-matrix, then

    Example,

    3201074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    33/62

    Constructing Two-DimensionalRotation Matrices

    The orthogonal property of rotation matrices is useful for

    constructing the matrix when we know the final orientation ofan object

    ,matrix within objects co-or system when knowing its orientationwithin overall word co-or system

    3301074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    34/62

    Other Two-Dimensionalransformations

    Reflection

    3401074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    35/62

    Reflection

    Reflection about the liney = 0 (the x axis) is

    A reflection about theline x = 0 (the y axis)w

    transformation matrixx r w

    keeping y coordinates

    the same

    3501074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    36/62

    Reflection (2)

    Reflection relative tothe coordinate origin

    Reflection axis as thediagonal line y = x

    3601074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    37/62

    Shear

    A transformation that distorts the shape of an object The transformed shape appears as if the object were

    slide over each other An x-direction shear relative to the x axis

    3701074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    38/62

    Shear (2)

    x-direction shears relative to other reference lines

    y-direction shear relative to the line x = xref

    3801074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    39/62

    Raster Methods for Geometricransformations

    All bit settings in the rectangular area shown are copied as a block into

    another part of the frame buffer

    Rotate a two-dimensional object or pattern 90 counterclockwise byreversin the ixel values in each row of the arra then interchan in

    rows and columns

    3901074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    40/62

    Raster Methods for Geometricransformations (2)

    For array rotations that are not multiples of90, we need to do some extra processing

    Similar methods to scale a block of pixels

    4001074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    41/62

    ransformations between Two-Dimensional Coordinate Systems

    Computer-graphics applications involve coordinate

    transformations from one reference frame to another duringvarious stages of scene processing

    - -1. Translate so that the origin (x0, y0) of the xy system is moved to

    the origin (0, 0) of the xy system

    2. Rotate the x axis onto the x axis

    4101074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    42/62

    Transformations between 2-DCoordinate Systems (2)

    Alternative method Specify a vector V that indicates the direction for the

    Obtain the unit vector u along the x axis by applying

    a 90 clockwise rotation to vector v

    set of orthonormal vectors

    4201074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    43/62

    Geometric Transformations inhree-Dimensional Space

    A position P=(x, y, z) in 3-D is translated to alocation P=(x, y, z) by adding translation distancestx, t , and tz

    4301074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    44/62

    3-Dimensional Rotation

    -

    4401074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    45/62

    3-Dimensional Rotation (2)

    Transformation equations for rotations about theother two coordinate axes can be obtained with acyclic permutation of the coordinate parameters x, y,and z

    x y z x

    4501074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    46/62

    3-Dimensional Rotation (3)

    x-axis rotation

    y-axis rotation

    4601074410 / 13016218 Computer Graphics

    h l

  • 8/12/2019 Lecture05 Transformation

    47/62

    Composite Three-Dimensionalransformations

    A rotation matrix for any axis that does notcoincide with a coordinate axis

    1. Translate the object so that the rotation axiscoincides with the parallel coordinate axis

    .

    3. Translate the object so that the rotation axis ismoved back to its ori inal osition

    4701074410 / 13016218 Computer Graphics

    C i Th Di i l

  • 8/12/2019 Lecture05 Transformation

    48/62

    Composite Three-Dimensionalransformations (2)

    A coordinate position P is transformed with thesequence

    w ere

    4801074410 / 13016218 Computer Graphics

    C it Th Di i l

  • 8/12/2019 Lecture05 Transformation

    49/62

    Composite Three-Dimensionalransformations (3)

    Rotate about an axis that is not parallel to one of

    the coordinate axes

    1. Translate the object so that the rotation axis passesthrough the coordinate origin

    2. Rotate the object so that the axis of rotation coincides with

    3. Perform the specified rotation about the selected coordinateaxis

    original orientation5. Apply the inverse translation to bring the rotation axis back

    to its original spatial position

    4901074410 / 13016218 Computer Graphics

    C it Th Di i l

  • 8/12/2019 Lecture05 Transformation

    50/62

    Composite Three-Dimensionalransformations (4)

    5001074410 / 13016218 Computer Graphics

    C it Th Di i l

  • 8/12/2019 Lecture05 Transformation

    51/62

    Composite Three-Dimensionalransformations (5)

    The components of the rotation-axis vector

    The unit rotation-axis vector u

    Move the point P1 to the origin

    x-axis rotation ets u into the xz lane

    51

    y-axis rotation swings u around to the z axis

    01074410 / 13016218 Computer Graphics

    C it Th Di i l

  • 8/12/2019 Lecture05 Transformation

    52/62

    Composite Three-Dimensionalransformations (6)

    Rotate around the x axis to get u into

    |u |=1 |u|=d

    Rotation matrix

    5201074410 / 13016218 Computer Graphics

    Composite Three Dimensional

  • 8/12/2019 Lecture05 Transformation

    53/62

    Composite Three-Dimensionalransformations (7)

    Resulting from the rotation aboutx axis is a vector labeled u

    about the y axis is

    5301074410 / 13016218 Computer Graphics

    Composite Three Dimensional

  • 8/12/2019 Lecture05 Transformation

    54/62

    Composite Three-Dimensionalransformations (8)

    The rotation axis is aligned with the positive z axis

    Apply the specified rotation angle

    To complete the required rotation about the givenaxis, we need to transform the rotation axis back to

    5401074410 / 13016218 Computer Graphics

    Quaternion Methods for

  • 8/12/2019 Lecture05 Transformation

    55/62

    Quaternion Methods forhree-Dimensional Rotations

    A more efficient method Require less storage space than 4x4 matrices Important in animations, which often require complicated motion

    of an objectq=(a,b,c)

    MR() = Rx-1() Ry

    -1() Rz() Ry() Rx()

    5501074410 / 13016218 Computer Graphics

    Other Three Dimensional

  • 8/12/2019 Lecture05 Transformation

    56/62

    Other Three-Dimensionalransformations

    Scaling

    5601074410 / 13016218 Computer Graphics

    Other Three Dimensional

  • 8/12/2019 Lecture05 Transformation

    57/62

    Other Three-Dimensional

    ransformations (2)

    Reflection

    Shear

    5701074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    58/62

  • 8/12/2019 Lecture05 Transformation

    59/62

  • 8/12/2019 Lecture05 Transformation

    60/62

    Affine Transformations

    An affine transformation is a form of coordinate transformation

    av ng e genera proper es a para e nes are rans ormeinto parallel lines and finite points map to finite points

    Examples

    Conversion of coordinate descriptions from one reference system toanother

    An affine transformation involving only translation, rotation, and

    60

    ,

    01074410 / 13016218 Computer Graphics

    OpenGL Geometric-

  • 8/12/2019 Lecture05 Transformation

    61/62

    OpenGL Geometric

    ransformation Functions

    Basic OpenGL Geometric Transformations glTranslate* (tx, ty, tz);

    -. , . , .

    glRotate* (theta, vx, vy, vz);

    glRotatef (90.0, 0.0, 0.0, 1.0);

    , ,

    glScalef (2.0, -3.0, 1.0);

    OpenGL Matrix Operations glMatrixMode (GL_MODELVIEW); glMatrixMode (GL_PROJECTION);

    6101074410 / 13016218 Computer Graphics

  • 8/12/2019 Lecture05 Transformation

    62/62