Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Rotation matrix
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Quaternion === {{Main|Quaternions and spatial rotation}} Given the unit quaternion {{math|'''q''' {{=}} ''w'' + ''x'''''i''' + ''y'''''j''' + ''z'''''k'''}}, the equivalent pre-multiplied (to be used with column vectors) {{nowrap|3 Γ 3}} rotation matrix is <ref>{{cite conference |last1=Shoemake |first1=Ken |title=Computer Graphics: SIGGRAPH '85 Conference Proceedings |conference=SIGGRAPH '85, 22β26 July 1985, San Francisco |chapter=Animating rotation with quaternion curves |year=1985 |volume=19 |number=3 |pages=245β254 |doi=10.1145/325334.325242 |doi-access=free |url=https://archive.org/details/siggraph85confer0000sigg/page/n2/ |publisher=Association for Computing Machinery |isbn=0897911660 }}</ref> :<math> Q = \begin{bmatrix} 1 - 2 y^2 - 2 z^2 & 2 x y - 2 z w & 2 x z + 2 y w \\ 2 x y + 2 z w & 1 - 2 x^2 - 2 z^2 & 2 y z - 2 x w \\ 2 x z - 2 y w & 2 y z + 2 x w & 1 - 2 x^2 - 2 y^2 \end{bmatrix} .</math> Now every [[quaternion]] component appears multiplied by two in a term of degree two, and if all such terms are zero what is left is an identity matrix. This leads to an efficient, robust conversion from any quaternion β whether unit or non-unit β to a {{nowrap|3 Γ 3}} rotation matrix. Given: :<math>\begin{align} n &= w \times w + x \times x + y \times y + z \times z \\ s &= \begin{cases} 0 &\text{if } n = 0 \\ \frac{2}{n} &\text{otherwise} \end{cases} \\ \end{align}</math> we can calculate :<math>Q = \begin{bmatrix} 1 - s(yy + zz) & s(xy - wz) & s(xz + wy) \\ s(xy + wz) & 1 - s(xx + zz) & s(yz - wx) \\ s(xz - wy) & s(yz + wx) & 1 - s(xx + yy) \end{bmatrix}</math> Freed from the demand for a unit quaternion, we find that nonzero quaternions act as [[homogeneous coordinates]] for {{nowrap|3 Γ 3}} rotation matrices. The Cayley transform, discussed earlier, is obtained by scaling the quaternion so that its {{mvar|w}} component is 1. For a 180Β° rotation around any axis, {{mvar|w}} will be zero, which explains the Cayley limitation. The sum of the entries along the main diagonal (the [[trace (linear algebra)|trace]]), plus one, equals {{math|4 β 4(''x''<sup>2</sup> + ''y''<sup>2</sup> + ''z''<sup>2</sup>)}}, which is {{math|4''w''<sup>2</sup>}}. Thus we can write the trace itself as {{math|2''w''<sup>2</sup> + 2''w''<sup>2</sup> β 1}}; and from the previous version of the matrix we see that the diagonal entries themselves have the same form: {{math|2''x''<sup>2</sup> + 2''w''<sup>2</sup> β 1}}, {{math|2''y''<sup>2</sup> + 2''w''<sup>2</sup> β 1}}, and {{math|2''z''<sup>2</sup> + 2''w''<sup>2</sup> β 1}}. So we can easily compare the magnitudes of all four quaternion components using the matrix diagonal. We can, in fact, obtain all four magnitudes using sums and square roots, and choose consistent signs using the skew-symmetric part of the off-diagonal entries: :<math>\begin{align} t &= \operatorname{tr} Q = Q_{xx} + Q_{yy} + Q_{zz} \quad (\text{the trace of }Q) \\ r &= \sqrt{1 + t} \\ w &= \tfrac{1}{2} r \\ x &= \operatorname{sgn}\left(Q_{zy} - Q_{yz}\right)\left|\tfrac12 \sqrt{1 + Q_{xx} - Q_{yy} - Q_{zz}}\right| \\ y &= \operatorname{sgn}\left(Q_{xz} - Q_{zx}\right)\left|\tfrac12 \sqrt{1 - Q_{xx} + Q_{yy} - Q_{zz}}\right| \\ z &= \operatorname{sgn}\left(Q_{yx} - Q_{xy}\right)\left|\tfrac12 \sqrt{1 - Q_{xx} - Q_{yy} + Q_{zz}}\right| \end{align}</math> Alternatively, use a single square root and division :<math>\begin{align} t &= \operatorname{tr} Q = Q_{xx} + Q_{yy} + Q_{zz} \\ r &= \sqrt{1 + t} \\ s &= \tfrac{1}{2r} \\ w &= \tfrac{1}{2} r \\ x &= \left(Q_{zy} - Q_{yz}\right)s \\ y &= \left(Q_{xz} - Q_{zx}\right)s \\ z &= \left(Q_{yx} - Q_{xy}\right)s \end{align}</math> This is numerically stable so long as the trace, {{mvar|t}}, is not negative; otherwise, we risk dividing by (nearly) zero. In that case, suppose {{mvar|Q<sub>xx</sub>}} is the largest diagonal entry, so {{mvar|x}} will have the largest magnitude (the other cases are derived by cyclic permutation); then the following is safe. :<math>\begin{align} r &= \sqrt{1 + Q_{xx} - Q_{yy} - Q_{zz}} \\ s &= \tfrac{1}{2r} \\ w &= \left(Q_{zy} - Q_{yz}\right)s \\ x &= \tfrac12 r \\ y &= \left(Q_{xy} + Q_{yx}\right)s \\ z &= \left(Q_{zx} + Q_{xz}\right)s \end{align}</math> If the matrix contains significant error, such as accumulated numerical error, we may construct a symmetric {{nowrap|4 Γ 4}} matrix, :<math> K = \frac13 \begin{bmatrix} Q_{xx}-Q_{yy}-Q_{zz} & Q_{yx}+Q_{xy} & Q_{zx}+Q_{xz} & Q_{zy}-Q_{yz} \\ Q_{yx}+Q_{xy} & Q_{yy}-Q_{xx}-Q_{zz} & Q_{zy}+Q_{yz} & Q_{xz}-Q_{zx} \\ Q_{zx}+Q_{xz} & Q_{zy}+Q_{yz} & Q_{zz}-Q_{xx}-Q_{yy} & Q_{yx}-Q_{xy} \\ Q_{zy}-Q_{yz} & Q_{xz}-Q_{zx} & Q_{yx}-Q_{xy} & Q_{xx}+Q_{yy}+Q_{zz} \end{bmatrix} ,</math> and find the [[eigenvector]], {{math|(''x'', ''y'', ''z'', ''w'')}}, of its largest magnitude eigenvalue. (If {{mvar|Q}} is truly a rotation matrix, that value will be 1.) The quaternion so obtained will correspond to the rotation matrix closest to the given matrix {{Harv|Bar-Itzhack|2000}} (Note: formulation of the cited article is post-multiplied, works with row vectors).
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)