2D Transformations Các phép biến đổi 2D

  • View
    62

  • Download
    1

Embed Size (px)

DESCRIPTION

2D Transformations Cc php bin i 2D. Gii thiu. Bn cht ca php bin i hnh hc l thay i v tr ca i tng, lm thay i i tng v hng, kch thc, hnh dng. Hai phng php bin i hnh hc: Bin i i tng: thay i ta ca i tng. - PowerPoint PPT Presentation

Transcript

  • 2D TransformationsCc php bin i 2D

    Chris Weigle - Comp 136

  • Gii thiuBn cht ca php bin i hnh hc l thay i v tr ca i tng, lm thay i i tng v hng, kch thc, hnh dng.

    Hai phng php bin i hnh hc:Bin i i tng: thay i ta ca i tng.

    Bin i h ta : to h ta mi v tt c i tng s c chuyn v h ta mi.

    Cc php bin i hnh hc c bn: tnh tin, quay, bin i t l, bin dng.

    Chris Weigle - Comp 136

  • Php bin i hnh hcMt php bin i l mt nh x T:

    Chris Weigle - Comp 136

  • Php bin i hnh hc (cont.)Php bin i Affine l php bin i vi f(x,y) v g(x,y) l 2 hm tuyn tnh:

    Biu din php bin i Affine di dng ma trn:

    Thng thng, chng ta ch kho st php bin Affine nn ta thng dng thut ng php bin i ng l php bin i Affine.

    Chris Weigle - Comp 136

  • Php tnh tin - TranslationPhp tnh tin dng dch chuyn i tng t v tr ny sang v tr khc.

    Chris Weigle - Comp 136

  • Php tnh tin (cont.)Gi tr = (trx , try) l vector tnh tin t im P n im Q th:

    Ma trn bin i ca php tnh tin:

    Chris Weigle - Comp 136

  • Php quay - Rotationi hng i tng.Php quay gm c tm quay C, gc quay . Bin i im P thnh Q sao cho:P v Q nm trn ng trn tm C, Gc PCQ bng

    Do v tr ca tm quay nn ta c 2 loi php quay:Php quay quanh gc ta Php quay quanh mt tm bt k

    Gc quay theo qui c chiu dng l ngc chiu kim ng h.CQP

    Chris Weigle - Comp 136

  • Php quay mt gc quanh gc ta

    Chris Weigle - Comp 136

  • Php quay mt gc quanh gc ta Php i xng tm (gc ta )P v Q i xng qua gc ta . Do , php i xng tm l php quay quanh gc ta mt gc 1800.

    Chris Weigle - Comp 136

  • Php quay mt gc quanh tm bt kPT(-xc,-yc)PT()QT(xc,yc)Q

    Chris Weigle - Comp 136

  • Ta c th chng minh php quay tm C(xc, yc) mt gc l kt hp ca cc php bin i sau y:Tnh tin theo vector (-xc,-yc) dch chuyn tm quay v gc ta : P = T(-xc, -yc) . PQuay quanh gc ta mt gc : Q = T() . PTnh tin theo vector (xc,yc) a tm quay v v tr ban u: Q = T(xc,yc) . QKt hp 3 php bin i trn ta c: Q = T(xc,yc) . T() . T(-xc,-yc) . PNh vy, ma trn bin i ca php quay tm bt k l:

    Php quay mt gc quanh tm bt k (cont.)

    Chris Weigle - Comp 136

  • Php bin i t l - ScalingCo gin i tng

    sx v sy c gi l h s co gin theo trc x v trc y

    Chris Weigle - Comp 136

  • Php bin i t l (cont.)Khi sy = 1 th i tng co gin theo trc x

    Khi sx = 1 th i tng co gin theo trc y

    Chris Weigle - Comp 136

  • Php bin i t l (cont.)Khi sy = sy th ta gi y l php bin i ng dng uniform scaling, bo ton tnh cn xng ca i tng. Nu sx = sy < 1 th y l php thu nh, ngc li th y l php phng to

    Thu nhPhng to

    Chris Weigle - Comp 136

  • Php bin i t l (cont.)Php i xng trc

    i xng qua trc honh:

    i xng qua trc tung:

    Chris Weigle - Comp 136

  • Php bin dng - ShearingThay i hnh dng ca i tng

    Php bin dng theo trc x lm thay i honh cn tung gi nguyn.

    Php bin dng theo trc y lm thay i tung cn honh gi nguyn.

    Chris Weigle - Comp 136

  • Php bin dng - ShearingPhp bin dng tng qut

    Chris Weigle - Comp 136

  • Bi tpBin i i tng 2D

    M t tnh cht hnh hc ca i tng

    Tm, c ta so vi h ta thc : centerDng hnh hc, c dng a gic i xng qua tm : pointsMu sc : color

    centerpointscolorH ta thcH ta i tng

    Chris Weigle - Comp 136

  • Bi tpBin i i tng 2D (cont.)

    p dng cc php bin i trn i tng

    Tnh tin i tng bng vect tr, thc cht l tnh tin tm ca i tngQuay i tng theo gc angle, thc cht l quay cc nh ca a gic

    H ta thctr

    Chris Weigle - Comp 136

  • Bi tpBin i i tng 2D (cont.)

    Cu trc d liu#define MAXNUMPOINTS10struct Point2D{double x, y;};struct Object{Point2D center;Point2D points[MAXNUMPOINTS];int numOfPoints;int color;Point2D tr;double angle;// };

    Chris Weigle - Comp 136

  • Bi tpBin i i tng 2D (cont.)

    V i tng i tng: void drawObject(Object &o);V a gic xc nh bi points, lu cc im points[i] c ta thc l: points[i] + centeri tng c v bng mu color

    Tnh tin i tng: void translateObject(Object &o);Tnh tin tm ca i tng theo vect tnh tin : center = center + trLu trng hp i tng vt khi khung nhn:Tnh li tm ca i tngTnh li vect tnh tintr

    Chris Weigle - Comp 136

  • Bi tpBin i i tng 2D (cont.)

    Quay i tng: void roatateObject(Object &o);Quay cc nh ca a gic ca i tng theo theo gc angle : rotatePoints(o.points[i], o.angle);Chng trnh chnh:Object o;initObject(o);while (!kbhit()){o.color = CYAN;drawObject(o);delay(50);o.color = BLACK;drawObject(o);translateObject(o);ratateObject(o);// }

    Chris Weigle - Comp 136

    Chris Weigle - Comp 136