+ All Categories
Home > Documents > 2d Transforms

2d Transforms

Date post: 14-Apr-2018
Category:
Upload: gopal-chatterjee
View: 224 times
Download: 0 times
Share this document with a friend

of 47

Transcript
  • 7/30/2019 2d Transforms

    1/47

    2D Transformations

  • 7/30/2019 2d Transforms

    2/47

    2D Transformations

    World Coordinates

    Translate

    Rotate

    Scale

    Viewport Transforms Hierarchical Model Transforms

    Putting it all together

  • 7/30/2019 2d Transforms

    3/47

    Transformations

    Rigid Body Transformations - transformations that do

    not change the object.

    Translate

    If you translate a rectangle, it is still a rectangle

    Scale

    If you scale a rectangle, it is still a rectangle

    Rotate If you rotate a rectangle, it is still a rectangle

  • 7/30/2019 2d Transforms

    4/47

    Vertices

    We have always represented vertices as

    (x,y)

    An alternate method is:

    Example:

    y

    xyx ),(

    8.4

    1.2)8.4,1.2(

  • 7/30/2019 2d Transforms

    5/47

    Matrix * Vector

    10

    01

    '

    '

    '

    '

    I

    dycxy

    byaxx

    y

    x

    dc

    ba

    y

    x

    100

    010

    001'

    '

    ''

    '

    '

    I

    izhygxz

    fzeydxy

    czbyaxxz

    y

    x

    ihg

    fed

    cba

    z

    y

    x

  • 7/30/2019 2d Transforms

    6/47

    Matrix * Matrix

    10

    01?

    *

    ,

    dc

    ba

    dwcydzcx

    bwaybzaxBA

    wz

    yxB

    dc

    baA

    Does A*B = B*A? NO

    What does the identity do?

    AI=A

  • 7/30/2019 2d Transforms

    7/47

    Translation

    Translation - repositioning an object along a

    straight-line path (the translation distance)

    from one coordinate location to another.

    (x,y)

    (x,y)

    (tx,ty)

  • 7/30/2019 2d Transforms

    8/47

    Translation

    Given:

    We want:

    Matrix form:

    TPP

    t

    t

    y

    x

    y

    x

    tyy

    txx

    ttT

    yxP

    y

    x

    y

    x

    yx

    '

    '

    '

    '

    '

    ),(

    ),(

    1.4'

    4.3'

    2.8

    1.7

    1.4

    7.3

    '

    '

    2.81.4'

    1.77.3'

    )2.8,1.7(

    )1.4,7.3(

    y

    x

    y

    x

    y

    x

    T

    P

  • 7/30/2019 2d Transforms

    9/47

    Translation Examples

    P=(2,4), T=(-1,14), P=(?,?)

    P=(8.6,-1), T=(0.4,-0.2), P=(?,?)

    P=(0,0), T=(1,0), P=(?,?)

  • 7/30/2019 2d Transforms

    10/47

    Recall

    A point is a position specified with

    coordinate values in some reference frame.

    We usually label a point in this reference

    point as the origin.

    All points in the reference frame are given

    with respect to the origin.

  • 7/30/2019 2d Transforms

    11/47

    Applying to Triangles

    (tx,ty)

  • 7/30/2019 2d Transforms

    12/47

    What do we have here?

    You know how to:

  • 7/30/2019 2d Transforms

    13/47

    Scale

    Scale - Alters the size of an object.

    Scales about a fixed point

    (x,y)

    (x,y)

  • 7/30/2019 2d Transforms

    14/47

    Scale

    Given:

    We want:

    Matrix form:PSP

    y

    x

    s

    s

    y

    x

    ysy

    xsx

    ssS

    yxP

    y

    x

    y

    x

    yx

    '

    0

    0

    '

    '

    '

    '

    ),(

    ),(

    6.6'

    2.4'

    2.24.1

    3003

    ''

    2.2*3'

    4.1*3'

    )3,3(

    )2.2,4.1(

    y

    x

    yx

    y

    x

    S

    P

  • 7/30/2019 2d Transforms

    15/47

    Non-Uniform Scale

    (x,y)

    (x,y)

    S=(1,2)

  • 7/30/2019 2d Transforms

    16/47

    Rotation

    Rotation - repositions an object along a

    circular path.

    Rotation requires an and a pivot point

  • 7/30/2019 2d Transforms

    17/47

    Rotation

    )sin('

    )cos('

    sin

    cos

    )(

    ),(

    ry

    rx

    ry

    rx

    R

    yxp

    Rpp

    y

    x

    y

    x

    yxy

    yxx

    rry

    rrx

    '

    cossin

    sincos

    '

    '

    cossin'

    sincos'

    cossinsincos'

    sinsincoscos'

  • 7/30/2019 2d Transforms

    18/47

    Example

    P=(4,4)

    =45 degrees

  • 7/30/2019 2d Transforms

    19/47

    RotationsV(-0.6,0) V(0,-0.6) V(0.6,0.6)

    Rotate -30 degrees

    V(0,0.6) V(0.3,0.9) V(0,1.2)

  • 7/30/2019 2d Transforms

    20/47

    Combining Transformations

    Q: How do we

    specify each

    transformation?

  • 7/30/2019 2d Transforms

    21/47

    Specifying 2D Transformations

    Translation

    T(tx, ty)

    Translation distances Scale

    S(sx,sy)

    Scale factors

    Rotation

    R()

    Rotation angle

  • 7/30/2019 2d Transforms

    22/47

    Combining Transformations

    Using translate, rotation, and scale, how do

    we get:

  • 7/30/2019 2d Transforms

    23/47

    Combining Transformations Note there are two ways to combine rotation

    and translation. Why?

  • 7/30/2019 2d Transforms

    24/47

    Lets look at the equations

    cos'sin'"

    sin'cos'"

    '

    '

    '''

    ')(

    ),(

    ),(

    yxy

    yxx

    tyy

    txx

    PRP

    TPPR

    ttT

    yxP

    y

    x

    yx

    y

    x

    yx

    yx

    tyxy

    tyxx

    yxy

    yxx

    TPPPRP

    tytxy

    tytxx

    cossin"

    sincos"

    cossin'

    sincos'

    '"'

    cos'sin"

    sin'cos"

  • 7/30/2019 2d Transforms

    25/47

    Combining them

    We must do each step in turn. First we

    rotate the points, then we translate, etc.

    Since we can represent the transformationsby matrices, why dont we just combine

    them?

    PSP

    PRP

    TPP

    '

    '

    '

  • 7/30/2019 2d Transforms

    26/47

    2x2 -> 3x3 Matrices

    We can combine transformations by

    expanding from 2x2 to 3x3 matrices.

    100

    0cossin

    0sincos

    cossin

    sincos

    10000

    00

    0

    0

    ,

    100

    10

    01

    ,

    R

    s

    s

    s

    s

    ssS

    t

    t

    t

    t

    y

    xttT

    y

    x

    y

    x

    yx

    y

    x

    y

    x

    yx

  • 7/30/2019 2d Transforms

    27/47

    Homogenous Coordinates

    We need to do something to the vertices

    By increasing the dimensionality of the

    problem we can transform the additioncomponent of Translation into

    multiplication.

    2

    22

    147

    263

    2

    14

    6

    7

    3.,

    1

    2

    4

    2

    4. ExEx

    h

    hh

    yy

    hxx

    h

    y

    x

    y

    xP h

    h

    h

    h

  • 7/30/2019 2d Transforms

    28/47

    Homogenous Coordinates

    Homogenous Coordinates - term used in

    mathematics to refer to the effect of this

    representation on Cartesian equations. Convertinga pt(x,y) and f(x,y)=0 -> (xh,yh,h) then in

    homogenous equations mean (v*xh,v*yh,v*h) can

    be factored out.

    What you should get: By expressing thetransformations with homogenous equations and

    coordinates, all transformations can be expressed

    as matrix multiplications.

  • 7/30/2019 2d Transforms

    29/47

    Final Transformations -

    Compare Equations

    PRPPRP

    y

    x

    y

    x

    y

    x

    y

    xR

    PssSPPssSP

    y

    x

    s

    s

    y

    x

    y

    x

    s

    s

    y

    xssS

    PttTPPttTP

    y

    x

    t

    t

    y

    x

    y

    x

    t

    t

    y

    xttT

    yxyx

    y

    x

    y

    x

    yx

    yxyx

    y

    x

    y

    x

    yx

    1100

    0cossin

    0sincos

    1

    '

    '

    cossin

    sincos

    '

    '

    ,,

    1100

    00

    00

    1

    '

    '

    0

    0

    '

    ',

    ,,

    1100

    10

    01

    1

    '

    '

    '

    ',

  • 7/30/2019 2d Transforms

    30/47

    Combining Transformations

    1

    '

    '

    100

    10

    01

    100

    0cossin

    0sincos

    1

    "

    "1

    '

    '

    100

    0cossin

    0sincos

    1

    "

    "

    1100

    10

    01

    1

    '

    '

    )60(),2,4641.0(),4,3(

    "'",'

    y

    x

    t

    t

    y

    x

    y

    x

    y

    x

    y

    x

    t

    t

    y

    x

    RTP

    PBAPPBPPAP

    y

    x

    y

    x

    1100

    cossin

    sincos

    1

    "

    "

    1100

    0cossin

    0sincos

    100

    10

    01

    1

    "

    "

    1100

    cossincossin

    sincossincos

    1

    "

    "

    y

    x

    t

    t

    y

    x

    y

    x

    t

    t

    y

    x

    y

    x

    tt

    tt

    y

    x

    y

    x

    y

    x

    yx

    yx

  • 7/30/2019 2d Transforms

    31/47

    How would we get:

  • 7/30/2019 2d Transforms

    32/47

    How would we get:

  • 7/30/2019 2d Transforms

    33/47

    Coordinate Systems

    Object Coordinates

    World Coordinates

    Eye Coordinates

  • 7/30/2019 2d Transforms

    34/47

    Object Coordinates

  • 7/30/2019 2d Transforms

    35/47

    World Coordinates

  • 7/30/2019 2d Transforms

    36/47

    Screen Coordinates

  • 7/30/2019 2d Transforms

    37/47

    Coordinate Hierarchy

    Object #1

    Object Coordinates

    Transformation

    Object #1 ->World

    Object #2

    Object Coordinates

    Transformation

    Object #2 ->World

    Object #3

    Object Coordinates

    Transformation

    Object #3 ->World

    World Coordinates

    Transformation

    World->Screen

    Screen Coordinates

  • 7/30/2019 2d Transforms

    38/47

    Lets reexamine assignment 1

  • 7/30/2019 2d Transforms

    39/47

    Transformation Hierarchies

    (See chapter 10 for details)

    For example, a robot arm

  • 7/30/2019 2d Transforms

    40/47

    Transformation Hierarchies

    Lets examine:

  • 7/30/2019 2d Transforms

    41/47

    Transformation Hierarchies

    What is a better way?

  • 7/30/2019 2d Transforms

    42/47

    Transformation Hierarchies

    What is a better way?

    W ld

  • 7/30/2019 2d Transforms

    43/47

    Transformation Hierarchies

    We can have transformations be

    in relation to each other

    World

    Coordinates

    Upper Arm

    Coordinates

    Lower Arm

    Coordinates

    Hand

    Coordinates

    Transformation:

    Upper Arm -> World

    Transformation:

    Lower -> Upper

    Transformation:

    Hand-> Lower

  • 7/30/2019 2d Transforms

    44/47

    44Angel: Interactive Computer

    Graphics 5E Addison-Wesley 2009

    Rotation about a Fixed Point

    Start with identity matrix: CI

    Move fixed point to origin: CCT

    Rotate: CCR

    Move fixed point back: CCT -1

    Result: C = TR T 1which is backwardsCp

    This result is a consequence of doing postmultiplications.Lets try again.

  • 7/30/2019 2d Transforms

    45/47

    45Angel: Interactive Computer

    Graphics 5E Addison-Wesley 2009

    Reversing the Order

    We want C = T 1 R Tso we must do the operations in the following order

    C

    ICCT -1CCRCCT

    Each operation corresponds to one function call in theprogram.

    Note that the last operation specified is the first executed inthe program

  • 7/30/2019 2d Transforms

    46/47

    46Angel: Interactive Computer

    Graphics 5E Addison-Wesley 2009

    OpenGL Example

    Rotation about z axis by 30 degrees with a fixed

    point of (1.0, 2.0, 3.0)

    Remember that last transform specified in the

    program is the first applied

    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();glTranslatef(1.0, 2.0, 3.0);

    glRotatef(30.0, 0.0, 0.0, 1.0);

    glTranslatef(-1.0, -2.0, -3.0);

    glBegin(GL_TRIANGLES);...

  • 7/30/2019 2d Transforms

    47/47

    Angel: Interactive Computer

    Matrix Stacks In many situations we want to save

    transformation matrices for use later

    Traversing hierarchical data structures (Chapter 10)

    Avoiding state changes when executing display lists

    OpenGL maintains stacks for each type of

    matrix

    Access present type (as set by glMatrixMode)by glPushMatrix()

    glPopMatrix()


Recommended