TheAlgorithms-C/dc/d9a/group__quats.html

322 lines
28 KiB
HTML
Raw Normal View History

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.20"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C: 3D Quaternion operations</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Algorithms_in_C
&#160;<span id="projectnumber">1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.20 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('dc/d9a/group__quats.html','../../'); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#nested-classes">Data Structures</a> &#124;
<a href="#typedef-members">Typedefs</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">3D Quaternion operations<div class="ingroups"><a class="el" href="../../de/d5a/group__quaternions.html">Library for 3D Vectors &amp; Quaternions</a></div></div> </div>
</div><!--header-->
<div class="contents">
<div class="dynheader">
Collaboration diagram for 3D Quaternion operations:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../dc/d9a/group__quats.svg" width="380" height="51"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../de/d58/structquaternion__.html">quaternion_</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">a Quaternion type represented using a scalar \(w\) or \(q_0\) and a 3D vector \(\left(q_1,q_2,q_3\right)\) <a href="../../de/d58/structquaternion__.html#details">More...</a><br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d2/de8/structeuler__.html">euler_</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">3D Euler or Tait-Bryan angles (in radian) <a href="../../d2/de8/structeuler__.html#details">More...</a><br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="typedef-members"></a>
Typedefs</h2></td></tr>
<tr class="memitem:gaacd70a16b61dd47a19eb5fb729c2669b"><td class="memItemLeft" align="right" valign="top"><a id="gaacd70a16b61dd47a19eb5fb729c2669b"></a>
typedef struct <a class="el" href="../../de/d58/structquaternion__.html">quaternion_</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d9a/group__quats.html#gaacd70a16b61dd47a19eb5fb729c2669b">quaternion</a></td></tr>
<tr class="memdesc:gaacd70a16b61dd47a19eb5fb729c2669b"><td class="mdescLeft">&#160;</td><td class="mdescRight">a Quaternion type represented using a scalar \(w\) or \(q_0\) and a 3D vector \(\left(q_1,q_2,q_3\right)\) <br /></td></tr>
<tr class="separator:gaacd70a16b61dd47a19eb5fb729c2669b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga8cc5e5b7a5fa492423ecf034c8bb52bd"><td class="memItemLeft" align="right" valign="top"><a id="ga8cc5e5b7a5fa492423ecf034c8bb52bd"></a>
typedef struct <a class="el" href="../../d2/de8/structeuler__.html">euler_</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d9a/group__quats.html#ga8cc5e5b7a5fa492423ecf034c8bb52bd">euler</a></td></tr>
<tr class="memdesc:ga8cc5e5b7a5fa492423ecf034c8bb52bd"><td class="mdescLeft">&#160;</td><td class="mdescRight">3D Euler or Tait-Bryan angles (in radian) <br /></td></tr>
<tr class="separator:ga8cc5e5b7a5fa492423ecf034c8bb52bd"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga4779f448daaf806ce5e750c13b3e0965"><td class="memItemLeft" align="right" valign="top"><a class="el" href="../../dc/d9a/group__quats.html#gaacd70a16b61dd47a19eb5fb729c2669b">quaternion</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d9a/group__quats.html#ga4779f448daaf806ce5e750c13b3e0965">quat_from_euler</a> (const <a class="el" href="../../dc/d9a/group__quats.html#ga8cc5e5b7a5fa492423ecf034c8bb52bd">euler</a> *in_euler)</td></tr>
<tr class="memdesc:ga4779f448daaf806ce5e750c13b3e0965"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function to convert given Euler angles to a quaternion. <a href="../../dc/d9a/group__quats.html#ga4779f448daaf806ce5e750c13b3e0965">More...</a><br /></td></tr>
<tr class="separator:ga4779f448daaf806ce5e750c13b3e0965"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga1afd165100e9b02b86e3bd11b50f3b06"><td class="memItemLeft" align="right" valign="top"><a class="el" href="../../dc/d9a/group__quats.html#ga8cc5e5b7a5fa492423ecf034c8bb52bd">euler</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d9a/group__quats.html#ga1afd165100e9b02b86e3bd11b50f3b06">euler_from_quat</a> (const <a class="el" href="../../dc/d9a/group__quats.html#gaacd70a16b61dd47a19eb5fb729c2669b">quaternion</a> *in_quat)</td></tr>
<tr class="memdesc:ga1afd165100e9b02b86e3bd11b50f3b06"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function to convert given quaternion to Euler angles. <a href="../../dc/d9a/group__quats.html#ga1afd165100e9b02b86e3bd11b50f3b06">More...</a><br /></td></tr>
<tr class="separator:ga1afd165100e9b02b86e3bd11b50f3b06"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaf5ad0f9c4f0facc5a9c3735a178156b1"><td class="memItemLeft" align="right" valign="top"><a class="el" href="../../dc/d9a/group__quats.html#gaacd70a16b61dd47a19eb5fb729c2669b">quaternion</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d9a/group__quats.html#gaf5ad0f9c4f0facc5a9c3735a178156b1">quaternion_multiply</a> (const <a class="el" href="../../dc/d9a/group__quats.html#gaacd70a16b61dd47a19eb5fb729c2669b">quaternion</a> *in_quat1, const <a class="el" href="../../dc/d9a/group__quats.html#gaacd70a16b61dd47a19eb5fb729c2669b">quaternion</a> *in_quat2)</td></tr>
<tr class="memdesc:gaf5ad0f9c4f0facc5a9c3735a178156b1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function to multiply two quaternions. <a href="../../dc/d9a/group__quats.html#gaf5ad0f9c4f0facc5a9c3735a178156b1">More...</a><br /></td></tr>
<tr class="separator:gaf5ad0f9c4f0facc5a9c3735a178156b1"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga1afd165100e9b02b86e3bd11b50f3b06"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga1afd165100e9b02b86e3bd11b50f3b06">&#9670;&nbsp;</a></span>euler_from_quat()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="../../dc/d9a/group__quats.html#ga8cc5e5b7a5fa492423ecf034c8bb52bd">euler</a> euler_from_quat </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="../../dc/d9a/group__quats.html#gaacd70a16b61dd47a19eb5fb729c2669b">quaternion</a> *&#160;</td>
<td class="paramname"><em>in_quat</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Function to convert given quaternion to Euler angles. </p>
<p class="formulaDsp">
\begin{eqnarray*} \phi &amp; = &amp; \tan^{-1}\left[\frac{2\left(q_0q_1+q_2q_3\right)}{1-2\left(q_1^2+q_2^2\right)}\right]\\ \theta &amp; = &amp;-\sin^{-1}\left[2\left(q_0q_2-q_3q_1\right)\right]\\ \psi &amp; = &amp; \tan^{-1}\left[\frac{2\left(q_0q_3+q_1q_2\right)}{1-2\left(q_2^2+q_3^2\right)}\right]\\ \end{eqnarray*}
</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">in_quat</td><td>input quaternion instance </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>converted euler angles </dd></dl>
<div class="fragment"><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>&#160;{</div>
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>&#160; <a class="code" href="../../d2/de8/structeuler__.html">euler</a> out_euler;</div>
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span>&#160; <span class="keywordflow">if</span> (!in_quat) <span class="comment">// if null</span></div>
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>&#160; {</div>
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span>&#160; fprintf(stderr, <span class="stringliteral">&quot;%s: Invalid input.&quot;</span>, __func__);</div>
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span>&#160; <span class="keywordflow">return</span> out_euler;</div>
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span>&#160; }</div>
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>&#160; </div>
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>&#160; out_euler.<a class="code" href="../../d2/de8/structeuler__.html#a3f1b77e489be443a8d84a84082b8092e">roll</a> = atan2f(</div>
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span>&#160; 2.f * (in_quat-&gt;<a class="code" href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">w</a> * in_quat-&gt;q1 + in_quat-&gt;q2 * in_quat-&gt;q3),</div>
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span>&#160; 1.f - 2.f * (in_quat-&gt;q1 * in_quat-&gt;q1 + in_quat-&gt;q2 * in_quat-&gt;q2));</div>
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span>&#160; out_euler.<a class="code" href="../../d2/de8/structeuler__.html#aa71f9aa6dfa32d8014b2d54ab8410e0b">pitch</a> =</div>
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span>&#160; asinf(2.f * (in_quat-&gt;<a class="code" href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">w</a> * in_quat-&gt;q2 + in_quat-&gt;q1 * in_quat-&gt;q3));</div>
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span>&#160; out_euler.<a class="code" href="../../d2/de8/structeuler__.html#aad52507cc423ec49847471f6f15dd9d7">yaw</a> = atan2f(</div>
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>&#160; 2.f * (in_quat-&gt;<a class="code" href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">w</a> * in_quat-&gt;q3 + in_quat-&gt;q1 * in_quat-&gt;q2),</div>
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>&#160; 1.f - 2.f * (in_quat-&gt;q2 * in_quat-&gt;q2 + in_quat-&gt;q3 * in_quat-&gt;q3));</div>
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>&#160; </div>
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span>&#160; <span class="keywordflow">return</span> out_euler;</div>
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<a id="ga4779f448daaf806ce5e750c13b3e0965"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga4779f448daaf806ce5e750c13b3e0965">&#9670;&nbsp;</a></span>quat_from_euler()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="../../dc/d9a/group__quats.html#gaacd70a16b61dd47a19eb5fb729c2669b">quaternion</a> quat_from_euler </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="../../dc/d9a/group__quats.html#ga8cc5e5b7a5fa492423ecf034c8bb52bd">euler</a> *&#160;</td>
<td class="paramname"><em>in_euler</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Function to convert given Euler angles to a quaternion. </p>
<p class="formulaDsp">
\begin{eqnarray*} q_{0} &amp; = &amp;\cos\left(\frac{\phi}{2}\right)\cos\left(\frac{\theta}{2}\right)\cos\left(\frac{\psi}{2}\right) + \sin\left(\frac{\phi}{2}\right)\sin\left(\frac{\theta}{2}\right)\sin\left(\frac{\psi}{2}\right)\\ q_{1} &amp; = &amp;\sin\left(\frac{\phi}{2}\right)\cos\left(\frac{\theta}{2}\right)\cos\left(\frac{\psi}{2}\right) - \cos\left(\frac{\phi}{2}\right)\sin\left(\frac{\theta}{2}\right)\sin\left(\frac{\psi}{2}\right)\\ q_{2} &amp; = &amp;\cos\left(\frac{\phi}{2}\right)\sin\left(\frac{\theta}{2}\right)\cos\left(\frac{\psi}{2}\right) + \sin\left(\frac{\phi}{2}\right)\cos\left(\frac{\theta}{2}\right)\sin\left(\frac{\psi}{2}\right)\\ q_{3} &amp; = &amp;\cos\left(\frac{\phi}{2}\right)\cos\left(\frac{\theta}{2}\right)\sin\left(\frac{\psi}{2}\right) - \sin\left(\frac{\phi}{2}\right)\sin\left(\frac{\theta}{2}\right)\cos\left(\frac{\psi}{2}\right)\\ \end{eqnarray*}
</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">in_euler</td><td>input Euler angles instance </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>converted quaternion </dd></dl>
<div class="fragment"><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160;{</div>
<div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160; <a class="code" href="../../de/d58/structquaternion__.html">quaternion</a> out_quat;</div>
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160; </div>
<div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160; <span class="keywordflow">if</span> (!in_euler) <span class="comment">// if null</span></div>
<div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160; {</div>
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160; fprintf(stderr, <span class="stringliteral">&quot;%s: Invalid input.&quot;</span>, __func__);</div>
<div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160; <span class="keywordflow">return</span> out_quat;</div>
<div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160; }</div>
<div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160; </div>
<div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160; <a class="code" href="../../de/d58/structquaternion__.html">quaternion</a> temp;</div>
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span>&#160; </div>
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span>&#160; <span class="keywordtype">float</span> cy = cosf(in_euler-&gt;<a class="code" href="../../d2/de8/structeuler__.html#aad52507cc423ec49847471f6f15dd9d7">yaw</a> * 0.5f);</div>
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span>&#160; <span class="keywordtype">float</span> sy = sinf(in_euler-&gt;<a class="code" href="../../d2/de8/structeuler__.html#aad52507cc423ec49847471f6f15dd9d7">yaw</a> * 0.5f);</div>
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span>&#160; <span class="keywordtype">float</span> cp = cosf(in_euler-&gt;<a class="code" href="../../d2/de8/structeuler__.html#aa71f9aa6dfa32d8014b2d54ab8410e0b">pitch</a> * 0.5f);</div>
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160; <span class="keywordtype">float</span> sp = sinf(in_euler-&gt;<a class="code" href="../../d2/de8/structeuler__.html#aa71f9aa6dfa32d8014b2d54ab8410e0b">pitch</a> * 0.5f);</div>
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160; <span class="keywordtype">float</span> cr = cosf(in_euler-&gt;<a class="code" href="../../d2/de8/structeuler__.html#a3f1b77e489be443a8d84a84082b8092e">roll</a> * 0.5f);</div>
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160; <span class="keywordtype">float</span> sr = sinf(in_euler-&gt;<a class="code" href="../../d2/de8/structeuler__.html#a3f1b77e489be443a8d84a84082b8092e">roll</a> * 0.5f);</div>
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160; </div>
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160; temp.w = cr * cp * cy + sr * sp * sy;</div>
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160; temp.q1 = sr * cp * cy - cr * sp * sy;</div>
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160; temp.q2 = cr * sp * cy + sr * cp * sy;</div>
<div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160; temp.q3 = cr * cp * sy - sr * sp * cy;</div>
<div class="line"><a name="l00070"></a><span class="lineno"> 70</span>&#160; </div>
<div class="line"><a name="l00071"></a><span class="lineno"> 71</span>&#160; <span class="keywordflow">return</span> temp;</div>
<div class="line"><a name="l00072"></a><span class="lineno"> 72</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<a id="gaf5ad0f9c4f0facc5a9c3735a178156b1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaf5ad0f9c4f0facc5a9c3735a178156b1">&#9670;&nbsp;</a></span>quaternion_multiply()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="../../dc/d9a/group__quats.html#gaacd70a16b61dd47a19eb5fb729c2669b">quaternion</a> quaternion_multiply </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="../../dc/d9a/group__quats.html#gaacd70a16b61dd47a19eb5fb729c2669b">quaternion</a> *&#160;</td>
<td class="paramname"><em>in_quat1</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="../../dc/d9a/group__quats.html#gaacd70a16b61dd47a19eb5fb729c2669b">quaternion</a> *&#160;</td>
<td class="paramname"><em>in_quat2</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Function to multiply two quaternions. </p>
<p class="formulaDsp">
\begin{eqnarray*} \mathbf{c} &amp; = &amp; \mathbf{a}\otimes\mathbf{b}\\ &amp; = &amp; \begin{bmatrix}a_{0} &amp; a_{1} &amp; a_{2} &amp; a_{3}\end{bmatrix}\otimes\begin{bmatrix}b_{0} &amp; b_{1} &amp; b_{2} &amp; b_{3}\end{bmatrix}\\ &amp; = &amp; \begin{bmatrix} a_{0}b_{0}-a_{1}b_{1}-a_{2}b_{2}-a_{3}b_{3}\\ a_{0}b_{1}+a_{1}b_{0}+a_{2}b_{3}-a_{3}b_{2}\\ a_{0}b_{2}-a_{1}b_{3}+a_{2}b_{0}+a_{3}b_{1}\\ a_{0}b_{3}+a_{1}b_{2}-a_{2}b_{1}+a_{3}b_{0} \end{bmatrix}^{T} \end{eqnarray*}
</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">in_quat1</td><td>first input quaternion instance </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">in_quat2</td><td>second input quaternion instance </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>resultant quaternion </dd></dl>
<div class="fragment"><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>&#160;{</div>
<div class="line"><a name="l00132"></a><span class="lineno"> 132</span>&#160; <a class="code" href="../../de/d58/structquaternion__.html">quaternion</a> out_quat;</div>
<div class="line"><a name="l00133"></a><span class="lineno"> 133</span>&#160; <span class="keywordflow">if</span> (!in_quat1 || !in_quat2) <span class="comment">// if null</span></div>
<div class="line"><a name="l00134"></a><span class="lineno"> 134</span>&#160; {</div>
<div class="line"><a name="l00135"></a><span class="lineno"> 135</span>&#160; fprintf(stderr, <span class="stringliteral">&quot;%s: Invalid input.&quot;</span>, __func__);</div>
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span>&#160; <span class="keywordflow">return</span> out_quat;</div>
<div class="line"><a name="l00137"></a><span class="lineno"> 137</span>&#160; }</div>
<div class="line"><a name="l00138"></a><span class="lineno"> 138</span>&#160; </div>
<div class="line"><a name="l00139"></a><span class="lineno"> 139</span>&#160; out_quat.<a class="code" href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">w</a> = in_quat1-&gt;<a class="code" href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">w</a> * in_quat2-&gt;<a class="code" href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">w</a> - in_quat1-&gt;q1 * in_quat2-&gt;q1 -</div>
<div class="line"><a name="l00140"></a><span class="lineno"> 140</span>&#160; in_quat1-&gt;q2 * in_quat2-&gt;q2 - in_quat1-&gt;q3 * in_quat2-&gt;q3;</div>
<div class="line"><a name="l00141"></a><span class="lineno"> 141</span>&#160; out_quat.q1 = in_quat1-&gt;<a class="code" href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">w</a> * in_quat2-&gt;q1 + in_quat1-&gt;q1 * in_quat2-&gt;<a class="code" href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">w</a> +</div>
<div class="line"><a name="l00142"></a><span class="lineno"> 142</span>&#160; in_quat1-&gt;q2 * in_quat2-&gt;q3 - in_quat1-&gt;q3 * in_quat2-&gt;q2;</div>
<div class="line"><a name="l00143"></a><span class="lineno"> 143</span>&#160; out_quat.q2 = in_quat1-&gt;<a class="code" href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">w</a> * in_quat2-&gt;q2 - in_quat1-&gt;q1 * in_quat2-&gt;q3 +</div>
<div class="line"><a name="l00144"></a><span class="lineno"> 144</span>&#160; in_quat1-&gt;q2 * in_quat2-&gt;<a class="code" href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">w</a> + in_quat1-&gt;q3 * in_quat2-&gt;q1;</div>
<div class="line"><a name="l00145"></a><span class="lineno"> 145</span>&#160; out_quat.q3 = in_quat1-&gt;<a class="code" href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">w</a> * in_quat2-&gt;q3 + in_quat1-&gt;q1 * in_quat2-&gt;q2 -</div>
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>&#160; in_quat1-&gt;q2 * in_quat2-&gt;q1 + in_quat1-&gt;q3 * in_quat2-&gt;<a class="code" href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">w</a>;</div>
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>&#160; </div>
<div class="line"><a name="l00148"></a><span class="lineno"> 148</span>&#160; <span class="keywordflow">return</span> out_quat;</div>
<div class="line"><a name="l00149"></a><span class="lineno"> 149</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<div class="ttc" id="astructquaternion___html_a835e2ba72517fbb29d0d4e3cb4c2914f"><div class="ttname"><a href="../../de/d58/structquaternion__.html#a835e2ba72517fbb29d0d4e3cb4c2914f">quaternion_::w</a></div><div class="ttdeci">float w</div><div class="ttdoc">real part of quaternion</div><div class="ttdef"><b>Definition:</b> geometry_datatypes.h:64</div></div>
<div class="ttc" id="astructeuler___html_aa71f9aa6dfa32d8014b2d54ab8410e0b"><div class="ttname"><a href="../../d2/de8/structeuler__.html#aa71f9aa6dfa32d8014b2d54ab8410e0b">euler_::pitch</a></div><div class="ttdeci">float pitch</div><div class="ttdoc">or elevation = rotation about Y axis</div><div class="ttdef"><b>Definition:</b> geometry_datatypes.h:89</div></div>
<div class="ttc" id="astructeuler___html_a3f1b77e489be443a8d84a84082b8092e"><div class="ttname"><a href="../../d2/de8/structeuler__.html#a3f1b77e489be443a8d84a84082b8092e">euler_::roll</a></div><div class="ttdeci">float roll</div><div class="ttdoc">or bank = rotation about X axis</div><div class="ttdef"><b>Definition:</b> geometry_datatypes.h:84</div></div>
<div class="ttc" id="astructeuler___html"><div class="ttname"><a href="../../d2/de8/structeuler__.html">euler_</a></div><div class="ttdoc">3D Euler or Tait-Bryan angles (in radian)</div><div class="ttdef"><b>Definition:</b> geometry_datatypes.h:81</div></div>
<div class="ttc" id="astructquaternion___html"><div class="ttname"><a href="../../de/d58/structquaternion__.html">quaternion_</a></div><div class="ttdoc">a Quaternion type represented using a scalar or and a 3D vector</div><div class="ttdef"><b>Definition:</b> geometry_datatypes.h:61</div></div>
<div class="ttc" id="astructeuler___html_aad52507cc423ec49847471f6f15dd9d7"><div class="ttname"><a href="../../d2/de8/structeuler__.html#aad52507cc423ec49847471f6f15dd9d7">euler_::yaw</a></div><div class="ttdeci">float yaw</div><div class="ttdoc">or heading = rotation about Z axis</div><div class="ttdef"><b>Definition:</b> geometry_datatypes.h:94</div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by <a href="http://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.8.20 </li>
</ul>
</div>
</body>
</html>