blob: 257ebe52f32b8a8db3288dce0b45d4b63cf083a1 [file] [log] [blame]
<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 &ndash; 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 &lt;draw.h&gt;
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>#include &lt;geometry.h&gt;
<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&nbsp;&nbsp;&nbsp;&nbsp;Description<br>
<tt><font size=+1>qadd</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Add two quaternions.<br>
<tt><font size=+1>qsub</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Subtract two quaternions.<br>
<tt><font size=+1>qneg</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Negate a quaternion.<br>
<tt><font size=+1>qmul</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Multiply two quaternions.<br>
<tt><font size=+1>qdiv</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Divide two quaternions.<br>
<tt><font size=+1>qinv</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;Return the multiplicative inverse of a quaternion.<br>
<tt><font size=+1>qlen</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;Return a unit quaternion (<i>length=1</i>) with components proportional
to <i>q</i>&#8217;s.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
A rotation by angle <i>&#952;</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>&#952;</i>/2, <i>A</i>sin <i>&#952;</i>/2).
The same rotation is represented by -<i>q</i>; a rotation by -<i>&#952;</i> about -<i>A</i>
is the same as a rotation by <i>&#952;</i> about <i>A</i>. The quaternion <i>q</i> transforms
points by (0,<i>x&#8217;,y&#8217;,z&#8217;</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 &#8216;standard&#8217; 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>&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;Convert a unit quaternion to a rotation matrix.<br>
<tt><font size=+1>slerp</font></tt>&nbsp;&nbsp;&nbsp;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&nbsp;&nbsp;&nbsp;&nbsp;slerp(q, r, .5)<br>
qsqrt</font></tt>&nbsp;&nbsp;&nbsp;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>