07 Transform

Embed Size (px)

Citation preview

  • 7/30/2019 07 Transform

    1/8

    1

    Modeling Transformations

    Tom Funkhouser

    Princeton University

    COS 426, Spring 2006

    Modeling Transformations

    Specify transformations for objects

    Allows definitions of objects in own coordinate systems Allows use of object definition multiple times in a scene

    Mike Marr, COS 426

    Overview

    2D Transformations Basic 2D transformations

    Matrix representation

    Matrix composition

    3D Transformations

    Basic 3D transformations

    Same as 2D

    Transformation Hierarchies Scene graphs

    Ray casting

    2D Modeling Transformations

    ScaleRotate

    Translate

    ScaleTranslate

    x

    y

    World Coordinates

    ModelingCoordinates

    2D Modeling Transformations

    x

    y

    World Coordinates

    ModelingCoordinates

    Lets lookat this indetail

    2D Modeling Transformations

    x

    y

    ModelingCoordinates

  • 7/30/2019 07 Transform

    2/8

    2

    2D Modeling Transformations

    x

    y

    ModelingCoordinates

    Scale .3, .3Rotate -90

    Translate 5, 3

    2D Modeling Transformations

    x

    y

    ModelingCoordinates

    Scale .3, .3Rotate -90

    Translate 5, 3

    2D Modeling Transformations

    x

    y

    ModelingCoordinates

    Scale .3, .3Rotate -90

    Translate 5, 3

    World Coordinates

    Basic 2D Transformations

    Translation: x = x + tx y = y + ty

    Scale: x = x * sx y = y * sy

    Shear: x = x + hx*y y = y + hy*x

    Rotation:

    x = x*cos

    - y*sin

    y = x*sin + y*cos

    Transformationscan be combined

    (with simple algebra)

    Basic 2D Transformations

    Translation: x = x + tx

    y = y + ty

    Scale: x = x * sx

    y = y * sy

    Shear: x = x + hx*y y = y + hy*x

    Rotation: x = x*cos - y*sin y = x*sin + y*cos

    Basic 2D Transformations

    Translation: x = x + tx

    y = y + ty

    Scale: x = x * sx

    y = y * sy

    Shear: x = x + hx*y y = y + hy*x

    Rotation: x = x*cos - y*sin y = x*sin + y*cos

    x = x*sx

    y = y*sy

    x = x*sx

    y = y*sy

    (x,y)

    (x,y)

  • 7/30/2019 07 Transform

    3/8

    3

    Basic 2D Transformations

    Translation:

    x = x + tx y = y + ty

    Scale: x = x * sx y = y * sy

    Shear: x = x + hx*y

    y = y + hy*x

    Rotation: x = x*cos - y*sin y = x*sin + y*cos

    x = (x*sx)*cos (y*sy)*siny = (x*sx)*sin + (y*sy)*cos

    x = (x*sx)*cos (y*sy)*siny = (x*sx)*sin + (y*sy)*cos

    (x,y)

    Basic 2D Transformations

    Translation:

    x = x + tx y = y + ty

    Scale: x = x * sx y = y * sy

    Shear: x = x + hx*y

    y = y + hy*x

    Rotation: x = x*cos - y*sin y = x*sin + y*cos

    x = ((x*sx)*cos (y*sy)*sin) +txy = ((x*sx)*sin + (y*sy)*cos) + ty

    x = ((x*sx)*cos (y*sy)*sin) + txy = ((x*sx)*sin + (y*sy)*cos) + ty

    (x,y)

    Basic 2D Transformations

    Translation: x = x + tx y = y + ty

    Scale: x = x * sx y = y * sy

    Shear: x = x + hx*y y = y + hy*x

    Rotation:

    x = x*cos

    - y*sin

    y = x*sin + y*cos

    x = ((x*sx)*cos (y*sy)*sin) + txy = ((x*sx)*sin + (y*sy)*cos) + ty

    x = ((x*sx)*cos (y*sy)*sin) +txy = ((x*sx)*sin + (y*sy)*cos) + ty

    Overview

    2D Transformations Basic 2D transformations

    Matrix representation

    Matrix composition

    3D Transformations

    Basic 3D transformations

    Same as 2D

    Transformation Hierarchies Scene graphs

    Ray casting

    Matrix Representation

    Represent 2D transformation by a matrix

    Multiply matrix by column vector apply transformation to point

    =

    yx

    dcba

    yx

    ''

    dcba

    dycxy

    byaxx

    +=

    +=

    '

    '

    Matrix Representation

    Transformations combined by multiplication

    =

    yx

    lk

    ji

    hg

    fedcba

    yx

    ''

    Matrices are a convenient and efficient wayto represent a sequence of transformations!

  • 7/30/2019 07 Transform

    4/8

    4

    =

    yx

    dcba

    yx

    ''

    2x2 Matrices

    What types of transformations can be

    represented with a 2x2 matrix?

    2D Identity?

    yyxx

    =

    =

    ''

    =

    yx

    yx

    1001

    ''

    2D Scale around (0,0)?

    ysyyxsxx

    *'*'

    =

    =

    =

    yx

    dcba

    yx

    ''

    =

    yx

    sysx

    yx

    00

    ''

    2x2 Matrices

    What types of transformations can be

    represented with a 2x2 matrix?

    2D Rotate around (0,0)?

    yxyyxx

    *cos*sin'*sin*cos'

    +=

    =

    =

    yx

    dcba

    yx

    ''

    =

    yx

    yx

    cossinsincos

    ''

    2D Shear?

    yxshyyyshxxx

    +=

    +=

    *'*'

    =

    yx

    dcba

    yx

    ''

    =

    yx

    shyshx

    yx

    11

    ''

    2x2 Matrices

    What types of transformations can berepresented with a 2x2 matrix?

    2D Mirror over Y axis?

    yyxx

    =

    =

    ''

    =

    yx

    dcba

    yx

    ''

    =

    yx

    yx

    1001

    ''

    2D Mirror over (0,0)?

    yyxx

    =

    =

    ''

    =

    yx

    dcba

    yx

    ''

    =

    yx

    yx

    1001

    ''

    =

    yx

    dcba

    yx

    ''

    2x2 Matrices

    What types of transformations can berepresented with a 2x2 matrix?

    2D Translation?

    tyyytxxx

    +=

    +=

    ''

    Only linear 2D transformationscan be represented with a 2x2 matrix

    NO!

    Linear Transformations

    Linear transformations are combinations of Scale,

    Rotation,

    Shear, and

    Mirror

    Properties of linear transformations: Satisfies:

    Origin maps to origin

    Lines map to lines

    Parallel lines remain parallel

    Ratios are preserved

    Closed under composition

    )()()( 22112211 pppp TsTsssT +=+

    =

    y

    x

    dc

    ba

    y

    x

    '

    '

    2D Translation

    2D translation represented by a 3x3 matrix Point represented with homogeneous coordinates

    tyyy

    txxx

    +=

    +=

    '

    '

    =

    1100

    10

    01

    1

    '

    '

    y

    x

    ty

    tx

    y

    x

  • 7/30/2019 07 Transform

    5/8

    5

    Homogeneous Coordinates

    Add a 3rd coordinate to every 2D point

    (x, y, w) represents a point at location ( x/w, y/w) (x, y, 0) represents a point at infinity

    (0, 0, 0) is not allowed

    1 2

    1

    2(2,1,1) or (4,2,2) or (6,3,3)

    Convenient coordinate system torepresent many useful transformations

    x

    y

    Basic 2D Transformations

    Basic 2D transformations as 3x3 matrices

    =

    1100

    0cossin

    0sincos

    1

    '

    '

    y

    x

    y

    x

    =

    1100

    10

    01

    1

    '

    '

    y

    x

    ty

    tx

    y

    x

    =

    1100

    01

    01

    1

    '

    '

    y

    x

    shy

    shx

    y

    x

    Translate

    Rotate Shear

    =

    1100

    00

    00

    1

    '

    '

    y

    x

    sy

    sx

    y

    x

    Scale

    Affine Transformations

    Affine transformations are combinations of Linear transformations, and

    Translations

    Properties of affine transformations: Origin does not necessarily map to origin

    Lines map to lines

    Parallel lines remain parallel

    Ratios are preserved

    Closed under composition

    =

    w

    yx

    fedcba

    w

    yx

    100''

    Projective Transformations

    Projective transformations Affine transformations, and

    Projective warps

    Properties of projective transformations: Origin does not necessarily map to origin

    Lines map to lines

    Parallel lines do not necessarily remain parallel

    Ratios are not preserved (but c ross-ratios are) Closed under composition

    =

    w

    yx

    ihg

    fedcba

    w

    yx

    '''

    Overview

    2D Transformations Basic 2D transformations

    Matrix representation

    Matrix composition

    3D Transformations Basic 3D transformations

    Same as 2D

    Transformation Hierarchies Scene graphs

    Ray casting

    Matrix Composition

    Transformations can be combined bymatrix multiplication

    =

    w

    yx

    sysx

    tytx

    w

    yx

    100

    0000

    1000cossin0sincos

    100

    1001

    '

    ''

    p = T(tx,ty) R() S(sx,sy) p

  • 7/30/2019 07 Transform

    6/8

    6

    Matrix Composition

    Matrices are a convenient and efficient way to

    represent a sequence of transformations General purpose representation

    Hardware matrix multiply

    Efficiency with premultiplication

    Matrix multiplication is associative

    p = (T * (R * (S*p) ) )p = (T*R*S) * p

    Matrix Composition

    Be aware: order of transformations matters

    Matrix multiplication is not commutative

    p = T * R * S * p

    Global Local

    Matrix Composition

    Rotate by around arbitrary point (a,b) M=T(a,b) * R() * T(-a,-b)

    Scale by sx,sy around arbitrary point (a,b) M=T(a,b) * S(sx,sy) * T(-a,-b)

    (a,b)

    (a,b)

    The trick:

    First, translate (a,b) to the origin.Next, do the rotation about origin.Finally, translate back.

    (Use the same trick.)

    Overview

    2D Transformations Basic 2D transformations

    Matrix representation

    Matrix composition

    3D Transformations

    Basic 3D transformations

    Same as 2D

    Transformation Hierarchies Scene graphs

    Ray casting

    3D Transformations

    Same idea as 2D transformations Homogeneous coordinates: (x,y,z,w)

    4x4 transformation matrices

    =

    wz

    yx

    ponm

    lkji

    hgfedcba

    wz

    yx

    ''''

    Basic 3D Transformations

    =

    wz

    yx

    wz

    yx

    1000010000100001

    '

    ''

    =

    wz

    yx

    tz

    tytx

    wz

    yx

    1000100

    010001

    '

    ''

    =

    wz

    yx

    sz

    sysx

    wz

    yx

    1000000

    000000

    '

    ''

    =

    wz

    yx

    wz

    yx

    1000010000100001

    '

    ''

    Identity Scale

    Translation Mirror over X axis

  • 7/30/2019 07 Transform

    7/8

    7

    Basic 3D Transformations

    =

    wzy

    x

    wzy

    x

    1000010000cossin

    00sincos

    ''

    'Rotate around Z axis:

    =

    wz

    yx

    wz

    yx

    10000cos0sin00100sin0cos

    '

    ''

    Rotate around Y axis:

    =

    wz

    yx

    wz

    yx

    10000cossin00sincos00001

    '''

    Rotate around X axis:

    Overview

    2D Transformations

    Basic 2D transformations Matrix representation

    Matrix composition

    3D Transformations Basic 3D transformations

    Same as 2D

    Transformation Hierarchies Scene graphs

    Ray casting

    Angel Figures 8.8 & 8.9

    Transformation Hierarchies

    Scene may have hierarchy of coordinate systems Each level stores matrix

    representing transformationfrom parents coordinate system

    Base[M1]

    Upper Arm[M2]

    Lower Arm[M3]

    Robot Arm

    Transformation Example 1

    Rose et al. `96

    Well-suited for humanoid characters

    Root

    LHip

    LKnee

    LAnkle

    RHip

    RKnee

    RAnkle

    Chest

    LCollar

    LShld

    LElbow

    LWrist

    LCollar

    LShld

    LElbow

    LWrist

    Neck

    Head

    Transformation Example 1

    Mike Marr, COS 426,

    Princeton University, 1995

    Transformation Example 2

    An object may appear in a scene multiple times

    Draw same 3D data withdifferent transformations

  • 7/30/2019 07 Transform

    8/8

    8

    Transformation Example 2

    Building

    Floor 4 Floor5Floor 3Floor 2Floor 1

    Chair KBookshelf 1

    Desk ChairBookshelf

    Desk 1 Desk 2 Chair 1

    Floor Furniture

    Office NOffice 1

    Office Furniture

    DefinitionsDefinitions

    InstancesInstances

    Transformation Example 3

    H&B Figure 109

    Transformation Example 3

    IcosahedronTetrahedronCube Octahedron Dodecahedron

    Level B

    Instance 4Instance 1

    Level A

    Instances

    Definitions

    Instance 4Instance 1

    Scene

    Instance 4Instance 1

    Angel Figures 8.8 & 8.9

    Ray Casting With Hierarchies

    How interesect a ray withhierarchy of transformedprimitives?

    Base[M1]

    Upper Arm[M2]

    Lower Arm[M3]

    Robot Arm

    Ray

    World Coordinates

    Angel Figures 8.8 & 8.9

    Ray Casting With Hierarchies

    Transform rays, not primitives For each node ...

    Transform ray by inverse of matrix

    Intersect with primitives

    Transform hit by matrix

    Base[M1]

    Upper Arm

    [M2]

    Lower Arm[M3]

    Robot Arm

    World Coordinates

    Summary

    Coordinate systems World coordinates

    Modeling coordinates

    Representations of 3D modeling transformations 4x4 Matrices

    Scale, rotate, translate, shear, projections, etc.

    Not arbitrary warps

    Composition of 3D transformations Matrix multiplication (order matters)

    Transformation hierarchies