mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-21 04:18:34 +08:00
359 lines
29 KiB
HTML
359 lines
29 KiB
HTML
<!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=11"/>
|
|
<meta name="generator" content="Doxygen 1.9.3"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>Algorithms_in_C++: math/vector_cross_product.cpp File Reference</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 id="projectrow">
|
|
<td id="projectalign">
|
|
<div id="projectname">Algorithms_in_C++<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.9.3 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
|
|
/* @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:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(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:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(document).ready(function(){initNavTree('df/d66/vector__cross__product_8cpp.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="#namespaces">Namespaces</a> |
|
|
<a href="#func-members">Functions</a> </div>
|
|
<div class="headertitle"><div class="title">vector_cross_product.cpp File Reference</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p>Calculates the <a href="https://en.wikipedia.org/wiki/Cross_product" target="_blank">Cross Product</a> and the magnitude of two mathematical 3D vectors.
|
|
<a href="#details">More...</a></p>
|
|
<div class="textblock"><code>#include <iostream></code><br />
|
|
<code>#include <array></code><br />
|
|
<code>#include <cmath></code><br />
|
|
<code>#include <cassert></code><br />
|
|
</div><div class="textblock"><div class="dynheader">
|
|
Include dependency graph for vector_cross_product.cpp:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../db/dc3/vector__cross__product_8cpp__incl.svg" width="331" height="112"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
</div><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="namespaces" name="namespaces"></a>
|
|
Namespaces</h2></td></tr>
|
|
<tr class="memitem:dd/d47/namespacemath"><td class="memItemLeft" align="right" valign="top">namespace  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d47/namespacemath.html">math</a></td></tr>
|
|
<tr class="memdesc:dd/d47/namespacemath"><td class="mdescLeft"> </td><td class="mdescRight">for <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/random/rand.html">std::rand</a> <br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:d4/d91/namespacevector__cross"><td class="memItemLeft" align="right" valign="top">namespace  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d91/namespacevector__cross.html">vector_cross</a></td></tr>
|
|
<tr class="memdesc:d4/d91/namespacevector__cross"><td class="mdescLeft"> </td><td class="mdescRight">Functions for Vector Cross Product algorithms. <br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
|
|
Functions</h2></td></tr>
|
|
<tr class="memitem:a225732399c5c076976eae5b180a9f8c9"><td class="memItemLeft" align="right" valign="top"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a>< double, 3 > </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d66/vector__cross__product_8cpp.html#a225732399c5c076976eae5b180a9f8c9">math::vector_cross::cross</a> (const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a>< double, 3 > &A, const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a>< double, 3 > &B)</td></tr>
|
|
<tr class="memdesc:a225732399c5c076976eae5b180a9f8c9"><td class="mdescLeft"> </td><td class="mdescRight">Function to calculate the cross product of the passed arrays containing the direction ratios of the two mathematical vectors. <a href="../../df/d66/vector__cross__product_8cpp.html#a225732399c5c076976eae5b180a9f8c9">More...</a><br /></td></tr>
|
|
<tr class="separator:a225732399c5c076976eae5b180a9f8c9"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a4b2a9757a87c18e1642d72410ecfaba8"><td class="memItemLeft" align="right" valign="top">double </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d66/vector__cross__product_8cpp.html#a4b2a9757a87c18e1642d72410ecfaba8">math::vector_cross::mag</a> (const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a>< double, 3 > &vec)</td></tr>
|
|
<tr class="memdesc:a4b2a9757a87c18e1642d72410ecfaba8"><td class="mdescLeft"> </td><td class="mdescRight">Calculates the magnitude of the mathematical vector from it's direction ratios. <a href="../../df/d66/vector__cross__product_8cpp.html#a4b2a9757a87c18e1642d72410ecfaba8">More...</a><br /></td></tr>
|
|
<tr class="separator:a4b2a9757a87c18e1642d72410ecfaba8"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d66/vector__cross__product_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
|
|
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft"> </td><td class="mdescRight">namespace math <a href="../../df/d66/vector__cross__product_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">More...</a><br /></td></tr>
|
|
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d66/vector__cross__product_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
|
|
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft"> </td><td class="mdescRight">Main Function. <a href="../../df/d66/vector__cross__product_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
|
|
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
<div class="textblock"><p >Calculates the <a href="https://en.wikipedia.org/wiki/Cross_product" target="_blank">Cross Product</a> and the magnitude of two mathematical 3D vectors. </p>
|
|
<p >Cross Product of two vectors gives a vector. Direction Ratios of a vector are the numeric parts of the given vector. They are the tree parts of the vector which determine the magnitude (value) of the vector. The method of finding a cross product is the same as finding the determinant of an order 3 matrix consisting of the first row with unit vectors of magnitude 1, the second row with the direction ratios of the first vector and the third row with the direction ratios of the second vector. The magnitude of a vector is it's value expressed as a number. Let the direction ratios of the first vector, P be: a, b, c Let the direction ratios of the second vector, Q be: x, y, z Therefore the calculation for the cross product can be arranged as:</p>
|
|
<div class="fragment"><div class="line">P x Q:</div>
|
|
<div class="line"> 1 1 1</div>
|
|
<div class="line"> a b c</div>
|
|
<div class="line"> x y z</div>
|
|
</div><!-- fragment --><p >The direction ratios (DR) are calculated as follows: 1st DR, J: (b * z) - (c * y) 2nd DR, A: -((a * z) - (c * x)) 3rd DR, N: (a * y) - (b * x)</p>
|
|
<p >Therefore, the direction ratios of the cross product are: J, A, N The following C++ Program calculates the direction ratios of the cross products of two vector. The program uses a function, <a class="el" href="../../df/d66/vector__cross__product_8cpp.html#a225732399c5c076976eae5b180a9f8c9" title="Function to calculate the cross product of the passed arrays containing the direction ratios of the t...">cross()</a> for doing so. The direction ratios for the first and the second vector has to be passed one by one seperated by a space character.</p>
|
|
<p >Magnitude of a vector is the square root of the sum of the squares of the direction ratios.</p>
|
|
<h3><a class="anchor" id="autotoc_md86"></a>
|
|
Example:</h3>
|
|
<p >An example of a running instance of the executable program: </p><pre class="fragment">Pass the first Vector: 1 2 3
|
|
</pre><p> Pass the second Vector: 4 5 6 The cross product is: -3 6 -3 Magnitude: 7.34847</p>
|
|
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/Shreyas-OwO" target="_blank">Shreyas Sable</a> </dd></dl>
|
|
</div><h2 class="groupheader">Function Documentation</h2>
|
|
<a id="a225732399c5c076976eae5b180a9f8c9" name="a225732399c5c076976eae5b180a9f8c9"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a225732399c5c076976eae5b180a9f8c9">◆ </a></span>cross()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a>< double, 3 > math::vector_cross::cross </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a>< double, 3 > & </td>
|
|
<td class="paramname"><em>A</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a>< double, 3 > & </td>
|
|
<td class="paramname"><em>B</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Function to calculate the cross product of the passed arrays containing the direction ratios of the two mathematical vectors. </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">A</td><td>contains the direction ratios of the first mathematical vector. </td></tr>
|
|
<tr><td class="paramname">B</td><td>contains the direction ration of the second mathematical vector. </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>the direction ratios of the cross product. </dd></dl>
|
|
<p >Performs the cross product as shown in @algorithm.</p>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 69</span> {</div>
|
|
<div class="line"><span class="lineno"> 70</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array<double, 3></a> product;<span class="comment"></span></div>
|
|
<div class="line"><span class="lineno"> 71</span><span class="comment"> /// Performs the cross product as shown in @algorithm.</span></div>
|
|
<div class="line"><span class="lineno"> 72</span><span class="comment"></span> product[0] = (A[1] * B[2]) - (A[2] * B[1]);</div>
|
|
<div class="line"><span class="lineno"> 73</span> product[1] = -((A[0] * B[2]) - (A[2] * B[0]));</div>
|
|
<div class="line"><span class="lineno"> 74</span> product[2] = (A[0] * B[1]) - (A[1] * B[0]);</div>
|
|
<div class="line"><span class="lineno"> 75</span> <span class="keywordflow">return</span> product;</div>
|
|
<div class="line"><span class="lineno"> 76</span> }</div>
|
|
<div class="ttc" id="aarray_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a></div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../df/d66/vector__cross__product_8cpp_a225732399c5c076976eae5b180a9f8c9_cgraph.svg" width="146" height="76"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a4b2a9757a87c18e1642d72410ecfaba8" name="a4b2a9757a87c18e1642d72410ecfaba8"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a4b2a9757a87c18e1642d72410ecfaba8">◆ </a></span>mag()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">double math::vector_cross::mag </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a>< double, 3 > & </td>
|
|
<td class="paramname"><em>vec</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Calculates the magnitude of the mathematical vector from it's direction ratios. </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">vec</td><td>an array containing the direction ratios of a mathematical vector. </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>type: double description: the magnitude of the mathematical vector from the given direction ratios. </dd></dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 83</span> {</div>
|
|
<div class="line"><span class="lineno"> 84</span> <span class="keywordtype">double</span> magnitude = <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/sqrt.html">sqrt</a>((vec[0] * vec[0]) + (vec[1] * vec[1]) + (vec[2] * vec[2]));</div>
|
|
<div class="line"><span class="lineno"> 85</span> <span class="keywordflow">return</span> magnitude;</div>
|
|
<div class="line"><span class="lineno"> 86</span> }</div>
|
|
<div class="ttc" id="asqrt_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/numeric/math/sqrt.html">std::sqrt</a></div><div class="ttdeci">T sqrt(T... args)</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../df/d66/vector__cross__product_8cpp_a4b2a9757a87c18e1642d72410ecfaba8_cgraph.svg" width="178" height="62"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">◆ </a></span>main()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int main </td>
|
|
<td>(</td>
|
|
<td class="paramtype">void </td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Main Function. </p>
|
|
<p >Asks the user to enter the direction ratios for each of the two mathematical vectors using <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_istream.html">std::cin</a> </p><dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
|
|
<p >Tests the functions with sample input before asking for user input.</p>
|
|
<p >Gets the values for the first vector.</p>
|
|
<p >Gets the values for the second vector.</p>
|
|
<p >Displays the output out.</p>
|
|
<p >Displays the magnitude of the cross product.</p>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 109</span> {</div>
|
|
<div class="line"><span class="lineno"> 110</span><span class="comment"></span> </div>
|
|
<div class="line"><span class="lineno"> 111</span><span class="comment"> /// Tests the functions with sample input before asking for user input.</span></div>
|
|
<div class="line"><span class="lineno"> 112</span><span class="comment"></span> <a class="code hl_function" href="../../df/d66/vector__cross__product_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>();</div>
|
|
<div class="line"><span class="lineno"> 113</span> </div>
|
|
<div class="line"><span class="lineno"> 114</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array<double, 3></a> vec1;</div>
|
|
<div class="line"><span class="lineno"> 115</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array<double, 3></a> vec2;</div>
|
|
<div class="line"><span class="lineno"> 116</span><span class="comment"></span> </div>
|
|
<div class="line"><span class="lineno"> 117</span><span class="comment"> /// Gets the values for the first vector.</span></div>
|
|
<div class="line"><span class="lineno"> 118</span><span class="comment"></span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"\nPass the first Vector: "</span>;</div>
|
|
<div class="line"><span class="lineno"> 119</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_istream.html">std::cin</a> >> vec1[0] >> vec1[1] >> vec1[2];</div>
|
|
<div class="line"><span class="lineno"> 120</span><span class="comment"></span> </div>
|
|
<div class="line"><span class="lineno"> 121</span><span class="comment"> /// Gets the values for the second vector.</span></div>
|
|
<div class="line"><span class="lineno"> 122</span><span class="comment"></span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"\nPass the second Vector: "</span>;</div>
|
|
<div class="line"><span class="lineno"> 123</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_istream.html">std::cin</a> >> vec2[0] >> vec2[1] >> vec2[2];</div>
|
|
<div class="line"><span class="lineno"> 124</span><span class="comment"></span> </div>
|
|
<div class="line"><span class="lineno"> 125</span><span class="comment"> /// Displays the output out.</span></div>
|
|
<div class="line"><span class="lineno"> 126</span><span class="comment"></span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array<double, 3></a> product = <a class="code hl_function" href="../../df/d66/vector__cross__product_8cpp.html#a225732399c5c076976eae5b180a9f8c9">math::vector_cross::cross</a>(vec1, vec2);</div>
|
|
<div class="line"><span class="lineno"> 127</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"\nThe cross product is: "</span> << product[0] << <span class="stringliteral">" "</span> << product[1] << <span class="stringliteral">" "</span> << product[2] << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
|
<div class="line"><span class="lineno"> 128</span><span class="comment"></span> </div>
|
|
<div class="line"><span class="lineno"> 129</span><span class="comment"> /// Displays the magnitude of the cross product.</span></div>
|
|
<div class="line"><span class="lineno"> 130</span><span class="comment"></span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Magnitude: "</span> << <a class="code hl_function" href="../../df/d66/vector__cross__product_8cpp.html#a4b2a9757a87c18e1642d72410ecfaba8">math::vector_cross::mag</a>(product) << <span class="stringliteral">"\n"</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
|
<div class="line"><span class="lineno"> 131</span> </div>
|
|
<div class="line"><span class="lineno"> 132</span> <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><span class="lineno"> 133</span>}</div>
|
|
<div class="ttc" id="abasic_istream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_istream.html">std::cin</a></div></div>
|
|
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
|
|
<div class="ttc" id="aendl_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a></div><div class="ttdeci">T endl(T... args)</div></div>
|
|
<div class="ttc" id="avector__cross__product_8cpp_html_a225732399c5c076976eae5b180a9f8c9"><div class="ttname"><a href="../../df/d66/vector__cross__product_8cpp.html#a225732399c5c076976eae5b180a9f8c9">math::vector_cross::cross</a></div><div class="ttdeci">std::array< double, 3 > cross(const std::array< double, 3 > &A, const std::array< double, 3 > &B)</div><div class="ttdoc">Function to calculate the cross product of the passed arrays containing the direction ratios of the t...</div><div class="ttdef"><b>Definition:</b> vector_cross_product.cpp:69</div></div>
|
|
<div class="ttc" id="avector__cross__product_8cpp_html_a4b2a9757a87c18e1642d72410ecfaba8"><div class="ttname"><a href="../../df/d66/vector__cross__product_8cpp.html#a4b2a9757a87c18e1642d72410ecfaba8">math::vector_cross::mag</a></div><div class="ttdeci">double mag(const std::array< double, 3 > &vec)</div><div class="ttdoc">Calculates the magnitude of the mathematical vector from it's direction ratios.</div><div class="ttdef"><b>Definition:</b> vector_cross_product.cpp:83</div></div>
|
|
<div class="ttc" id="avector__cross__product_8cpp_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../df/d66/vector__cross__product_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">namespace math</div><div class="ttdef"><b>Definition:</b> vector_cross_product.cpp:94</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../df/d66/vector__cross__product_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="182" height="88"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="aa8dca7b867074164d5f45b0f3851269d" name="aa8dca7b867074164d5f45b0f3851269d"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aa8dca7b867074164d5f45b0f3851269d">◆ </a></span>test()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">static void test </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">static</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>namespace math </p>
|
|
<p >test function.</p>
|
|
<p >test the <a class="el" href="../../df/d66/vector__cross__product_8cpp.html#a225732399c5c076976eae5b180a9f8c9" title="Function to calculate the cross product of the passed arrays containing the direction ratios of the t...">cross()</a> and the <a class="el" href="../../df/d66/vector__cross__product_8cpp.html#a4b2a9757a87c18e1642d72410ecfaba8" title="Calculates the magnitude of the mathematical vector from it's direction ratios.">mag()</a> functions. </p>
|
|
<p >Tests the <a class="el" href="../../df/d66/vector__cross__product_8cpp.html#a225732399c5c076976eae5b180a9f8c9" title="Function to calculate the cross product of the passed arrays containing the direction ratios of the t...">cross()</a> function.</p>
|
|
<p >Tests the <a class="el" href="../../df/d66/vector__cross__product_8cpp.html#a4b2a9757a87c18e1642d72410ecfaba8" title="Calculates the magnitude of the mathematical vector from it's direction ratios.">mag()</a> function.</p>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 94</span> {<span class="comment"></span></div>
|
|
<div class="line"><span class="lineno"> 95</span><span class="comment"> /// Tests the cross() function.</span></div>
|
|
<div class="line"><span class="lineno"> 96</span><span class="comment"></span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array<double, 3></a> t_vec = <a class="code hl_function" href="../../df/d66/vector__cross__product_8cpp.html#a225732399c5c076976eae5b180a9f8c9">math::vector_cross::cross</a>({1, 2, 3}, {4, 5, 6});</div>
|
|
<div class="line"><span class="lineno"> 97</span> assert(t_vec[0] == -3 && t_vec[1] == 6 && t_vec[2] == -3);</div>
|
|
<div class="line"><span class="lineno"> 98</span><span class="comment"></span> </div>
|
|
<div class="line"><span class="lineno"> 99</span><span class="comment"> /// Tests the mag() function.</span></div>
|
|
<div class="line"><span class="lineno"> 100</span><span class="comment"></span> <span class="keywordtype">double</span> t_mag = <a class="code hl_function" href="../../df/d66/vector__cross__product_8cpp.html#a4b2a9757a87c18e1642d72410ecfaba8">math::vector_cross::mag</a>({6, 8, 0});</div>
|
|
<div class="line"><span class="lineno"> 101</span> assert(t_mag == 10);</div>
|
|
<div class="line"><span class="lineno"> 102</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
</div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<!-- start footer part -->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="../../dir_296d53ceaeaa7e099814a6def439fe8a.html">math</a></li><li class="navelem"><a class="el" href="../../df/d66/vector__cross__product_8cpp.html">vector_cross_product.cpp</a></li>
|
|
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.3 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|