Académique Documents
Professionnel Documents
Culture Documents
Ian Parberry
University of North Texas
Chapter 8 2otes
Word Cloud
Chapter 8 2otes
Section 8%'6
Chapter 8 2otes
8rientation
What is orientation: 3ore than direction% ; &ector speci ies direction but it can also be t(isted%
Chapter 8 2otes
Chapter 8 2otes
Chapter 8 2otes
Chapter 8 2otes
Section 8%)6
3atri* Form
Chapter 8 2otes
'C
3atri* Form
Dist the relati&e orientation o t(o coordinate spaces by listin! the trans ormation matri* that takes one space to another% For e*ample6 rom ob"ect space to upri!ht space% Trans orm back by usin! the in&erse matri*%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& ''
+*ample
WeE&e seen ho( a matri* can be used to trans orm points rom one coordinate space to another% In the i!ure on the ne*t slide$ the matri* in the upper ri!ht hand corner can be used to rotate points rom the ob"ect space o the "et into upri!ht space% WeE&e pulled out the ro(s o this matri* to emphasiFe their direct relationship to the coordinates or the "etEs body a*es% The rotation matri* contains the ob"ect a*es e*pressed in upri!ht space% Simultaneously$ it is a rotation matri*% We can multiply ro( &ectors by this matri* to trans orm those &ectors rom ob"ect space coordinates to upri!ht space coordinates%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& ')
Chapter 8 2otes
'#
; Coders Dament
<ut practically speakin!$ in our opinion$ it is /uite important% ;t issue is (hether you can (rite code that is intuiti&e to read and (orks the irst time$ or i it re/uires a lot o (ork to decipher$ or a kno(led!e o con&entions (hich are not stated since they are ob&ious to e&eryone but you% 8ur opinions come rom (atchin! pro!rammers !rapple (ith rotation matrices% We donEt e*pect that e&eryone (ill a!ree (ith us$ but (e hope that e&ery reader (ill at least appreciate the &alue in considerin! these issues%
Chapter 8 2otes
'.
Chapter 8 2otes
'0
<utH
It is a common practice to use the !eneric trans ormation matri* class to describe the orientation o an ob"ect% In this case$ rotation is treated "ust like any other trans ormation% The inter ace remains in terms o a source and destination space% It is our e*perience that the ollo(in! t(o matri* operations are by ar the most commonly used6
'% Take an ob"ect space &ector and e*press it in upri!ht coordinates% )% Take an upri!ht space &ector and e*press it in ob"ect coordinates%
Chapter 8 2otes
'1
Chapter 8 2otes
'8
Chapter 8 2otes
'B
Chapter 8 2otes
)C
In Code
Rotate some &ector rom ob"ect space to upri!ht space is translated into code as multiplication by the matri*% Rotate a &ector rom upri!ht space to ob"ect space is translated into code as multiplication by the in&erse o the matri*% =;ctually$ multiplication by the transpose$ since rotation matrices are ortho!onal$ but that is not the point here%>
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& )'
8n Codin! Style
2otice that the code does not match one-to-one (ith the hi!h-le&el intentions o the pro!rammer% Furthermore$ to read or (rite this code re/uires that you kno( (hat the con&entions are% It is our opinion that this codin! style is a contributin! actor to the di iculty that be!innin! pro!rammers ha&e in learnin! ho( to use matrices%
Chapter 8 2otes
))
?ust a 3atri*:
;n e/ui&alent practice is to not use a class at all$ and "ust declare a matri* (ith somethin! like float R L#ML#M % This style o code (ill orce e&ery user to remember (hat the con&entions are e&ery time they use the matri*% From our e*perience$ they are usually not documented$ since it (as o"vio s to the author o this code ho( it (as supposed to (ork% This in&ariably results in iddlin! and random transposin! by the uninitiated$ (ho are orced to re&erse en!ineer the arbitrary con&entions throu!h trial and error%
Chapter 8 2otes
)#
Chapter 8 2otes
),
Chapter 8 2otes
).
Chapter 8 2otes
)0
It Shouldnt 3atter
So$ back to the /uestion posed earlier6 Which matri* should (e use: 8ur ans(er is 7It shouldnEt matter%9 <y that (e mean there is a (ay to desi!n your matri* code in such a (ay that it can be used (ithout kno(in! (hat choice (as made%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& )1
Chapter 8 2otes
)8
Chapter 8 2otes
)B
Chapter 8 2otes
#C
These a*es can be interpreted as !eometric rather than al!ebraic entities$ so it really does not matter (hat coordinates are used to describe the a*es =pro&ided (e use the same coordinate space to describe all o them>$ the rotation matri* (ill be the same%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& #)
+*ample
For e*ample$ letEs say that our a*es are described usin! the irst coordinate space% Then ha&e the tri&ial orms L'$ C$ CM$ LC$ '$ CM and LC$ C$ 'M$ respecti&ely% The basis &ectors o the second space$ are not e*pressed in their o(n space$ and thus they ha&e arbitrary coordinates% When (e substitute the tri&ial &ectors into the matri* on the pre&ious slide and e*pand the dot products$ (e !et6
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& ##
Chapter 8 2otes
#,
Conclusion
In other (ords$ the ro(s o the rotation matri* are the basis &ectors o the output coordinate space$ e*pressed usin! the coordinates o the input coordinate space% 8 course$ this act is not "ust true or rotation matrices$ itEs true or all trans ormation matrices% This is the central idea o (hy a trans ormation matri* (orks$ (hich (as de&eloped in Chapter ,%
Chapter 8 2otes
#.
Chapter 8 2otes
#1
Conclusion
This says that the columns o the rotation matri* are ormed rom the basis &ectors o the input space$ e*pressed usin! the coordinates o the output space% This is not true o trans ormation matrices in !eneralO it applies only to ortho!onal matrices such as rotation matrices%
Chapter 8 2otes
#8
Chapter 8 2otes
#B
Chapter 8 2otes
,C
Chapter 8 2otes
,'
Chapter 8 2otes
,#
Chapter 8 2otes
,,
Chapter 8 2otes
,0
Chapter 8 2otes
,1
Chapter 8 2otes
,8
Section 8%#6
+uler ;n!les
Chapter 8 2otes
,B
+uler ;n!les
+uler an!les are another common method o representin! orientation% +uler is pronounced 7oiler$9 not 7yoolur%9 They are named or the amous mathematician (ho de&eloped them$ Deonhard +uler ='1C1 G'18#>% =Ima!e rom Wikimedia Commons%>
Chapter 8 2otes
.C
+uler ;n!les
Speci y orientation as a series o # an!ular displacements rom upri!ht space to ob"ect space% Which a*es: Which order: 2eed a con&ention% @eadin!-pitch-bank
@eadin!6 rotation about y a*is =aka 7ya(9> Pitch6 rotation about x a*is <ank6 rotation about $ a*is =aka 7roll9>
Chapter 8 2otes
.'
@eadin!
Chapter 8 2otes
.#
Pitch
Chapter 8 2otes
.,
<ank
Chapter 8 2otes
..
Chapter 8 2otes
.0
Whats in a 2ame:
@eadin!-pitch-bank is o ten called yaw%pitch%roll =at the time o (ritin!$ the latter has a Wikipedia pa!e but the ormer doesnt> @eadin! is ya($ bank is roll% This came rom the aerospace industry$ (here ya( in act !oesn&t mean headin! the (ay (e interpret it% 8ther less common terms are o ten used%
'ea!ing also !oes by the name a$im th% Pitch is also called attit !e or elevation% (an) is sometimes called tilt$ or twist%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& .8
<ack to Ya(-pitch-roll
Perhaps more interestin! is that act that you (ill o ten hear these same three (ords listed in the opposite order6 rollpitch-ya(% ;s it turns out$ there is a per ectly reasonable e*planation or this back(ards con&ention6 itEs the order that (e actually do the rotations inside a computerQ
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& .B
+*ample
The i*ed-a*is system and the +uler an!le system are e/ui&alent$ pro&ided that you take the rotations in the opposite order% DetEs say (e ha&e a headin! =ya(> o h and a pitch o p% ;ccordin! to the +uler an!le con&ention6
We irst do the headin! and rotate about the ob"ect space y-a*is by h% Then (e rotate about the ob"ect space x-a*is by p%
Isin! a i*ed-a*is scheme (e !et to this same endin! orientation by doin! the rotations in the opposite order%
First$ (e do the pitch$ rotatin! about the upri!ht x-a*is by p% Then$ (e per orm the headin!$ rotatin! about the upri!ht y-a*is by h%
Chapter 8 2otes
0'
3ore Dater
;lthou!h (e mi!ht &isualiFe +uler an!les$ inside a computer (hen rotatin! &ectors rom upri!ht space to ob"ect space$ (e (ill actually use a i*ed-a*is system% WeEll discuss this in !reater detail (hen (e learn ho( to con&ert +uler an!les to a rotation matri*%
Chapter 8 2otes
0)
Chapter 8 2otes
0,
;liasin!
There are many (ays to represent a sin!le orientation$ e!% Pitch do(n '#. is the same as headin! '8C $ pitch do(n ,. $ then bank '8C % This is called the aliasing problem% 3akes it hard to con&ert orientations rom ob"ect to (orld space$ e!% 7;m I acin! +ast:9
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& 0.
Chapter 8 2otes
00
4imbal Dock
Chan!e headin! =y a*is> by ,. Pitch do(n BC 2o( i you bank$ your ob"ect space $ a*is is pointin! in (orld space (here your ob"ect space y a*is (as be ore you started your rotations% So any rotation about $ could ha&e been done as a headin! chan!e%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& 01
Chapter 8 2otes
08
@int or Pro!rammers
When (ritin! CNN that accepts +uler an!le ar!uments$ itEs usually best to ensure that they (ork !i&en +uler an!les in any ran!e% Duckily this is usually pretty easy$ and re/uently "ust automatically (orks (ithout takin! any e*tra precaution$ especially i the an!les are ed into tri! unctions% @o(e&er$ (hen (ritin! code that computes or returns +uler an!les$ itEs a !ood practice to try to return the canonical +uler an!le triple%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& 0B
Chapter 8 2otes
1C
Chapter 8 2otes
1'
Chapter 8 2otes
1)
Problems
2ot !ood (ith noncanonical an!les% For e*ample$ to interpolate rom 1)C to ,. in ' increments (ould mean turnin! around t(ice%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& 1#
Function wrapPi
De ine the ollo(in! unction6 Isin! (rapPi=> makes it easy to take the shortest arc (hen interpolatin! bet(een t(o an!les%
Chapter 8 2otes
10
;nother Problem
+&en (ith these t(o band-aid solutions$ you are le t (ith !imbal lock% Solution6 dont use +uler an!les or interpolation% Ise somethin! else$ like /uaternions%
Chapter 8 2otes
11
Chapter 8 2otes
1B
Chapter 8 2otes
8C
Chapter 8 2otes
8'
Section 8%,6
Chapter 8 2otes
8)
+*ponential 3aps
The t(o &alues n and V describe an an!ular displacement in axis% angle form% ;lternati&ely$ since n has unit len!th$ (ithout loss o in ormation (e can multiply it by V$ yieldin! the sin!le &ector e T Vn% This scheme or describin! rotation !oes by the rather intimidatin! and obscure name o exponential map% The rotation an!le can be deduced rom the len!th o e$ i%e% V T WWeWW$ and the a*is is obtained by normaliFin! e% The e*ponential map is not only more compact than a*is-an!le =# numbers instead o ,>$ it ele!antly a&oids certain sin!ularities and has better interpolation and di erentiation properties%
Chapter 8 2otes
8,
8ther ;liases
The other aliases cannot be dispatched so easily% ;s (ith +uler an!les$ addin! a multiple o #0CK to V produces an an!ular displacement that results in the same orientation$ in both the a*is-an!le and the e*ponential map% @o(e&er$ this is not al(ays a shortcomin! G or describin! an!ular displacement$ this ability to represent such e*tra rotation is an important and use ul property% For e*ample$ itEs /uite important to be able to distin!uish bet(een rotation about the xa*is at a rate o 1)CK per second$ &ersus rotation about the same a*is at a rate o 'C8CK per second$ e&en thou!h these displacements result in the same endin! orientation i applied or an inte!ral number o seconds% It is not possible to capture this distinction in /uaternion ormat%
Chapter 8 2otes
88
Chapter 8 2otes
8B
Concatenatin! Rotations
Suppose e' and e) are rotations in e*ponential map ormat% The result o per ormin! the rotations in se/uence$ or e*ample e' then e)$ is not the same as per ormin! the rotation e' N e)$ because &ector addition is commutati&e$ but three-space rotations are not% For e*ample$ suppose that e' is a BCK do(n(ard pitch rotation$ and e) is a BCK +ast(ard headin! rotation$ that is$ e' T LBCK$ C$ CM$ and e) T LC$ BCK$ CM% Per ormin! e' ollo(ed by e)$ (e (ould end up lookin! do(n(ard (ith our head pointin! +ast$ but doin! them in the opposite order$ (e end up on our ear acin! +ast%
Chapter 8 2otes
BC
Chapter 8 2otes
B'
Terminolo!y Disclaimer
;lternati&e names or these concepts abound% We ha&e tried to choose the most standard names (e could$ but it (as di icult to ind any consensus in the literature% Some authors use the term axis%angle to describe both a*is-an!le and e*ponential map and donEt really distin!uish bet(een them% +&en more con usin! is the use o the term * ler axis to re er to either orm =but not to +uler an!lesQ>% +otation vector is another term you mi!ht see attached to (hat (e are callin! exponential map% Finally$ the term exponential map$ in the broader conte*t o Die al!ebra$ rom (hence the term ori!inates$ actually re ers to an operation =a map> rather than a /uantity%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& B)
Section 8%.6
Auaternions
Chapter 8 2otes
B#
Auaternions
Auaternions (ere in&ented by the Irish mathematician Sir William Ro(an @amilton in '8,#% They ha&e been the cause o much puFFlement to students since then% =Ima!e rom Wikimedia Commons%>
Chapter 8 2otes
B,
Chapter 8 2otes
B.
2erd ;lertQ
8n his (ay$ as he (as passin! o&er <room =<rou!hamS<roome> <rid!e$ he disco&ered the undamental /uaternion ormula6 i) T #) T )) T i#) T G'% @e (as so e*cited about this that he scratched the ormula onto the brid!e (ith his penkni e% 2o trace can be ound today$ but in 'B.8 a pla/ue (as erected on the site%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& B0
Auaternions Jersion )6
Jector-Scalar 2otation
Instead o the ima!inary number notation6 w - xi - y# - $) use &ector-scalar notation6 ! / L w v M$ (here w is a scalar and v a &ector% ;lternati&ely6 !/Lw=xy$>M =its the same w, x, y, $>.
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& BB
Auaternions Jersion #6
,D Space
@amilton himsel thou!ht o /uaternions as ,D &ectors Lw, x, y, $M% @o(e&er$ /uaternions are not the same as &ectors in homo!enous ,D space Lx, y, $, wM% In particular$ his w is not the same as the w in homo!enous ,D space%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& 'CC
Comple* 3ultiplication
; rotation =represented as a comple* number> can be applied to a point =also represented as a comple* number> usin! multiplication o comple* numbers% =x - yi> =cos N i sin > T =x cos G y sin > N i =x sin
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De&
N y cos >
'C#
Chapter 8 2otes
'C,
Chapter 8 2otes
'C0
Chapter 8 2otes
'C1
Points as Auaternions
Represent #D point = x y $ > as the /uaternion p T L C = x y $ > M% 8r e/ui&alently in comple* number notation6 xi - y# - $). 4ames !enerally dont implement the C &alue or w%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& 'C8
Rotations as Auaternions
The scalar part 7kind o 9 represents the an!le% The &ector part 7kind o 9 represents the a*is% Rotation by an an!le around unit a*is n is represented by the /uaternion6 " T L cos S) T L cos S)
Chapter 8 2otes
sin S) n M
Auaternion 2e!ation
I ! T L( =* y F>M T L( vM is a /uaternion$ de ine its ne!ation to be6 G! T GL( =* y F>M T LG( =G* Gy GF>M T GL( vM T LG( GvM% Surprisin!ly$ ! T G!% The /uaternions ! and G! describe the same an!ular displacement% ;ny an!ular displacement in #D has e*actly t(o distinct representations in /uaternion ormat$ and they are ne!ati&es o each other% ItEs not too di icult to see (hy% I (e add #0CK to $ it doesnEt chan!e the an!ular displacement represented by !$ but it ne!ates all our components o !%
Chapter 8 2otes
''C
Auaternion 3a!nitude
The ma!nitude o a /uaternion is
Chapter 8 2otes
'''
Chapter 8 2otes
'')
Auaternion 3ultiplication
Chapter 8 2otes
'',
Chapter 8 2otes
''.
Chapter 8 2otes
''0
Concatenatin! Rotations
2otice that rotatin! by a and then by b is e/ui&alent to per ormin! a sin!le rotation by the /uaternion product ba% Thus$ /uaternion multiplication can be used to concatenate multiple rotations$ "ust like matri* multiplication% We say 7"ust like matri* multiplication$9 but in act there is a sli!htly irritatin! di erence%
With matri* multiplication$ our pre erence to use ro( &ectors puts the &ectors on the le t$ resultin! in the nice property that concatenated rotations read le tto-ri!ht in the order o trans ormation% With /uaternions$ (e donEt ha&e this le*ibility6 concatenation o multiple rotations (ill al(ays read rom ri!ht to le t%
Chapter 8 2otes
''8
8rder o 3ultiplication
This means that to apply a rotation /uaternion ! ollo(ed by a rotation /uaternion r$ (e apply the product /uaternion !r6 r-'=!-'p !>r T =!r>-'p =!r> This is cool because /uaternion multiplication is done the same order as the trans ormations% <ooks that use column &ectors o ten de ine /uaternion product back(ards G re&ersin! the order o the cross product G to make the order natural or them%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& ''B
Auaternion Di erence
Det a and b be /uaternions representin! t(o orientations% The /uaternion d that takes orientation a to orientation b is called the 1 aternion !ifference bet(een a and b% Want ad T b% What is d: d T a-'b Why: ad T a=a-'b> T =aa-'>b T L ' # M b T b
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& ')'
Auaternion Do!
;s a shorthand$ let [ T 34. Det n be a unit &ector% Suppose /uaternion ! T Lcos [ n sin [M The logarithm o !$ denoted lo! !$ is de ined to be LC$ [nM% 2ote that lo! ! is not necessarily a unit /uaternion% ;lso note the similarity bet(een the logarithm of a 1 aternion and the exponential map format%
Chapter 8 2otes
')#
Auaternion +*ponential
The e*ponential unction or /uaternions is de ined in the e*act opposite manner% Suppose p T LC$ [nM$ (here n is a unit &ector% The e*ponential o p$ denoted e*p p$ is de ined to be Lcos [ n sin [M% 2ote that e*p p is al(ays a unit /uaternion% Auaternion lo! and e*ponential are in&erses$ that is$ or all /uaternions !$ e*p=lo! !> T lo!=e*p !> T !%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& '),
Auaternion +*ponentiation
We used the term 7e*ponential9 be ore$ no( its time or e*ponentiation% I ! is a /uaternion and t is a scalar$ de ine !t T e*p =t lo! !>% ;s t &aries rom C to '$ the /uaternion !t &aries rom L'$ #M to !% Auaternion e*ponentiation is use ul because it allo(s us to e*tract a raction o an an!ular displacement% For e*ample$ !'S# is a /uaternion that represents 'S#rd o the an!ular displacement represented by the /uaternion !%
Chapter 8 2otes
')0
The Ca&eat
The ca&eat (e mentioned is this6 a /uaternion represents an!ular displacements usin! the shortest arc% 3ultiple spins cannot be represented% For e*ample$ i ! represents a clock(ise rotation o #CK about the xa*is$ then !8 is not a ),CK clock(ise rotation about the *-a*is as e*pectedO it is a ')CK counterclock(ise rotation% 8 course$ rotatin! ),CK in one direction produces the same end result as rotatin! ')CK in the opposite direction$ and this is the point6 1 aternions only really capt re the en! res lt.
Chapter 8 2otes
')8
In Conse/uence
I urther operations on this /uaternion (ere per ormed$ thin!s (ill not beha&e as e*pected% For e*ample$ =!8>'S) is not !,$ as (e (ould intuiti&ely e*pect% In !eneral$ many o the al!ebraic identities concernin! e*ponentiation o scalars$ such as =as>t T ast$ do not apply to /uaternions% In some situations$ (e do care about the total amount o rotation$ not "ust the end result% The most important e*ample is that o an!ular &elocity% Auaternions are not the correct tool or this "obO use the e*ponential map =or its cousin$ the a*is-an!le ormat> instead%
Chapter 8 2otes
')B
Implementation 2otes
@eres (hy !t interpolates rom the identity /uaternion to ! as t &aries rom C to '%
The lo! operation essentially con&erts the /uaternion to e*ponential map ormat% =+*cept or a actor o )%> Then$ (hen (e per orm the scalar multiplication by the e*ponent t$ the e ect is to multiply the an!le by t% Finally$ the e*p undoes (hat the lo! operation did$ recalculatin! the ne( w and v rom the e*ponential &ector%
Direct implementation o the ormula !t T e*p =t lo! !> as an al!orithm or computin! !t can !i&e rise to code that is more complicated than necessary% Instead o (orkin! (ith a sin!le e*ponential-map-like /uantity like the ormula tells us to$ (e (ill break out the a*is and hal -an!le separately%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& '#C
Chapter 8 2otes
'#'
Chapter 8 2otes
'##
Chapter 8 2otes
'#,
Auaternion Interpolation
The raison !5etre o /uaternions in !ames and !raphics today is an operation kno(n as slerp$ (hich stands or spherical linear interpolation% Slerp allo(s us to smoothly interpolate bet(een t(o orientations (hile a&oidin! all the problems that pla!ued interpolation o +uler an!les% Slerp is a ternary operator$ meanin! it accepts three operands$ ) /uaternions and a scalar%
Chapter 8 2otes
'#.
Chapter 8 2otes
'#0
Chapter 8 2otes
',C
Chapter 8 2otes
','
Sol&in! or )'
;pplyin! some tri! to the ri!ht trian!le (ith hypotenuse )' v' =recallin! that v' is a unit &ector>$ (e see that6
Chapter 8 2otes
',)
Continuin!
Similarly$ ;nd there ore$
Chapter 8 2otes
',#
Computin! ]
We need a (ay to compute ]$ the an!le bet(een the t(o /uaternions% ;s it turns out$ the analo!y rom )D &ector math can be carried into /uaternion spaceO the /uaternion dot product is cos ]%
Chapter 8 2otes
',,
Complication '
There are t(o sli!ht complications% First$ the t(o /uaternions ! and G! represent the same orientation$ but may produce di erent results (hen used as an ar!ument to slerp% This problem doesnEt happen in )D or #D because the sur ace o a ,D hypersphere has a di erent topolo!y than +uclidian space% The solution is to choose the si!ns o !C and !' such that the dot product !C^!'is nonne!ati&e% This has the e ect o al(ays selectin! the shortest rotational arc rom !C to !' %
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& ',.
Complication )
The second consideration is that i !C and !' are &ery close$ then ] is &ery small$ and thus sin ] is also &ery small$ (hich (ill cause problems (ith the di&ision%
To a&oid this$ i sin ] is &ery small$ then use simple linear interpolation instead% 2e*t6 some C codeH
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& ',0
Chapter 8 2otes
',1
Chapter 8 2otes
',8
;d&anta!es o Auaternions
$mooth interpolation% The interpolation pro&ided by slerp pro&ides smooth interpolation bet(een orientations% 2o other representation method pro&ides or smooth interpolation% Fast concatenation and inversion of angular displacements. We can concatenate a se/uence o an!ular displacements into a sin!le an!ular displacement usin! the /uaternion cross product% The same operation usin! matrices in&ol&es more scalar operations$ thou!h (hich one is actually aster on a !i&en architectures is not so clean-cut6 SI3D &ector operations can make &ery /uick (ork o matri* multiplication% Auaternion con"u!ate pro&ides a (ay to compute the opposite an!ular displacement &ery e iciently% This can be done by transposin! a rotation matri*$ but is not easy (ith +uler an!les% Fast conversion to and from matrix form % ;s (e (ill see later$ /uaternions can be con&erted to and rom matri* orm a bit aster than +uler an!les% %nly four numbers% Since a /uaternion contains our scalar &alues$ it is considerably more economical than a matri*$ (hich uses nine numbers% =@o(e&er$ it still is ##_ lar!er than +uler an!les%>
Chapter 8 2otes
',B
Disad&anta!es o Auaternions
@o(e&er$ these ad&anta!es do come at some cost% Auaternions su er rom a e( o the problems that a ect matrices$ only to a lesser de!ree6 $lightly bigger than &uler angles% That one additional number may not seem like much$ but an e*tra ##_ can make a di erence (hen lar!e amounts o an!ular displacements are needed$ or e*ample$ (hen storin! animation data% ;nd the &alues inside a /uaternion are not e&enly spaced rom G' to ' so the component &alues do not interpolate smoothly e&en i the orientation does% This makes /uaternions more di icult to pack into a i*ed point number than +uler an!les or an e*ponential map% Can become invalid% This can happen either throu!h bad input data$ or rom accumulated loatin! point round o error% =We can o course normaliFe the /uaternion to ensure that it has unit ma!nitude%> ifficult for humans to 'ork 'ith% 8 the three representation methods$ /uaternions are the most di icult or humans to (ork (ith directly%
Chapter 8 2otes
'.C
Section 8%06
Comparison o 3ethods
Chapter 8 2otes
'.'
Chapter 8 2otes
'.)
Comparison o 3ethods )
In&ersion o rotations Matrix6 +asy and ast$ usin! matri* transpose &uler Angles6 2ot easy% &xponential Map6 +asy and ast$ usin! &ector ne!ation "uaternion6 +asy and ast$ usin! /uaternion con"u!ate Interpolation Matrix6 +*tremely problematic &uler Angles6 Possible$ but 4imbal lock causes /uirkiness &xponential Map6 Possible$ (ith some sin!ularities$ but not as troublesome as +uler an!les% "uaternion6 Slerp pro&ides smooth interpolation
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& '.#
Comparison o 3ethods #
Direct human interpretation Matrix6 Di icult &uler Angles6 +asiest &xponential Map6 Jery di icult "uaternion6 Jery di icult Storin! in a memory or in a ile Matrix6 2ine numbers &uler Angles6 Three numbers that can be easily /uantiFed &xponential Map6 Three numbers that can be easily /uantiFed "uaternion6 , numbers that dont /uantiFe (ellO can be reduced to # by assumin! unit len!th and that ,th component is nonne!ati&e%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& '.,
Comparison o 3ethods ,
Ini/ue representation or a !i&en rotation Matrix6 Yes &uler Angles6 2o$ due to aliasin! &xponential Map6 2o$ due to aliasin!O less complicated than +uler an!les% "uaternion6 +*actly t(o distinct representations or any an!ular displacement$ and they are ne!ati&es o each other Possible to become in&alid Matrix6 Si* de!rees o redundancy inherent in ortho!onal matri*% 3atri* creep can occur% &uler Angles6 ;ny three numbers can be interpreted unambi!uously &xponential Map6 ;ny three numbers can be interpreted unambi!uously "uaternion6 +rror creep can occur
Chapter 8 2otes
'..
Chapter 8 2otes
'.0
Chapter 8 2otes
'.8
Chapter 8 2otes
'.B
Chapter 8 2otes
'0C
Section 8%16
Chapter 8 2otes
'0'
Con&ersion ;l!orithms
'% +uler an!les to rotation matri*% )% Rotation matri* to +uler an!les% #% Auaternion to matri*% ,% 3atri* to /uaternion% .% +uler an!les to /uaternion% 0% Auaternion to +uler an!les%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& '0)
Chapter 8 2otes
'0.
Chapter 8 2otes
'00
T
'01
Chapter 8 2otes
'08
Chapter 8 2otes
'10
Chapter 8 2otes
'11
Chapter 8 2otes
'18
See i (e can rearran!e it so that the parts o a /uaternion leap out at us%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& '1B
Auaternion to 3atri* )
Were tryin! to manipulate the matri* so that the ollo(in! &alues pop out at us6 w T cos= 3)> x T nx sin= 3)> y T ny sin= 3)> $ T ny sin= 3)> there are really only t(o ma"or cases to handle6 the dia!onal elements and the o -dia!onal elements%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& '8C
Auaternion to 3atri* #
DetEs start (ith the dia!onal elements o the matri*% WeEll (ork throu!h m'' hereO m)) and m## can be sol&ed similarly%
Chapter 8 2otes
'8'
Auaternion to 3atri* ,
Chapter 8 2otes
'8)
Auaternion to 3atri* .
2o( (e need to replace the cos term (ith somethin! that contains cos S) or sin S)$ since the components o a /uaternion contain those terms% Det [ T S)% WeEll (rite one o the double-an!le ormulas or cosine rom Section '%,%, in terms o [$ and then substitute in %
Chapter 8 2otes
'8#
Auaternion to 3atri* 0
Substitutin! or cos $ (e ha&e
Chapter 8 2otes
'8,
Auaternion to 3atri* 1
Since n is a unit &ector$ nx) N ny) N n$) T '$ and there ore ' G nx) T ny) N n$) $ so6
Auaternion to 3atri* 8
2o( letEs look at the non-dia!onal elements o the matri*O they are easier than the dia!onal elements% WeEll use m') as an e*ample%
WeEll need the re&erse o the double-an!le ormula or sine% sin )[ T ) sin [ cos [ sin T ) sin = S)> cos = S)>
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& '80
Auaternion to 3atri* B
8ther &ariations can be ound in other sources% For e*ample m'' T G' N )w) N )$) also (orks$ since w) N x) N y) N $) T '%
Chapter 8 2otes #D 3ath Primer or 4raphics 5 4ame De& '88
Chapter 8 2otes
'8B
3atri* to Auaternion )
+*aminin! the sum o the dia!onal elements =kno(n as the trace o the matri*> (e !et6
Chapter 8 2otes
'BC
3atri* to Auaternion #
There ore$ and similarly$
Chapter 8 2otes
'B'
3atri* to Auaternion ,
In ortunately$ (e cannot use this trick or all our components$ since the s/uare root (ill al(ays yield positi&e results% =3ore accurately$ (e ha&e no basis or choosin! the positi&e or ne!ati&e root%> @o(e&er$ since ! and G! represent the same orientation$ (e can arbitrarily choose to use the nonne!ati&e root or one o the our components and still al(ays return a correct /uaternion% We "ust canEt use the abo&e techni/ue or all our &alues o the /uaternion% ;nother trick is to e*amine the sum and di erence o dia!onally opposite matri* elements%
Chapter 8 2otes
'B)
3atri* to Auaternion .
Chapter 8 2otes
'B#
3atri* to Auaternion 0
;rmed (ith these ormulas$ (e use a t(o-step strate!y%
'% Sol&e or one o the components o the trace% )% Plu! that &alue into one o the e/uations rom the pre&ious slide to sol&e or the other three%
This strate!y boils do(n to selectin! a ro( rom the table on the ne*t slide$ then sol&in! the e/uations in that ro( rom le t to ri!ht%
Chapter 8 2otes
'B,
3atri* to Auaternion 1
Chapter 8 2otes
'B.
3atri* to Auaternion 8
The only /uestions is$ (hich ro( should (e use: Which component should (e sol&e or irst: The simplest strate!y (ould be to "ust pick one arbitrarily and al(ays use the same procedure$ but this is rau!ht (ith problems%
DetEs say (e choose to al(ays use the top ro($ meanin! (e sol&e or w rom the trace$ and then or x$ y$ and $ (ith the e/uations on the ri!ht side o the arro(% <ut i w T C$ the di&isions to ollo( (ill be unde ined% +&en i w ` C$ a small w (ill produce numeric instability%
Shoemake su!!ests the strate!y o irst determinin! (hich o w$ x$ y$ and $ has the lar!est absolute &alue$ computin! that component usin! the dia!onal o the matri*$ and then usin! it to compute the other three accordin! to the table on the pre&ious slide%
Chapter 8 2otes
'B0
Chapter 8 2otes
'B1
Chapter 8 2otes
'B8
Chapter 8 2otes
'BB
Chapter 8 2otes
)CC
Chapter 8 2otes
)C'
Chapter 8 2otes
)C#
Chapter 8 2otes
)C,
Chapter 8 2otes
)C.
Chapter 8 2otes
)C0
Chapter 8 2otes
)C1
Chapter 8 2otes
)C8
Chapter 8 2otes
)CB
Chapter 8 2otes
)'C
4eometric Primiti&es
Chapter 8 2otes
)''