http://openluna.org/wiki/index.php?title=Quaternion_math&feed=atom&action=historyQuaternion math - Revision history2022-11-30T20:58:06ZRevision history for this page on the wikiMediaWiki 1.20.3http://openluna.org/wiki/index.php?title=Quaternion_math&diff=462&oldid=prevSnyder at 18:12, 2 May 20092009-05-02T18:12:49Z<p></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 18:12, 2 May 2009</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 52:</td>
<td colspan="2" class="diff-lineno">Line 52:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>   Cos(t/2) + sin(t/2)Wxi/t + sin(t/2)Wyi/t + sin(t/s)Wzk/t  where t = the magnitude of Wx,W,Wz   </div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>   Cos(t/2) + sin(t/2)Wxi/t + sin(t/2)Wyi/t + sin(t/s)Wzk/t  where t = the magnitude of Wx,W,Wz   </div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>[[Float Quaternion <del class="diffchange diffchange-inline">Propigate</del>]]</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>[[Float Quaternion <ins class="diffchange diffchange-inline">Propagate]]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">As an addendum, sometimes the vectors in this math need to be crossed. Since we can represent them as a not necissarily normalized quaternion with a scalar part of zero, we might as well include the code</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">[[Float Quaternoinish Cross</ins>]]  </div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>This is all great except for one or two problems.  </div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>This is all great except for one or two problems.  </div></td></tr>
</table>Snyderhttp://openluna.org/wiki/index.php?title=Quaternion_math&diff=455&oldid=prevSnyder: New page: Okay here is some simple routines for doing the Quaternion Math First the representation of a vector can be written as: Vector = Bi + Cj + Dk where i,j,k are mutually perpendicular i...2009-04-29T20:25:42Z<p>New page: Okay here is some simple routines for doing the Quaternion Math First the representation of a vector can be written as: Vector = Bi + Cj + Dk where i,j,k are mutually perpendicular i...</p>
<p><b>New page</b></p><div>Okay here is some simple routines for doing the Quaternion Math<br />
<br />
First the representation of a vector can be written as:<br />
<br />
Vector = Bi + Cj + Dk <br />
<br />
where i,j,k are mutually perpendicular imaginary numbers (right hand rule).<br />
<br />
note: i*i = -1 (the usual imaginary number def) where i*j = k and j * i = -k etc.<br />
<br />
A quaternion is a vector with an associated scalar so that <br />
<br />
Quaternion = A + Bi + Cj + Dk<br />
<br />
with the added twist that the length of the vector + scalar == 1<br />
<br />
sqrt(A*A + B*B + C*C + D*D) = length = 1.0 <br />
<br />
for software in the C programming language we can easily define a quaternian as a 4 element vector<br />
<br />
float q[4]; <br />
<br />
with values of v[0],..., v[3] corresponding to A,...,D<br />
<br />
to multiply two quaternions we just multiply like any other equation.<br />
<br />
(A+Bi+Cj+Dk)*(E+Fi+Gj+Hk) = AE + EFi + AGj + AHk + BiE + BiFi + BiGj + ...<br />
<br />
where we can simplify terms like +BiGj into +BGk etc.<br />
<br />
[[Float Quaternion Multiply]]<br />
<br />
Due to rounding errors, sometimes quaternions need to be 'trimmed' to make sure they are still of unit length.<br />
<br />
[[Float Quaternion Normalise]]<br />
<br />
Then there is the complex conjugate. like in imaginary math, reverse the signs of the complex parts.<br />
<br />
[[Float Quaternion Conj]]<br />
<br />
Now, to transform a vector, V, (say a fix on a star) in the vehicles body frame, to the equivalent vector in the<br />
reference frame, with the rotation between the two defined by the quaternion Q we simple do the math<br />
<br />
Vref = Q Vbody Conj(Q)<br />
<br />
remembering that the Vector is represented with a zero scalar part and can be any length.<br />
<br />
[[Float quaternion Transform]] <br />
<br />
finally we want to take some (small) rotations, as measured in our vehicles body frame, and update the quaternion to reflect these motions. First we need to make these rotations into a quaternion, then fold them into (multiply) the existing quaternian. If the angles (in radians) are small, the vector portion will be the normalized vector of the component rotations. The scalar portion is the Cosine of 1/2 the resultant rotation about the quaternion. to keep the total magnitude at one, each vector component is multiplied by the Sine. This looks like:<br />
<br />
Cos(t/2) + sin(t/2)Wxi/t + sin(t/2)Wyi/t + sin(t/s)Wzk/t where t = the magnitude of Wx,W,Wz <br />
<br />
[[Float Quaternion Propigate]]<br />
<br />
This is all great except for one or two problems. <br />
This is all done in floating point math. Micro-controllers are better at MIPS than FLOPS. <br />
So the software needs to be converted to fixed point Math and the Sin and Cos (and sqrt) functions need <br />
to be converted into fixed point approximations for speed. (there is a few other ways to speed up part of <br />
the math in there also :)<br />
<br />
I suppose here is where the discussion showing that all the quaternion components are less than one so<br />
we will represent them as binary fractions. (bit16,bit15,bit14,bit13... = 1,1/2,1/4,1/8 ...etc)<br />
<br />
[[Fixed Point Quaternion routines]]<br />
<br />
back to [[Inertial Navigation]]</div>Snyder