initial
This commit is contained in:
228
vnproglib/cpp/help/math_2main_8cpp-example.html
Normal file
228
vnproglib/cpp/help/math_2main_8cpp-example.html
Normal file
@ -0,0 +1,228 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://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.10"/>
|
||||
<title>VectorNav C++ Library: math/main.cpp</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="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/javascript">
|
||||
$(document).ready(function() { init_search(); });
|
||||
</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="projectlogo"><img alt="Logo" src="proglib.png"/></td>
|
||||
<td id="projectalign" style="padding-left: 0.5em;">
|
||||
<div id="projectname">VectorNav C++ Library
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.8.10 -->
|
||||
<script type="text/javascript">
|
||||
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
</script>
|
||||
<div id="navrow1" class="tabs">
|
||||
<ul class="tablist">
|
||||
<li><a href="index.html"><span>Main Page</span></a></li>
|
||||
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Classes</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
<li><a href="examples.html"><span>Examples</span></a></li>
|
||||
<li>
|
||||
<div id="MSearchBox" class="MSearchBoxInactive">
|
||||
<span class="left">
|
||||
<img id="MSearchSelect" src="search/mag_sel.png"
|
||||
onmouseover="return searchBox.OnSearchSelectShow()"
|
||||
onmouseout="return searchBox.OnSearchSelectHide()"
|
||||
alt=""/>
|
||||
<input type="text" id="MSearchField" value="Search" accesskey="S"
|
||||
onfocus="searchBox.OnSearchFieldFocus(true)"
|
||||
onblur="searchBox.OnSearchFieldFocus(false)"
|
||||
onkeyup="searchBox.OnSearchFieldChange(event)"/>
|
||||
</span><span class="right">
|
||||
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
|
||||
</span>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div><!-- top -->
|
||||
<!-- 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="headertitle">
|
||||
<div class="title">math/main.cpp</div> </div>
|
||||
</div><!--header-->
|
||||
<div class="contents">
|
||||
<p>This example shows the basic math features available with the VectorNav library.</p>
|
||||
<h1><a class="anchor" id="vsCppMath"></a>
|
||||
Visual Studio (Windows)</h1>
|
||||
<ol type="1">
|
||||
<li>Open the solution file for your specific Visual Studio version located at <code><root>/cpp/examples/math/projects/vs20XX/math.sln</code>.</li>
|
||||
<li>Build the entire solution by going to the menu <code>BUILD -> Build Solution</code>.</li>
|
||||
<li>Right-click the project <code>math</code> and select <code>Debug -> Start new instance</code>.</li>
|
||||
</ol>
|
||||
<h1><a class="anchor" id="makeCppMath"></a>
|
||||
Make (Linux/Mac OS X)</h1>
|
||||
<ol type="1">
|
||||
<li>Open a terminal and change to the directory <code><root>/cpp/examples/math</code> .</li>
|
||||
<li>To build the example, run the command <code>make</code> .</li>
|
||||
<li>Run the example by executing the command <code>./math</code> .</li>
|
||||
</ol>
|
||||
<h1><a class="anchor" id="ClionCppMath"></a>
|
||||
CLion (Windows/Linux/Mac OS X)</h1>
|
||||
<ol type="1">
|
||||
<li>Open the project file located at <code><root>/cpp/examples/math</code> in CLion.</li>
|
||||
<li>Make sure the <code>math</code> configuration is active. You can set this by clicking the small drop-down list in the upper-right corner and selecting the option <code>math</code>.</li>
|
||||
<li>Build the solution by going to the menu <code>Run -> Build</code>.</li>
|
||||
<li>Run the example by going to the menu <code>Run -> Run 'math'</code>.</li>
|
||||
</ol>
|
||||
<h1><a class="anchor" id="otherCppMath"></a>
|
||||
Other</h1>
|
||||
<p>To compile and run for an environment not listed here, you will need to add all of the <code>*.c</code> files in the directory <code><root>/c/src</code> along with the file located at <code><root>/cpp/examples/math/main.cpp</code> to your project for compilation. You will also need to add <code><root>/cpp/include</code> to your include directories.</p>
|
||||
<div class="fragment"><div class="line"><span class="preprocessor">#include <iostream></span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"><span class="preprocessor">#include "<a class="code" href="vector_8h.html">vn/vector.h</a>"</span></div>
|
||||
<div class="line"><span class="preprocessor">#include "<a class="code" href="matrix_8h.html">vn/matrix.h</a>"</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"><span class="keyword">using namespace </span>std;</div>
|
||||
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacevn_1_1math.html">vn::math</a>;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div>
|
||||
<div class="line">{</div>
|
||||
<div class="line"> <span class="comment">// The VectorNav Programming Library provides structures for representing vectors and matrices.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// Common vectors you will normally encounter are conveniently named. Below we create some simple vector objects.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <a name="_a0"></a><a class="code" href="structvn_1_1math_1_1vec.html">vec3f</a> v1(1.0f, 2.0f, 3.0f); <span class="comment">// An initialized 3 component vector of floats.</span></div>
|
||||
<div class="line"> <a name="_a1"></a><a class="code" href="structvn_1_1math_1_1vec.html">vec3d</a> v2(4.0, 5.0, 6.0); <span class="comment">// An initialized 3 component vector of doubles.</span></div>
|
||||
<div class="line"> <a class="code" href="structvn_1_1math_1_1vec.html">vec4f</a> v3(1.0f, 2.0f, 3.0f, 4.0f); <span class="comment">// An initialized 4 component vector of floats.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// Convenience methods are provided to display vector values.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="keywordtype">string</span> v1Str = str(v1);</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"v1: "</span> << v1Str << endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// Or you can just write directly to cout.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> cout << <span class="stringliteral">"v2: "</span> << v2 << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"v3: "</span> << v3 << endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// Common vector values are readily available.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> cout << <span class="stringliteral">"zero vector: "</span> << vec3f::zero() << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"x-direction vector: "</span> << vec3f::unitX() << endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// A variety of vector operations are available.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <a class="code" href="structvn_1_1math_1_1vec.html">vec3f</a> va(1, 2, 3);</div>
|
||||
<div class="line"> <a class="code" href="structvn_1_1math_1_1vec.html">vec3f</a> vb(4, 5, 6);</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> std::cout << <span class="stringliteral">"va: "</span> << va << std::endl;</div>
|
||||
<div class="line"> std::cout << <span class="stringliteral">"vb: "</span> << vb << std::endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> cout << <span class="stringliteral">"va + vb = "</span> << va + vb << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"va - vb = "</span> << va - vb << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"2 * va = "</span> << 2.f * va << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"va / 3 = "</span> << va / 3.f << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"-va = "</span> << -va << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"va magnitude = "</span> << va.<a name="a2"></a><a class="code" href="structvn_1_1math_1_1vec.html#a3d62ee03c5842e16a67b62e7c4c11ecc">mag</a>() << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"va normalized = "</span> << va.<a name="a3"></a><a class="code" href="structvn_1_1math_1_1vec.html#a12ee38e4566aa64fe2dca3f72ff8e9ac">norm</a>() << endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// You can also access the individual vector components in a variety of ways.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> cout << <span class="stringliteral">"va y-component: "</span> << va.y << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"va z-component: "</span> << va[2] << endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// Although you will probably use the conveniently named vectors, sometime you will need a more specialized version.</span></div>
|
||||
<div class="line"> <span class="comment">// Because the vectors are based on a template structure, you can easily create the type you need.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <a class="code" href="structvn_1_1math_1_1vec.html">vec<5, unsigned short></a> v4(7); <span class="comment">// 5 component vector of unsigned shorts, all components initialized to the value of 7.</span></div>
|
||||
<div class="line"> <a class="code" href="structvn_1_1math_1_1vec.html">vec<10, bool></a> v5(<span class="keyword">true</span>); <span class="comment">// 10 component vector of bools, all components initialized to the value of true.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> cout << <span class="stringliteral">"v4: "</span> << v4 << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"v5: "</span> << v5 << endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// You may often find yourself working with matrices so we show some examples using the provided matrix structures.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <a name="_a4"></a><a class="code" href="structvn_1_1math_1_1mat.html">mat3f</a> m1(1, 2, 3, 4, 5, 6, 7, 8, 9); <span class="comment">// 3x3 matrix of floats.</span></div>
|
||||
<div class="line"> <a class="code" href="structvn_1_1math_1_1mat.html">mat2d</a> m2(1, 2, 3, 4); <span class="comment">// 2x2 matrix of doubles.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// As with vectors, there are convenient string functions.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="keywordtype">string</span> m1Str = str(m1);</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"m1: "</span> << m1Str << endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// Again, you can just write the matrix out to cout.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> cout << <span class="stringliteral">"m2: "</span> << m2 << endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// Common matrix values are readily available.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> cout << <span class="stringliteral">"one 3x3 matrix: "</span> << mat3f::one() << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"identity 3x3 matrix: "</span> << mat3f::identity() << endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// A variety of matrix operations are available.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <a class="code" href="structvn_1_1math_1_1mat.html">mat3f</a> ma(1, 2, 3, 4, 5, 6, 7, 8, 9);</div>
|
||||
<div class="line"> <a class="code" href="structvn_1_1math_1_1mat.html">mat3f</a> mb = mat3f::one();</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> cout << <span class="stringliteral">"ma + mb = "</span> << ma + mb << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"ma - mb = "</span> << ma - mb << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"2 * ma = "</span> << 2.f * ma << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"ma / 3 = "</span> << ma / 3.f << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"-ma = "</span> << -ma << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"ma transpose = "</span> << ma.<a name="a5"></a><a class="code" href="structvn_1_1math_1_1mat.html#ad787d0b22c792da3964b34bc8b1ace60">transpose</a>() << endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// Access to the individual matrix elements is illustrated below.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> cout << <span class="stringliteral">"0,0 element of ma: "</span> << ma.e00 << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"0,1 element of ma: "</span> << ma(0,1) << endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="comment">// You can also create different sizes and underlying data types for the matrices because of templating.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <a class="code" href="structvn_1_1math_1_1mat.html">mat<2, 3, short></a> m4(7); <span class="comment">// 2x3 matrix of shorts, all elements initialized to the value of 7.</span></div>
|
||||
<div class="line"> <a class="code" href="structvn_1_1math_1_1mat.html">mat<3, 7, bool></a> m5(<span class="keyword">true</span>); <span class="comment">// 3x7 matrix of bools, all elements initialized to the value of true.</span></div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> cout << <span class="stringliteral">"m4: "</span> << m4 << endl;</div>
|
||||
<div class="line"> cout << <span class="stringliteral">"m5: "</span> << m5 << endl;</div>
|
||||
<div class="line"></div>
|
||||
<div class="line"> <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line">}</div>
|
||||
</div><!-- fragment --> </div><!-- contents -->
|
||||
<!-- start footer part -->
|
||||
<hr class="footer"/><address class="footer"><small>
|
||||
Generated on Tue Jan 3 2017 18:27:03 for VectorNav C++ Library by  <a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
||||
</a> 1.8.10
|
||||
</small></address>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user