CENG 477 Inroducion o Compuer Graphics Modeling Transformaions
Modeling Transformaions Model coordinaes o World coordinaes: Model coordinaes: All shapes wih heir local coordinaes and sies. world World coordinaes: All shapes wih heir absolue coordinaes and sies. world world CENG 477 Compuer Graphics
Basic Geomeric Transformaions Used for modeling, animaion as well as viewing Wha o ransform? We picall ransform he verices (poins) and vecors describing he shape (such as he surface normal) This works due o he lineari of ransformaions Some, bu no all, ransformaions ma preserve aribues like sies, angles, raios of he shape CENG 477 Compuer Graphics 3
Translaion Simpl move he objec o a relaive posiion ' + ' + ' T ' ' ' ' + T CENG 477 Compuer Graphics 4
Roaion A roaion is defined b a roaion ais and a roaion angle For D roaion, he parameers are roaion angle () and he roaion poin ( r, r ) We reposiion he objec in a circular pah around he roaion poin (pivo poin) r a r CENG 477 Compuer Graphics 5
Roaion When ( r, r )(,) we have: ʹ r cos( φ + ) r cosφ cos r sinφ sin ʹ r sin( φ + ) r cosφ sin + r sinφ cos r cosφ The original coordinaes are: r sin φ ' Subsiuing hem in he firs equaion we ge: In he mari form we have: ʹ ʹ ʹ cos sin + R sin cos cos sin R sin cos CENG 477 Compuer Graphics 6
Roaion Roaion around an arbirar poin ( r, r ) ʹ ʹ r r + ( r + ( r )cos ( )sin + ( r r )sin )cos ( r, r ) ' These equaions can be wrien as mari operaions (we will see when we discuss homogeneous coordinaes) CENG 477 Compuer Graphics 7
Scaling Changes he sie of an objec Inpu: scaling facors (s, s ) ' s ' s ' S s s ' S non-uniform vs. uniform scaling CENG 477 Compuer Graphics 8
Homogenous Coordinaes Translaion is addiive, roaion and scaling is muliplicaive (and addiive if ou roae around an arbirar poin or scale around a fied poin) Goal: Make all ransformaions as mari operaions Soluion: Add a hird dimension h h h h h h h h h h CENG 477 Compuer Graphics 9
Homogenous Coordinaes In HC, each poin now becomes a line The enire line represens he same poin The original (non-homogeneous) poin resides on he w plane w All poins along his line in HC represen he same poin, p p p w CENG 477 Compuer Graphics
Transformaions in HC Translaion: Roaion: Scaling: ( ) ( ) where ', T, T ( ) ( ) cos sin sin cos where R R ' ( ) ( ) ʹ where s s,s s S,s s S CENG 477 Compuer Graphics
Transforming Vecors Vecors can be roaed and scaled Bu ranslaing a vecor does no change i! Wh? A vecor is a difference beween wo poins These wo poins ranslae he same wa So he vecor remains he same Mahemaicall his can be achieved b seing he las coordinae of a vecor o (he las coordinae of poins should be ) D poin in HC is equal o D vecor in HC is equal o CENG 477 Compuer Graphics
Composie Transformaions Ofen, objecs are ransformed muliple imes Such ransformaions can be combined ino a single composie ransformaion E.g. Applicaion of a sequence of ransformaions o a poin: ʹ M M M CENG 477 Compuer Graphics 3
Composie Transformaions Composiion of he same pes of ransformaions is simple E.g. ranslaion: ( ) ( ) ( ) +, + T, T, T + + T T T T ʹ )}, ( ), ( { } ), ( { ), ( CENG 477 Compuer Graphics 4
( ) ( ) ( ) s,s s s s s s s s s s s,s s,s s S S S ( ) ( ) ( ) +φ +φ +φ +φ +φ φ φ+ φ φ+ φ φ φ φ φ R R R ) cos( ) sin( ) sin( ) cos( cos cos sin sin sin cos cos sin cos sin sin cos sin sin cos cos cos sin sin cos cos sin sin cos ϕ ϕ ϕ ϕ Composie Transformaions Roaion and scaling are similar: CENG 477 Compuer Graphics 5
Roaion Around a ivo oin Sep : Translae he objec so ha he pivo poin moves o he origin (, ) T r r M T (, ) r r CENG 477 Compuer Graphics 6
Roaion Around a ivo oin Sep : Roae around origin R( ) M R( ) CENG 477 Compuer Graphics 7
Roaion Around a ivo oin Sep 3: Translae he objec so ha he pivo poin is back o is original posiion (, ) T r r M 3 T (, ) r r CENG 477 Compuer Graphics 8
Roaion Around a ivo oin The composie ransformaion is equal o heir successive applicaion: M (, ) R( ) (, ) M 3M M T T r r r r CENG 477 Compuer Graphics 9
Scaling w.r.. a Fied oin The idea is he same: Translae o origin Scale Translae back ( ) ( ) ( ) ( ) ( ) f f f f f f f f f f s s s s s s,,s s, T S T ( ) f f, T ( ) s, s S ( ) f f, T CENG 477 Compuer Graphics
Order of mari composiions Mari composiion is no commuaive. So, be careful when appling a sequence of ransformaions. ivo ivo Roaion and ranslaion Translaion and roaion CENG 477 Compuer Graphics
Oher Transformaions Reflecion: special case of scaling CENG 477 Compuer Graphics
Oher Transformaions Shear: Deform he shape like shifed slices (or deck of cards). Can be in or direcion (,) (,) (,) (3,) ' sh ' sh CENG 477 Compuer Graphics 3
3D Transformaions Similar o D bu wih an era componen We assume a righ handed coordinae ssem Wih homogeneous coordinaes we have 4 dimensions Basic ransformaions: Translaion, roaion, scaling Equivalen was of hinking abou a righ-handed CS CENG 477 Compuer Graphics 4
Translaion Move he objec b some offse: ʹ ʹ ʹ T ʹ ʹ CENG 477 Compuer Graphics 5
Roaion Roaion around he coordinae aes -ais -ais -ais osiive angles represen couner-clockwise (CCW) roaion when looking along he posiive half owards origin CENG 477 Compuer Graphics 6
Roaion Around Major Aes Around : Around : Around : cos sin sin cos ) ( R R ʹ ) ( cos sin sin cos ) ( R R ʹ ) ( cos sin sin cos ) ( R R ʹ ) ( CENG 477 Compuer Graphics 7
Roaion Around a arallel Ais Roaing an objec around a line parallel o one of he aes: Translae o a major ais, roae, ranslae back E.g. roae around a line parallel o -ais: ʹ T,, ) R ( ) T(,, ) ( p p p p ( p, p ) Translae Roae Translae back CENG 477 Compuer Graphics 8
Roaion Around an Arbirar Ais Sep : Translae he objec so ha he roaion ais passes hough he origin Sep : Roae he objec so ha he roaion ais is aligned wih one of he major aes Sep 3: Make he specified roaion Sep 4: Reverse he ais roaion Sep 5: Translae back CENG 477 Compuer Graphics 9
Roaion Around an Arbirar Ais CENG 477 Compuer Graphics 3
Roaion Around an Arbirar Ais Firs deermine he ais of roaion: v (,, ) u is he uni vecor along v: u v v ( a, b, c) CENG 477 Compuer Graphics 3
Roaion Around an Arbirar Ais Ne ranslae o origin: T CENG 477 Compuer Graphics 3
Roaion Around an Arbirar Ais Then align u wih one of he major ais (,, or ) This is a wo-sep process: Roae around o bring u ono plane (CCW) Roae around o align he resul wih he -ais (CW) u α β u We need cosine and sine of angles α and ß CENG 477 Compuer Graphics 33
Roaion Around an Arbirar Ais We need cosine and sine of angles α and ß: u u' u α u u u u + u + u u + u where u cos c b d d c + uʹ α d b ʹ u u sinα ) ( d c d b d b d c R α CENG 477 Compuer Graphics 34
Roaion Around an Arbirar Ais We need cosine and sine of angles α and ß: u cos c b a c b u u + + + + u β u u + β u sin c b a a u + + u β + + + + + + + + + + ) ( c b a c b c b a a c b a a c b a c b R β CENG 477 Compuer Graphics 35 Noe ha a & + b & + c & - +
Roaion Around an Arbirar Ais uing i all ogeher: ),, ( ) ( ) ( ) ( ) ( ) ( ),, ( ) ( T R R R R R T R α β β α This is he acual desired roaion. Oher erms are for alignmen and undoing he alignmen CENG 477 Compuer Graphics 36 - +
Alernaive Mehod Assume we wan o roae around he uni vecor u: We creae an orhonormal basis (ONB) uvw: u v w u ) To find v, se he smalles componen of u (in an absolue sense) o ero and swap he oher wo while negaing one: E.g. if u (a, b, c) wih c being he smalles absolue value hen v (-b, a, ) This corresponds o projecing he vecor o he neares major plane and roaing i 9 along he ais perpendicular o ha plane ) w u v 3) Normalie v and w Noe ha we are jus finding one of he infiniel man soluions CENG 477 Compuer Graphics 37
Alernaive Mehod Now roae uvw such ha i aligns wih : call his ransform M Roae around (u is now ) Undo he iniial roaion: call his M - Finding M - (roaing o uvw) is rivial: How o ransform [ ] T such ha i urns ino [u u u ] T Similar for he and ais M u u u v v v w w w Verif ha his mari ransforms o u, o v, and o w CENG 477 Compuer Graphics 38
Alernaive Mehod Finding M is also rivial as M - is an orhonormal mari (all rows and columns are orhogonal uni vecors) For such marices, inverse is equal o ranspose: CENG 477 Compuer Graphics 39 w w w v v v u u u M
Alernaive Mehod The final roaion ransform is: M,- R / ()M We assumed ha he origin of uvw is he same as he origin of Oherwise, we should accoun for his difference: T,- M,- R / ()MT Undo he ranslaion Translae he origin of uvw o CENG 477 Compuer Graphics 4
Scaling Change he coordinaes of he objec b scaling facors ' ' ' s s s ʹ ʹ S CENG 477 Compuer Graphics 4
Scaling w.r.. a Fied oin Translae o origin, scale, ranslae back Translae Scale Translae back T S T ʹ ),, ( ),, ( f f f f f f CENG 477 Compuer Graphics 4
Reflecion Reflecion over he major planes: How abou reflecion over an arbirar plane? CENG 477 Compuer Graphics 43
Transforming Normals When we ransform an objec, wha happens o is normals? Do he ge ransformed b he same mari or does i require a differen one? Scale b: n / / S 3 n 3/ / 3 CENG 477 Compuer Graphics 44
Transforming Normals Afer he ransformaion he normal is no longer perpendicular o he objec Also i is no a uni vecor anmore Scale b: n / / S 3 n 3/ / 3 CENG 477 Compuer Graphics 45
Transforming Normals Roaion and ranslaion has no problems Bu, since all ransformaions are combined ino a single mari M, we should consider he general case. n v b a We mus have n.(b-a) n.v and his relaionship should be preserved afer he ransformaion CENG 477 Compuer Graphics 46
Transforming Normals Tha is n.v and n'.v' where v' Mv and n' Zn Z is he mari we are looking for How o compue Z? n v b a CENG 477 Compuer Graphics 47
Transforming Normals n.v n T v n'.v' n' T v' n' T Mv n T Z T Mv If Z T M I (ideni) he relaionship will be preserved So Z (M - ) T Noe ha his is equal o (M T ) - as (M - ) T (M T ) - for a square (n b n) mari M n v b a CENG 477 Compuer Graphics 48
A Word on Noaion Unil now, we performed ransformaions b mulipling our poins from he righ: 9 9 9 a b c d e f g h i j k l Anoher noaion is o mulipl from he lef: 9 9 9 a b c d e f g h i j k l D Noe ha in his case everhing is ransposed CENG 477 Compuer Graphics 49
A Word on Terminolog Imagine a D roaion mari such as: Transforming an objec b his mari will no change is shape If we also add ranslaion: cos () sin () sin () cos () The shape will remain inac cos () sin () / sin () cos () M CENG 477 Compuer Graphics 5
A Word on Terminolog In general, an arbirar sequence of roaion and ranslaion marices will have he following form: r -- r -& / r &- r && M Such ransformaions are called rigid-bod ransformaions A shape ma be roaed and ranslaed b is form is no alered in an wa CENG 477 Compuer Graphics 5
A Word on Terminolog Imagine also adding scaling The mari will now look like: a b / c d M where a, b, c, d conain he effec of roaion and scaling combined Such ransformaions will no necessaril preserve lenghs and angles, bu parallel lines will remain parallel Original Roaion Roaion and scaling CENG 477 Compuer Graphics 5
A Word on Terminolog Such ransformaions are called affine ransformaions An arbirar sequence of roaion, ranslaion, scaling, and shearing will produce an affine ransformaion Noe ha we sill have some degrees of freedom lef in he las row of our mari: a b / c d M B using his we can creae projecive ransformaions in which parallel lines ma no longer be parallel CENG 477 Compuer Graphics 53