2IV60!3!2D Transformations

  • Upload
    preetht

  • View
    230

  • Download
    0

Embed Size (px)

Citation preview

  • 7/25/2019 2IV60!3!2D Transformations

    1/57

    2IV60 Computer Graphics

    2D transformations

    Jack van Wijk

    TU/e

  • 7/25/2019 2IV60!3!2D Transformations

    2/57

    vervie!" Wh# transformations$

    " %asic transformations&

    'trans(ation) rotation) sca(in*

    " Com+inin* transformations'homo*enous coor,inates) transform- .atrices

    " irst 2D) net 1D

  • 7/25/2019 2IV60!3!2D Transformations

    3/57

    Transformations

    ima*e

    train

    !or(,

    !hee(modelling

    instantiation

    viewing

    animation

  • 7/25/2019 2IV60!3!2D Transformations

    4/57

    Wh# transformation$

    " .o,e( of o+jects

    !or(, coor,inates& km, mm, etc.

    ierarchica( mo,e(s&&human = torso + arm + arm + head + leg + leg

    arm = upperarm + lowerarm + hand

    "Vie!in*3oom in) move ,ra!in*) etc-

    " 4nimation

  • 7/25/2019 2IV60!3!2D Transformations

    5/57

    Trans(ation

    Trans(ate over vector 5tx, ty

    x=x+ tx) y=y+ ty

    or

    x

    y

    P

    P+T

    7% 89:&2209222

    T

    =

    =

    =

    +=

    y

    x

    t

    t

    y

    x

    y

    x TPP

    TPP'

    an,);;;

    !ith)

  • 7/25/2019 2IV60!3!2D Transformations

    6/57

    Trans(ation po(#*on

    Trans(ate po(#*on&

    4pp(# the same operation

    on a(( points-

    Works a(!a#s) for a((

    transformations of

    o+jects ,efine, as a set

    of points-

    x

    y

    T

    7% 89:&2209222

  • 7/25/2019 2IV60!3!2D Transformations

    7/57

  • 7/25/2019 2IV60!3!2D Transformations

    8/57

  • 7/25/2019 2IV60!3!2D Transformations

    9/57

    =cha(e !ith factorsxan,sy&

    x= sxx) y= syy

    or

    an,0

    0);

    ;;

    !ith)

    =

    =

    =

    =

    y

    xs

    s

    y

    x

    y

    xPSP

    SPP'

    =ca(in*

    x

    y

    P

    7% 89:&22>922?

    x

    P

    Q

    Q

  • 7/25/2019 2IV60!3!2D Transformations

    10/57

    =ca(in* !ith respect to a point F

    =ca(e !ith factorssxan,sy&

    Px= sxPx) Py= syPy

    With respect to F&

    PxFx= sx5PxFx)

    PyFy= sy5PyFy

    or Px= Fx+ sx5PxFx)

    Py= Fy+ sy5PyFy

    x

    y

    P

    7% 89:&22>922?

    x

    P

    Q

    QF

    P

    F

  • 7/25/2019 2IV60!3!2D Transformations

    11/57

    Transformations

    " Trans(ate !ith V&

    T@ P A V

    " =cha(e !ith factors@s#@s&

    S@sP

    "

  • 7/25/2019 2IV60!3!2D Transformations

    12/57

    Transformations

    " .ess#

    " Transformations !ith respect to points&

    even more mess#

    " o! to com+ine transformations$

    7% 892&22?922B

  • 7/25/2019 2IV60!3!2D Transformations

    13/57

    omo*eneous coor,inates :

    " Uniform representation of trans(ation)

    rotation) sca(in*

    " Uniforme representation of points an,

    vectors

    " Compact representation of seEuence of

    transformations

    7% 892&22?922B

  • 7/25/2019 2IV60!3!2D Transformations

    14/57

    omo*eneous coor,inaten 2

    " 4,, etra coor,inate&

    P @ 5p )p# )ph or

    x@ 5x, y, h

    " Cartesian coor,inates& ,ivi,e +# h

    x @ 5x/h)y/h" Foints& h @ : 5for the time +ein*)

    vectors& h @ 07% 892&22?922B

  • 7/25/2019 2IV60!3!2D Transformations

    15/57

    6)5;

    or

    ::00:0

    0:

    :;

    ;

    &nTrans(atio

    PTP yx

    y

    x

    tt

    y

    x

    t

    t

    y

    x

    =

    =

    Trans(ation matri

    7% 892&22?922B

  • 7/25/2019 2IV60!3!2D Transformations

    16/57

    5;

    or

    ::000cossin

    0sincos

    :;

    ;

    &

  • 7/25/2019 2IV60!3!2D Transformations

    17/57

    =ca(in* matri

    7% 892&22?922B

    )5;

    or

    ::0000

    00

    :;

    ;

    &=ca(in*

    PSP yx

    y

    x

    ss

    y

    x

    s

    s

    y

    x

    =

    =

  • 7/25/2019 2IV60!3!2D Transformations

    18/57

    Inverse transformations

    7% 891&22B

    :

    ):

    5)5

    &=ca(in*

    55

    &

  • 7/25/2019 2IV60!3!2D Transformations

    19/57

    12

    12

    12''

    '

    2

    ''

    1'

    MMMMP

    PMM

    P)(MMP

    PMP

    PMP

    ===

    =

    =

    =

    !ith

    &Com+ine,ation---transformsecon,

    ---sformationfirst tran

    Com+inin* transformations :

    7% 89>&22B922

  • 7/25/2019 2IV60!3!2D Transformations

    20/57

    PT

    PP

    PTTP

    PTP

    PTP

    ''

    '''

    '

    )5

    :00:0

    0:

    :00:0

    0:

    :00:0

    0:

    )5)5

    &Com+ine,

    ontrans(atisecon,)5

    s(ationfirst tran)5

    2:2:

    2:

    2:

    :

    :

    2

    2

    ::22

    22

    ::

    yxxx

    yy

    xx

    y

    x

    y

    x

    yxyx

    yx

    yx

    tttt

    tt

    tt

    t

    t

    t

    t

    tttt

    tt

    tt

    ++=

    +

    +

    =

    =

    =

    =

    =

    Com+inin* transformations 2

    7% 89>&22

  • 7/25/2019 2IV60!3!2D Transformations

    21/57

    6)56)56)5&sca(in*Composite

    656565

    &rotationsComposite

    6)56)56)5

    &onstrans(atiComposite

    2:2:::22

    2::2

    2:2:::22

    yyxxyxyx

    yxxxyxyx

    ssssssss

    R

    tttttttt

    SSS

    RR

    TTT

    =

    +=

    ++=

    Com+inin* transformations 1

    7% 89>&22

  • 7/25/2019 2IV60!3!2D Transformations

    22/57

    +ack-Trans(ate16ori*inHaroun,an*(eover

  • 7/25/2019 2IV60!3!2D Transformations

    23/57

    '''''

    '''

    '

    )PT(P

    )PR(P

    )PT(P

    R

    yx

    yx

    ,RR

    R,R

    ==

    =

    16

    26

    :6

    &pointaroun,an*(eover

  • 7/25/2019 2IV60!3!2D Transformations

    24/57

    )P)T()R(T(

    )P)R(T(

    )PT(P

    )P)T(R()PR(P

    )PT(P

    '

    '''''

    '''

    '

    yxyx

    yx

    yx

    yx

    yx

    R,R,RR

    ,RR

    ,RR

    R,R

    R,R

    =

    =

    =

    ==

    =

    16

    26

    :6

    &229210

  • 7/25/2019 2IV60!3!2D Transformations

    25/57

    PP

    )P)T()R(T(P

    '''

    '''

    +

    =

    =

    :00

    sin6cos:5cossin

    sin6cos:5sincos

    or

    169:

    xy

    yx

    yxyx

    RR

    RR

    R,R,RR

    R

    : 2 17% 89>&229210

  • 7/25/2019 2IV60!3!2D Transformations

    26/57

    a*ain-+ackTrans(ate16ori*inH!-r-t-=cha(e26

    ori*inH!ithcoinci,essuch thatTrans(ate:6

    &point!-r-t-an,factors!ith=ca(e

    F

    Fxx ss

    =ca(in* !-r-t- point :

    F

    : 2 17% 89>&210921:

  • 7/25/2019 2IV60!3!2D Transformations

    27/57

    '''''

    '''

    '

    )PT(P

    )PS(P

    )PT(P

    F

    yx

    yx

    yx

    ,FF

    ss

    F,F

    ==

    =

    16

    )26

    :6

    &point!-r-t-=cha(e

    =ca(in* !-r-t-point 2

    F

    : 2 17% 89>&210921:

  • 7/25/2019 2IV60!3!2D Transformations

    28/57

    PP

    )PT()ST(P

    '''

    '''

    =

    =

    :00

    6:50

    6:50

    or

    6)5169:

    yyy

    xxx

    yxyxyx

    sFs

    sFs

    F,Fss,FF

    =ca(in* !-r-t-point 1

    F

    : 2 17% 89>&210921:

  • 7/25/2019 2IV60!3!2D Transformations

    29/57

    a*ain-+ack

  • 7/25/2019 2IV60!3!2D Transformations

    30/57

    '''''

    '''

    '

    )PR(P)PS(P

    )PR(P

    ==

    =

    16)26

    :6

    &,irectionotherin=ca(e

    2: ss

    =ca(e in other ,irections 2

    : 2 17% 89>&210921:

  • 7/25/2019 2IV60!3!2D Transformations

    31/57

    PP

    )P)R()S(R(P

    '''

    '''

    ++

    =

    =

    :00

    0cossinsincos65

    0sincos65sincos

    or

    )169:

    22

    2::2

    :22

    22

    :

    2:

    ssss

    ssss

    ss

    =ca(e in other ,irections 1

    : 2 17% 89>&210921:

  • 7/25/2019 2IV60!3!2D Transformations

    32/57

    r,er of transformations :

    #

    0I

    #I0II

    #II

    #

    #

    0II

    #II

    .atri mu(tip(ication ,oes not commute-

    The or,er of transformations makes a ,ifference

    Rotaton, translaton !ranslaton, rotaton

    7% 89>&212

  • 7/25/2019 2IV60!3!2D Transformations

    33/57

    r,er of transformations 2

    " Fre9mu(tip(ication&

    P = Mn Mn9:M2 M: P

    Transformation Mn in *(o+a( coor,inates

    " Fost9mu(tip(ication&

    P = M: M2Mn9: Mn P

    Transformation Mn in (oca( coor,inates& thecoor,inate s#stem after app(ication of

    M : M2Mn9:

    7% 89>&212

  • 7/25/2019 2IV60!3!2D Transformations

    34/57

    r,er of transformations 1

    penG& glRotate, glScale) etc-&

    " Fost9mu(tip(ication of current

    transformation matri" 4(!a#s transformation in (oca( coor,inates

    " G(o+a( coor,inate version& rea, in reverse

    or,er

    7% 89>&212

  • 7/25/2019 2IV60!3!2D Transformations

    35/57

    r,er of transformations >

    glTranslate();

    glRotate();

    # 0II

    #II

    #

    Localtra"o

    nterpretaton

    Localtrans"ormatons&

    # 0II

    #II

    Globaltrans"ormatons#

    0I

    #I

    Globaltra"o

    nterpretaton

    7% 89>&212

  • 7/25/2019 2IV60!3!2D Transformations

    36/57

  • 7/25/2019 2IV60!3!2D Transformations

    37/57

    Direct construction of matri

    x

    y

    $

    AB

    T

    u

    If #ou kno! the tar*et frame&

    Construct matri ,irect(#-

    Define shape in nice (oca(u,$coor,inates) use matri

    transformation to put it

    inx,yspace-

    7% 89>&211921?

  • 7/25/2019 2IV60!3!2D Transformations

    38/57

    ( )

    ::00:

    or)

    ::

    or);

    =

    =

    ++=

    $u

    !%&!%&

    yx

    $

    u

    y

    x

    $u

    yyy

    xxx

    TBA

    TBAP

    Direct construction of matri

    x

    y

    $

    AB

    T

    u

    If #ou kno! the tar*et frame&

    Construct matri ,irect(#-

    7% 89>&211921?

  • 7/25/2019 2IV60!3!2D Transformations

    39/57

    ::00:

    of);

    =

    =

    $u

    trrrtrrr

    yx

    yyyyx

    xxyxx

    MPP

    &211921?0):KK):KK)an,

    su+matri(orthonorma&

    ===

    =

    =

    BABABAyy

    xy

    yx

    xx

    yyyx

    xyxx

    r

    r

    r

    r

    rr

    rr

  • 7/25/2019 2IV60!3!2D Transformations

    40/57

    ther 2D transformations

    "

  • 7/25/2019 2IV60!3!2D Transformations

    41/57

    PP'

    =:000:0

    00:

  • 7/25/2019 2IV60!3!2D Transformations

    42/57

    PRP'

    PP'

    6:B05as=ame

    :00

    0:0

    00:

    =

    =

    092>2

  • 7/25/2019 2IV60!3!2D Transformations

    43/57

    tan!ith

    :00

    0:0

    0:

    =

    =

    "

    "

    PP'

    =hear

    =hear they9as&

    x=x+"y) y=y

    or

    x

    y

    7% 89>&2>292>1

  • 7/25/2019 2IV60!3!2D Transformations

    44/57

    Transformations coor,inates

    Given 5x,y9coor,inates)

    in, 5x,y9coor,inates-

    692>B

  • 7/25/2019 2IV60!3!2D Transformations

    45/57

    Given 5x,y9coor,inates)

    in, 5x,y9coor,inates-

    Lamp(e& user points at

    5x,y, !hats the position

    in (oca( coor,inates$

    Transformations coor,inates

    x

    y

    x

    y

    5x0, y0

    7% 89B&2>692>B

  • 7/25/2019 2IV60!3!2D Transformations

    46/57

    Given X& 5x,y9coor,inates)

    in, X& 5x,y9coor,inates-

    =tan,ar,&

    X=MX 5o+ject trafo&

    from (oca( to *(o+a(

    ere&

    X=M-1X 5from *(o+a( to (oca(

    Transformations coor,inates

    x

    y

    x

    y

    5x0, y0

    7% 89B&2>692>B

  • 7/25/2019 2IV60!3!2D Transformations

    47/57

    Given X& 5x,y9coor,inates)

    in, X& 5x,y9coor,inates-

    ere&

    X=M-1

    X 5from *(o+a( to (oca(4pproach :&

    9 Determine Mstan,ar, matriN M 5from (oca( to *(o+a( coor,inates an, invert

    Transformations coor,inates

    x

    y

    x

    y

    5x0, y0

    7% 89B&2>692>B

  • 7/25/2019 2IV60!3!2D Transformations

    48/57

    Given X& 5x,y9coor,inates)

    in, X& 5x,y9coor,inates-

    ere&

    X=M-1X 5from *(o+a( to (oca(4pproach 2&

    9 construct transformation that maps (oca( frame to *(o+a( 5re$erse o" usual.

    Transformations coor,inates

    x

    y

    x

    y

    5x0, y0

    7% 89B&2>692>B

  • 7/25/2019 2IV60!3!2D Transformations

    49/57

    Given X& 5x,y9coor,inates)

    in, X& 5x,y9coor,inates-

    ere&

    X=M-1X 5from *(o+a( to (oca(

    4pproach 2&

    :-Trans(ate 5x0, y0 to ori*inH

    2-692>B

  • 7/25/2019 2IV60!3!2D Transformations

    50/57

    Given X& 5x,y9coor,inates)

    in, X& 5x,y9coor,inates-

    ere&

    X=M-1X 5from *(o+a( to (oca(

    4pproach 2&

    M-1= T5x() y(R5

    Transformations coor,inates

    x

    y

    x

    y

    5x0, y0

    7% 89B&2>692>B

  • 7/25/2019 2IV60!3!2D Transformations

    51/57

    penG 2D transformations :

    Interna((#&

    " Coor,inates are four9e(ement ro! vectors

    " Transformations are >> matrices

    2D trafos& I*nore)9coor,inates) set) = 0-

    7% 89&2>B92?1

  • 7/25/2019 2IV60!3!2D Transformations

    52/57

    penG 2D transformations 2

    penG maintains t!o matrices& GL_PROJECTION

    GL_MODELIE!

    Transformations are app(ie, to the current matri) to

    +e se(ecte, !ith&

    glMatr"#Mo$e(GL_PROJECTION) or glMatr"#Mo$e(GL_MODELIE!)

    7% 89&2>B92?1

  • 7/25/2019 2IV60!3!2D Transformations

    53/57

    penG 2D transformations 1

    Initia(i3in* the matri to I& glLoa$I$ent"t%();

  • 7/25/2019 2IV60!3!2D Transformations

    54/57

    penG 2D transformations >

    %asic transformation functions& *enerate matri an, post9

    mu(tip(# this !ith current matri-

    Trans(ate over Ot) t#) t3P&

    glTranslate+(t#, t%, t-);

    B92?1

  • 7/25/2019 2IV60!3!2D Transformations

    55/57

    penG 2D Transformations ?

    penG maintainsstacks of transformation matrices-

    T!o operations&

    glPs.Matr"#()0.ake cop# of current matri an, put that on top of the stackH

    glPo1Matr"#()0

    9128

  • 7/25/2019 2IV60!3!2D Transformations

    56/57

    penG 2D Transformations 6

    =tan,ar,&

    glRotate(2, , 3, 2);

    glScale(3, , 245);glTranslate(, 3, 6);

    glt!"reC7e();

    glTranslate(

    , 3,6);

    glScale(245, , 3);

    glRotate(

    2, , 3, 2);

    Usin* the stack&

    glPs.Matr"#();

    glRotate(2, , 3, 2);glScale(3, , 245);

    glTranslate(, 3, 6);

    glt!"reC7e();

    glPo1Matr"#();

    Un,o transformation

    =horter) more ro+ust

    7% 9B&12>9128

  • 7/25/2019 2IV60!3!2D Transformations

    57/57

    2D transformations summari3e,

    9 Transformations& mo,e(in*) vie!in*) animationH

    9 =evera( kin,s of transformationsH

    9 omo*eneous coor,inatesH

    9 Com+ine transformations usin* matri mu(tip(ication-

    Up to 1D