| <head> |
| <title>quaternion(3) - Plan 9 from User Space</title> |
| <meta content="text/html; charset=utf-8" http-equiv=Content-Type> |
| </head> |
| <body bgcolor=#ffffff> |
| <table border=0 cellpadding=0 cellspacing=0 width=100%> |
| <tr height=10><td> |
| <tr><td width=20><td> |
| <tr><td width=20><td><b>QUATERNION(3)</b><td align=right><b>QUATERNION(3)</b> |
| <tr><td width=20><td colspan=2> |
| <br> |
| <p><font size=+1><b>NAME </b></font><br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| qtom, mtoq, qadd, qsub, qneg, qmul, qdiv, qunit, qinv, qlen, slerp, |
| qmid, qsqrt – Quaternion arithmetic<br> |
| |
| </table> |
| <p><font size=+1><b>SYNOPSIS </b></font><br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| <tt><font size=+1>#include <draw.h> |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>#include <geometry.h> |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>Quaternion qadd(Quaternion q, Quaternion r) |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>Quaternion qsub(Quaternion q, Quaternion r) |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>Quaternion qneg(Quaternion q) |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>Quaternion qmul(Quaternion q, Quaternion r) |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>Quaternion qdiv(Quaternion q, Quaternion r) |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>Quaternion qinv(Quaternion q) |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>double qlen(Quaternion p) |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>Quaternion qunit(Quaternion q) |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>void qtom(Matrix m, Quaternion q) |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>Quaternion mtoq(Matrix mat) |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>Quaternion slerp(Quaternion q, Quaternion r, double a) |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>Quaternion qmid(Quaternion q, Quaternion r) |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>Quaternion qsqrt(Quaternion q)<br> |
| </font></tt> |
| </table> |
| <p><font size=+1><b>DESCRIPTION </b></font><br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| The Quaternions are a non-commutative extension field of the Real |
| numbers, designed to do for rotations in 3-space what the complex |
| numbers do for rotations in 2-space. Quaternions have a real component |
| <i>r</i> and an imaginary vector component <i>v</i>=(<i>i</i>,<i>j</i>,<i>k</i>). Quaternions add |
| componentwise and multiply according to |
| the rule (<i>r</i>,<i>v</i>)(<i>s</i>,<i>w</i>)=(<i>rs</i>-<i>v</i>.<i>w</i>, <i>rw</i>+<i>vs</i>+<i>v</i>x<i>w</i>), where . and x are the ordinary |
| vector dot and cross products. The multiplicative inverse of a |
| non-zero quaternion (<i>r</i>,<i>v</i>) is (<i>r</i>,<i>-v</i>)/(<i>r</i>2-<i>v</i>.<i>v</i>). |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| |
| The following routines do arithmetic on quaternions, represented |
| as<br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| <tt><font size=+1>typedef struct Quaternion Quaternion;<br> |
| struct Quaternion{<br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| double r, i, j, k;<br> |
| |
| </table> |
| };<br> |
| </font></tt> |
| </table> |
| Name Description<br> |
| <tt><font size=+1>qadd</font></tt> Add two quaternions.<br> |
| <tt><font size=+1>qsub</font></tt> Subtract two quaternions.<br> |
| <tt><font size=+1>qneg</font></tt> Negate a quaternion.<br> |
| <tt><font size=+1>qmul</font></tt> Multiply two quaternions.<br> |
| <tt><font size=+1>qdiv</font></tt> Divide two quaternions.<br> |
| <tt><font size=+1>qinv</font></tt> Return the multiplicative inverse of a quaternion.<br> |
| <tt><font size=+1>qlen</font></tt> Return <tt><font size=+1>sqrt(q.r*q.r+q.i*q.i+q.j*q.j+q.k*q.k)</font></tt>, the length of |
| a quaternion.<br> |
| <tt><font size=+1>qunit</font></tt> Return a unit quaternion (<i>length=1</i>) with components proportional |
| to <i>q</i>’s. |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| |
| A rotation by angle <i>θ</i> about axis <i>A</i> (where <i>A</i> is a unit vector) |
| can be represented by the unit quaternion <i>q</i>=(cos <i>θ</i>/2, <i>A</i>sin <i>θ</i>/2). |
| The same rotation is represented by -<i>q</i>; a rotation by -<i>θ</i> about -<i>A</i> |
| is the same as a rotation by <i>θ</i> about <i>A</i>. The quaternion <i>q</i> transforms |
| points by (0,<i>x’,y’,z’</i>) = <i>q</i>-1(0,<i>x,y,z</i>)<i>q</i>. Quaternion |
| multiplication composes rotations. The orientation of an object |
| in 3-space can be represented by a quaternion giving its rotation |
| relative to some ‘standard’ orientation. |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| |
| The following routines operate on rotations or orientations represented |
| as unit quaternions:<br> |
| <tt><font size=+1>mtoq</font></tt> Convert a rotation matrix (see <a href="../man3/matrix.html"><i>matrix</i>(3)</a>) to a unit quaternion.<br> |
| <tt><font size=+1>qtom</font></tt> Convert a unit quaternion to a rotation matrix.<br> |
| <tt><font size=+1>slerp</font></tt> Spherical lerp. Interpolate between two orientations. The |
| rotation that carries <i>q</i> to <i>r</i> is <i>q</i>-1<i>r</i>, so <tt><font size=+1>slerp(q, r, t)</font></tt> is <i>q</i>(<i>q</i>-1<i>r</i>)<i>t</i>.<br> |
| <tt><font size=+1>qmid slerp(q, r, .5)<br> |
| qsqrt</font></tt> The square root of <i>q</i>. This is just a rotation about the same |
| axis by half the angle.<br> |
| |
| </table> |
| <p><font size=+1><b>SOURCE </b></font><br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| <tt><font size=+1>/usr/local/plan9/src/libgeometry/quaternion.c<br> |
| </font></tt> |
| </table> |
| <p><font size=+1><b>SEE ALSO </b></font><br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| <a href="../man3/matrix.html"><i>matrix</i>(3)</a>, <a href="../man3/qball.html"><i>qball</i>(3)</a><br> |
| |
| </table> |
| |
| <td width=20> |
| <tr height=20><td> |
| </table> |
| <!-- TRAILER --> |
| <table border=0 cellpadding=0 cellspacing=0 width=100%> |
| <tr height=15><td width=10><td><td width=10> |
| <tr><td><td> |
| <center> |
| <a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a> |
| </center> |
| </table> |
| <!-- TRAILER --> |
| </body></html> |