2D Transformations in Computer Graphics

  • Upload
    iagpls

  • View
    247

  • Download
    0

Embed Size (px)

Citation preview

  • 8/12/2019 2D Transformations in Computer Graphics

    1/32

    Machiraju/Zhang/Mller

    2D Transformations

    CMPT 361

    Introduction to Computer GraphicsTorsten Mller

  • 8/12/2019 2D Transformations in Computer Graphics

    2/32

    Machiraju/Zhang/Mller

    2

    Graphics Pipeline

    Hardware

    Modelling

    Transform Visibility

    Illumination +

    Shading

    ColorPerception,

    Interaction

    Texture/

    Realism

  • 8/12/2019 2D Transformations in Computer Graphics

    3/32

    Machiraju/Zhang/Mller

    3

    Reading

    Chapter 3 of Angel

    Chapter 5 of Foley, van Dam,

  • 8/12/2019 2D Transformations in Computer Graphics

    4/32

    Machiraju/Zhang/Mller

    4

    Schedule

    Geometry basics

    Affine transformations

    Use of homogeneous coordinates Concatenation of transformations

    3D transformations

    Transformation of coordinate systems Transform the transforms

    Transformations in OpenGL

  • 8/12/2019 2D Transformations in Computer Graphics

    5/32

    Machiraju/Zhang/Mller

    5

    Basic transformations

    The most basic ones

    Translation

    Scaling

    Rotation

    Shear

    And others, e.g., perspective transform, projection, etc.

    Basic types of transformationsRigid-body: preserves length and angle

    Affine: preserves parallel lines, not angles or lengths

    Free-form: a

    nything goes

  • 8/12/2019 2D Transformations in Computer Graphics

    6/32

    Machiraju/Zhang/Mller

    6

    Translation in 2D

    P = P+ T

    x = x+ dx

    y = y + dy x

    y=

    xy+ dx

    dy

  • 8/12/2019 2D Transformations in Computer Graphics

    7/32

    Machiraju/Zhang/Mller

    7

    Scaling in 2D

    x

    y

    =

    sx 0

    0 sy

    x

    y

    P= S P

    x

    = sx x

    y= sy y

    Uni orm sx = sy

    Non-uniform sx = sy

  • 8/12/2019 2D Transformations in Computer Graphics

    8/32

    Machiraju/Zhang/Mller

    Positive angles:

    counterclockwise

    For negative angles

    8

    Rotation about origin

    P= R P

    x = x cos(

    )

    ysin(

    )y

    = x sin() + ycos()

    cos() = cos()

    sin() = sin()

    x

    y

    =

    cos() sin()

    sin() cos()

    x

    y

  • 8/12/2019 2D Transformations in Computer Graphics

    9/32

    Machiraju/Zhang/Mller

    Make use of polar coordinates:

    9

    Derivation of rotation matrix

    x= r cos

    y= r sin()

    x= r cos +

    y= r sin(+ )x

    = r cos(+ )

    = r cos()cos() r sin() sin()

    = x cos() ysin()

    y = r sin( + )

    = r sin() cos() + r cos() sin()

    = ycos() + x sin()

    (r,) (x, y)

    (r,) (x, y)

  • 8/12/2019 2D Transformations in Computer Graphics

    10/32

    Machiraju/Zhang/Mller

    10

    Shearing in 2D

    P= SHy P

    P= SHx P

    x

    y

    =

    1 a

    0 1

    x

    y

    xy

    =

    1 0b 1

    xy

    x= x+ ay

    y= y

  • 8/12/2019 2D Transformations in Computer Graphics

    11/32

    Machiraju/Zhang/Mller

    11

    Schedule

    Geometrybasics

    Affine transformations

    Use of homogeneous coordinates Concatenation of transformations

    3D transformations

    Transformation of coordinate systems Transform the transforms

    Transformations in OpenGL

  • 8/12/2019 2D Transformations in Computer Graphics

    12/32

    Machiraju/Zhang/Mller

    12

    Homogeneous coordinates

    Only translation cannot be expressed as

    matrix-vector multiplications

    But we can add a third coordinate

    Homogeneous coordinatesfor 2D points

    (x, y) turns into (x, y, W)

    if (x, y, W) and (x', y', W ) are multiples of one

    another, they represent the same point typically, W !0.

    points with W = 0 are points at infinity

  • 8/12/2019 2D Transformations in Computer Graphics

    13/32

    Machiraju/Zhang/Mller

    13

    2D Homogeneous Coordinates

    Cartesian coordinatesof the homogenous point

    (x, y, W): x/W, y/W (divide through by W)

    Our typical homogenized points: (x, y, 1) Connection to 3D?

    (x, y, 1) represents a 3D

    point on the plane W = 1

    A homogeneous point is a

    linein 3D, through the origin

  • 8/12/2019 2D Transformations in Computer Graphics

    14/32

    Machiraju/Zhang/Mller

    14

    Transformation in

    homogeneous coordinates General form of affine (linear) transformation

    E.g., 2D translation inhomogeneous coordinates

  • 8/12/2019 2D Transformations in Computer Graphics

    15/32

    Machiraju/Zhang/Mller

    2D line equation

    Duality of 3D points to a line

    3D plane equation:

    Duality of 4D points to a plane

    Homog. Coords in 1D?

    15

    Homogeneous Coords (3)

    ax+ y +cx + = 0

    a b c d

    xy

    z

    1

    = 0

    ax+by +c = 0

    a b c

    x

    y1

    = 0

  • 8/12/2019 2D Transformations in Computer Graphics

    16/32

    Machiraju/Zhang/Mller

    16

    Basic 2D transformations

  • 8/12/2019 2D Transformations in Computer Graphics

    17/32

    Machiraju/Zhang/Mller

    17

    Inverse of transformations

    Inverse of T(dx, dy) = T("dx, "dy)

    R(#)!

    1= R("#)

    S(sx, sy)!1= S(1/sx, 1/sy)

    Sh(ax)!1= Sh("ax)

    T("dx, "dy) = T(dx, dy)!1

  • 8/12/2019 2D Transformations in Computer Graphics

    18/32

    Machiraju/Zhang/Mller

    18

    Schedule

    Geometrybasics

    Affine transformations

    Use of homogeneous coordinates Concatenation of transformations

    3D transformations

    Transformation of coordinate systems Transform the transforms

    Transformations in OpenGL

  • 8/12/2019 2D Transformations in Computer Graphics

    19/32

    Machiraju/Zhang/Mller

    19

    Compound transformations

    Often we need many transforms to build

    objects (or to direct them)

    e.g., rotation about an arbitrary point/line?

    Concatenate basic transforms sequentially

    This corresponds to multiplication of the

    transform matrices, thanks to homogeneous

    coordinates

  • 8/12/2019 2D Transformations in Computer Graphics

    20/32

    Machiraju/Zhang/Mller

    20

    Compound translation

    What happens when a point goes through

    T(dx1, dy1) and then T(dx2, dy2)?

    Combined translation: T(d

    x1

    +dx2

    , dy1

    +dy2

    )

    Concatenation of transformations: matrix multiplication

    1 0 dx2

    0 1 dy2

    0 0 1

    1 0 dx1

    0 1 dy1

    0 0 1

    =

    1 0 dx1 +dx2

    0 1 dy1 +dy2

    0 0 1

  • 8/12/2019 2D Transformations in Computer Graphics

    21/32

    Machiraju/Zhang/Mller

    21

    Compound rotation

    What happens when a point goes through

    R(#) and then R($)?

    Combined rotation: R(#+ $)

    Scaling or shearing (in one direction) is similar

    These concatenations are commutative

  • 8/12/2019 2D Transformations in Computer Graphics

    22/32

    Machiraju/Zhang/Mller

    22

    Commutativity

    Transformations that do commute:

    Translate translate

    Rotate rotate (around the same axis)

    Scale scale

    Uniform scale rotate

    Shear in x (y) shear in x (y), etc.

    In general, the order in which transformationsare composed is important

    After all, matrix multiplications are not

    commutative

  • 8/12/2019 2D Transformations in Computer Graphics

    23/32

    Machiraju/Zhang/Mller

    23

    Commutativity

    the order in which we compose matrices is

    important: matrix multiplication does not

    commute

    x

    y

    z

    x

    y

    z x

    y

    z

    x

    y

    z x

    y

    z

    X then Z

    Z then X

  • 8/12/2019 2D Transformations in Computer Graphics

    24/32

    Machiraju/Zhang/Mller

    24

    Rotation about an

    arbitrary point Break it down into easier problems:

    Translate to the origin: T("x1, "y1)

    Rotate: R(q)

    And translate back: T(x1, y1)

  • 8/12/2019 2D Transformations in Computer Graphics

    25/32

    Machiraju/Zhang/Mller

    25

    Rotation about an

    arbitrary point Compound transformation (non-commutative):

    T(x1, y1) R(q) T("x1, "y1)

    P = T(x1, y1)R(q)T("x1, "y1)P = AP

    Why combine these matrices into a single A?

  • 8/12/2019 2D Transformations in Computer Graphics

    26/32

    Machiraju/Zhang/Mller

    26

    Another example

    Compound transformation:

    T(x2, y2) R(90o) S(sx, sy) T("x1, "y1)

  • 8/12/2019 2D Transformations in Computer Graphics

    27/32

    Machiraju/Zhang/Mller

    27

    Rigid-body transformation

    A transformation matrix

    where the upper 2 %2 submatrix is

    orthonormal, preserves angles and lengths

    called rigid-bodytransformation

    any sequence of translation and rotation give a

    rigid-body transformation

  • 8/12/2019 2D Transformations in Computer Graphics

    28/32

    Machiraju/Zhang/Mller

    28

    Affine transformation

    Preserves parallelism, not lengths or angles

    Product of a sequence of translation, scaling,

    rotation, and shear is affine

    Unit cube Rot("45o) Scale in x

  • 8/12/2019 2D Transformations in Computer Graphics

    29/32

    Machiraju/Zhang/Mller

    29

    Types of Transforms

    Continuous/Discrete, one to one ; invertible

    Classification

    Euclidean (preserves angles)

    translation, rotation, uniform scale

    Affine (preserves parallel lines)

    Euclidean plus non-uniform scale, shearing

    Projective (preserves lines) Isometry (preserves distance)

    Reflection, rigid body motion

    Nonlinear (lines become curves)

    Twists, Bends, warps, morphs

  • 8/12/2019 2D Transformations in Computer Graphics

    30/32

    Machiraju/Zhang/Mller

    30

    Window-To-Viewport

    Transformation Important example of compound transform

    World coords: space users work in

    need to map world to the screen window in world-coordinate space and

    viewport in screen coordinate space

  • 8/12/2019 2D Transformations in Computer Graphics

    31/32

    Machiraju/Zhang/Mller

    one can specify non-uniform scaling

    results in distorted images

    What property of window and viewportindicates whether the mapping will distort the

    images?

    31

    Window-To-Viewport

    Transformation (2)

  • 8/12/2019 2D Transformations in Computer Graphics

    32/32

    Machiraju/Zhang/Mller

    32

    Window-To-Viewport

    Transformation (3) Specify transform in matrix form

    Mwv = T

    uminvmin

    S

    umaxumin

    xmaxxminvmaxvmin

    ymaxymin

    T

    xminymin