Files
C-Plus-Plus/d4/dde/classgeometry_1_1jarvis_1_1_convexhull.html
2022-09-02 14:36:25 +00:00

340 lines
23 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" lang="en-US">
<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.5"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: geometry::jarvis::Convexhull Class 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">&#160;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.5 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../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&amp;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&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('d4/dde/classgeometry_1_1jarvis_1_1_convexhull.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">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pub-static-methods">Static Public Member Functions</a> &#124;
<a href="#pri-attribs">Private Attributes</a> &#124;
<a href="../../d1/de7/classgeometry_1_1jarvis_1_1_convexhull-members.html">List of all members</a> </div>
<div class="headertitle"><div class="title">geometry::jarvis::Convexhull Class Reference</div></div>
</div><!--header-->
<div class="contents">
<div class="dynheader">
Collaboration diagram for geometry::jarvis::Convexhull:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../db/d29/classgeometry_1_1jarvis_1_1_convexhull__coll__graph.svg" width="199" height="227"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
<center><span class="legend">[<a target="top" href="../../graph_legend.html">legend</a>]</span></center></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a8306e48040a8570e164c58d1c530f870"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/dde/classgeometry_1_1jarvis_1_1_convexhull.html#a8306e48040a8570e164c58d1c530f870">Convexhull</a> (const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a>&lt; <a class="el" href="../../d9/d5a/structgeometry_1_1jarvis_1_1_point.html">Point</a> &gt; &amp;pointList)</td></tr>
<tr class="separator:a8306e48040a8570e164c58d1c530f870"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aeec46e86786ddd461464b07a77c4d5f1"><td class="memItemLeft" align="right" valign="top"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a>&lt; <a class="el" href="../../d9/d5a/structgeometry_1_1jarvis_1_1_point.html">Point</a> &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/dde/classgeometry_1_1jarvis_1_1_convexhull.html#aeec46e86786ddd461464b07a77c4d5f1">getConvexHull</a> () const</td></tr>
<tr class="separator:aeec46e86786ddd461464b07a77c4d5f1"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-static-methods" name="pub-static-methods"></a>
Static Public Member Functions</h2></td></tr>
<tr class="memitem:a54df5f9a8f37170bd97c91127664655c"><td class="memItemLeft" align="right" valign="top">static int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/dde/classgeometry_1_1jarvis_1_1_convexhull.html#a54df5f9a8f37170bd97c91127664655c">orientation</a> (const <a class="el" href="../../d9/d5a/structgeometry_1_1jarvis_1_1_point.html">Point</a> &amp;p, const <a class="el" href="../../d9/d5a/structgeometry_1_1jarvis_1_1_point.html">Point</a> &amp;q, const <a class="el" href="../../d9/d5a/structgeometry_1_1jarvis_1_1_point.html">Point</a> &amp;r)</td></tr>
<tr class="separator:a54df5f9a8f37170bd97c91127664655c"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pri-attribs" name="pri-attribs"></a>
Private Attributes</h2></td></tr>
<tr class="memitem:a835cd4cdc5a644abb84535197d753b02"><td class="memItemLeft" align="right" valign="top"><a id="a835cd4cdc5a644abb84535197d753b02" name="a835cd4cdc5a644abb84535197d753b02"></a>
<a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a>&lt; <a class="el" href="../../d9/d5a/structgeometry_1_1jarvis_1_1_point.html">Point</a> &gt;&#160;</td><td class="memItemRight" valign="bottom"><b>points</b></td></tr>
<tr class="separator:a835cd4cdc5a644abb84535197d753b02"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2272bb62c35af959953b0ea06b010036"><td class="memItemLeft" align="right" valign="top"><a id="a2272bb62c35af959953b0ea06b010036" name="a2272bb62c35af959953b0ea06b010036"></a>
int&#160;</td><td class="memItemRight" valign="bottom"><b>size</b></td></tr>
<tr class="separator:a2272bb62c35af959953b0ea06b010036"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >Class which can be called from main and is globally available throughout the code </p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a8306e48040a8570e164c58d1c530f870" name="a8306e48040a8570e164c58d1c530f870"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8306e48040a8570e164c58d1c530f870">&#9670;&#160;</a></span>Convexhull()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">geometry::jarvis::Convexhull::Convexhull </td>
<td>(</td>
<td class="paramtype">const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a>&lt; <a class="el" href="../../d9/d5a/structgeometry_1_1jarvis_1_1_point.html">Point</a> &gt; &amp;&#160;</td>
<td class="paramname"><em>pointList</em></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">explicit</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p >Constructor of given class</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">pointList</td><td>list of all points in the space </td></tr>
<tr><td class="paramname">n</td><td>number of points in space </td></tr>
</table>
</dd>
</dl>
<div class="fragment"><div class="line"><span class="lineno"> 66</span> {</div>
<div class="line"><span class="lineno"> 67</span> points = pointList;</div>
<div class="line"><span class="lineno"> 68</span> size = points.size();</div>
<div class="line"><span class="lineno"> 69</span> }</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="../../d4/dde/classgeometry_1_1jarvis_1_1_convexhull_a8306e48040a8570e164c58d1c530f870_cgraph.svg" width="363" height="51"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="aeec46e86786ddd461464b07a77c4d5f1" name="aeec46e86786ddd461464b07a77c4d5f1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aeec46e86786ddd461464b07a77c4d5f1">&#9670;&#160;</a></span>getConvexHull()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a>&lt; <a class="el" href="../../d9/d5a/structgeometry_1_1jarvis_1_1_point.html">Point</a> &gt; geometry::jarvis::Convexhull::getConvexHull </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p >Creates convex hull of a set of n points. There must be 3 points at least for the convex hull to exist</p>
<dl class="section return"><dt>Returns</dt><dd>an vector array containing points in space which enclose all given points thus forming a hull </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 78</span> {</div>
<div class="line"><span class="lineno"> 79</span> <span class="comment">// Initialize Result</span></div>
<div class="line"><span class="lineno"> 80</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;Point&gt;</a> hull;</div>
<div class="line"><span class="lineno"> 81</span> </div>
<div class="line"><span class="lineno"> 82</span> <span class="comment">// Find the leftmost point</span></div>
<div class="line"><span class="lineno"> 83</span> <span class="keywordtype">int</span> leftmost_point = 0;</div>
<div class="line"><span class="lineno"> 84</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i &lt; size; i++) {</div>
<div class="line"><span class="lineno"> 85</span> <span class="keywordflow">if</span> (points[i].x &lt; points[leftmost_point].x) {</div>
<div class="line"><span class="lineno"> 86</span> leftmost_point = i;</div>
<div class="line"><span class="lineno"> 87</span> }</div>
<div class="line"><span class="lineno"> 88</span> }</div>
<div class="line"><span class="lineno"> 89</span> <span class="comment">// Start from leftmost point, keep moving counterclockwise</span></div>
<div class="line"><span class="lineno"> 90</span> <span class="comment">// until reach the start point again. This loop runs O(h)</span></div>
<div class="line"><span class="lineno"> 91</span> <span class="comment">// times where h is number of points in result or output.</span></div>
<div class="line"><span class="lineno"> 92</span> <span class="keywordtype">int</span> p = leftmost_point, q = 0;</div>
<div class="line"><span class="lineno"> 93</span> <span class="keywordflow">do</span> {</div>
<div class="line"><span class="lineno"> 94</span> <span class="comment">// Add current point to result</span></div>
<div class="line"><span class="lineno"> 95</span> hull.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/push_back.html">push_back</a>(points[p]);</div>
<div class="line"><span class="lineno"> 96</span> </div>
<div class="line"><span class="lineno"> 97</span> <span class="comment">// Search for a point &#39;q&#39; such that orientation(p, x, q)</span></div>
<div class="line"><span class="lineno"> 98</span> <span class="comment">// is counterclockwise for all points &#39;x&#39;. The idea</span></div>
<div class="line"><span class="lineno"> 99</span> <span class="comment">// is to keep track of last visited most counter clock-</span></div>
<div class="line"><span class="lineno"> 100</span> <span class="comment">// wise point in q. If any point &#39;i&#39; is more counter clock-</span></div>
<div class="line"><span class="lineno"> 101</span> <span class="comment">// wise than q, then update q.</span></div>
<div class="line"><span class="lineno"> 102</span> q = (p + 1) % size;</div>
<div class="line"><span class="lineno"> 103</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; size; i++) {</div>
<div class="line"><span class="lineno"> 104</span> <span class="comment">// If i is more counterclockwise than current q, then</span></div>
<div class="line"><span class="lineno"> 105</span> <span class="comment">// update q</span></div>
<div class="line"><span class="lineno"> 106</span> <span class="keywordflow">if</span> (<a class="code hl_function" href="../../d4/dde/classgeometry_1_1jarvis_1_1_convexhull.html#a54df5f9a8f37170bd97c91127664655c">orientation</a>(points[p], points[i], points[q]) == 2) {</div>
<div class="line"><span class="lineno"> 107</span> q = i;</div>
<div class="line"><span class="lineno"> 108</span> }</div>
<div class="line"><span class="lineno"> 109</span> }</div>
<div class="line"><span class="lineno"> 110</span> </div>
<div class="line"><span class="lineno"> 111</span> <span class="comment">// Now q is the most counterclockwise with respect to p</span></div>
<div class="line"><span class="lineno"> 112</span> <span class="comment">// Set p as q for next iteration, so that q is added to</span></div>
<div class="line"><span class="lineno"> 113</span> <span class="comment">// result &#39;hull&#39;</span></div>
<div class="line"><span class="lineno"> 114</span> p = q;</div>
<div class="line"><span class="lineno"> 115</span> </div>
<div class="line"><span class="lineno"> 116</span> } <span class="keywordflow">while</span> (p != leftmost_point); <span class="comment">// While we don&#39;t come to first point</span></div>
<div class="line"><span class="lineno"> 117</span> </div>
<div class="line"><span class="lineno"> 118</span> <span class="keywordflow">return</span> hull;</div>
<div class="line"><span class="lineno"> 119</span> }</div>
<div class="ttc" id="aclassgeometry_1_1jarvis_1_1_convexhull_html_a54df5f9a8f37170bd97c91127664655c"><div class="ttname"><a href="../../d4/dde/classgeometry_1_1jarvis_1_1_convexhull.html#a54df5f9a8f37170bd97c91127664655c">geometry::jarvis::Convexhull::orientation</a></div><div class="ttdeci">static int orientation(const Point &amp;p, const Point &amp;q, const Point &amp;r)</div><div class="ttdef"><b>Definition:</b> jarvis_algorithm.cpp:133</div></div>
<div class="ttc" id="apush_back_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/vector/push_back.html">std::vector::push_back</a></div><div class="ttdeci">T push_back(T... args)</div></div>
<div class="ttc" id="avector_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</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="../../d4/dde/classgeometry_1_1jarvis_1_1_convexhull_aeec46e86786ddd461464b07a77c4d5f1_cgraph.svg" width="435" height="102"><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="a54df5f9a8f37170bd97c91127664655c" name="a54df5f9a8f37170bd97c91127664655c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a54df5f9a8f37170bd97c91127664655c">&#9670;&#160;</a></span>orientation()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">static int geometry::jarvis::Convexhull::orientation </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="../../d9/d5a/structgeometry_1_1jarvis_1_1_point.html">Point</a> &amp;&#160;</td>
<td class="paramname"><em>p</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="../../d9/d5a/structgeometry_1_1jarvis_1_1_point.html">Point</a> &amp;&#160;</td>
<td class="paramname"><em>q</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="../../d9/d5a/structgeometry_1_1jarvis_1_1_point.html">Point</a> &amp;&#160;</td>
<td class="paramname"><em>r</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p >This function returns the geometric orientation for the three points in a space, ie, whether they are linear ir clockwise or anti-clockwise </p><dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">p</td><td>first point selected </td></tr>
<tr><td class="paramname">q</td><td>adjacent point for q </td></tr>
<tr><td class="paramname">r</td><td>adjacent point for q</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>0 -&gt; Linear </dd>
<dd>
1 -&gt; Clock Wise </dd>
<dd>
2 -&gt; Anti Clock Wise </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 133</span> {</div>
<div class="line"><span class="lineno"> 134</span> <span class="keywordtype">int</span> val = (q.y - p.<a class="code hl_variable" href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">y</a>) * (r.x - q.x) - (q.x - p.x) * (r.<a class="code hl_variable" href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">y</a> - q.y);</div>
<div class="line"><span class="lineno"> 135</span> </div>
<div class="line"><span class="lineno"> 136</span> <span class="keywordflow">if</span> (val == 0) {</div>
<div class="line"><span class="lineno"> 137</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 138</span> }</div>
<div class="line"><span class="lineno"> 139</span> <span class="keywordflow">return</span> (val &gt; 0) ? 1 : 2;</div>
<div class="line"><span class="lineno"> 140</span> }</div>
<div class="ttc" id="astruct_point_html_a2e1b5fb2b2a83571f5c0bc0f66a73cf7"><div class="ttname"><a href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">Point::y</a></div><div class="ttdeci">int y</div><div class="ttdoc">Point respect to x coordinate.</div><div class="ttdef"><b>Definition:</b> line_segment_intersection.cpp:14</div></div>
</div><!-- fragment -->
</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li>geometry/<a class="el" href="../../d4/d8d/jarvis__algorithm_8cpp.html">jarvis_algorithm.cpp</a></li>
</ul>
</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="../../d5/d5f/namespacegeometry.html">geometry</a></li><li class="navelem"><b>jarvis</b></li><li class="navelem"><a class="el" href="../../d4/dde/classgeometry_1_1jarvis_1_1_convexhull.html">Convexhull</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.5 </li>
</ul>
</div>
</body>
</html>