Files
C-Plus-Plus/d4/db4/struct_segment_intersection.html
2025-05-19 11:38:33 +00:00

322 lines
22 KiB
HTML

<!-- HTML header for doxygen 1.12.0-->
<!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.13.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>TheAlgorithms/C++: SegmentIntersection Struct Reference</title>
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
<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>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpack-3rd-party/doxygen-awesome-css@2.2.0-1/doxygen-awesome-darkmode-toggle.js"></script>
<script type="text/javascript">
DoxygenAwesomeDarkModeToggle.init()
</script>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../cookie.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">
window.MathJax = {
options: {
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process'
},
loader: {
load: ['[tex]/ams']
},
tex: {
macros: {},
packages: ['base','configmacros','ams']
}
};
</script>
<script type="text/javascript" id="MathJax-script" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../doxygen-awesome.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="projectlogo"><img alt="Logo" src="../../project_logo.png"/></td>
<td id="projectalign">
<div id="projectname">TheAlgorithms/C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">All the algorithms implemented in C++</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.13.2 -->
<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">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(1); });
/* @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',true);
$(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 */
$(function(){initNavTree('d4/db4/struct_segment_intersection.html','../../'); initResizable(true); });
/* @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="../../dd/da8/struct_segment_intersection-members.html">List of all members</a> </div>
<div class="headertitle"><div class="title">SegmentIntersection Struct Reference</div></div>
</div><!--header-->
<div class="contents">
<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:aefd077282f45bd16799b53f8aa430ffd" id="r_aefd077282f45bd16799b53f8aa430ffd"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#aefd077282f45bd16799b53f8aa430ffd">intersect</a> (<a class="el" href="../../d8/dc8/struct_point.html">Point</a> first_point, <a class="el" href="../../d8/dc8/struct_point.html">Point</a> second_point, <a class="el" href="../../d8/dc8/struct_point.html">Point</a> third_point, <a class="el" href="../../d8/dc8/struct_point.html">Point</a> forth_point)</td></tr>
<tr class="separator:aefd077282f45bd16799b53f8aa430ffd"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3beb2ac1b35d67354f1dbaf9a971e655" id="r_a3beb2ac1b35d67354f1dbaf9a971e655"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a3beb2ac1b35d67354f1dbaf9a971e655">direction</a> (<a class="el" href="../../d8/dc8/struct_point.html">Point</a> first_point, <a class="el" href="../../d8/dc8/struct_point.html">Point</a> second_point, <a class="el" href="../../d8/dc8/struct_point.html">Point</a> third_point)</td></tr>
<tr class="separator:a3beb2ac1b35d67354f1dbaf9a971e655"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a008941b2272866c64cdaf959afa939bf" id="r_a008941b2272866c64cdaf959afa939bf"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a008941b2272866c64cdaf959afa939bf">on_segment</a> (<a class="el" href="../../d8/dc8/struct_point.html">Point</a> first_point, <a class="el" href="../../d8/dc8/struct_point.html">Point</a> second_point, <a class="el" href="../../d8/dc8/struct_point.html">Point</a> third_point)</td></tr>
<tr class="separator:a008941b2272866c64cdaf959afa939bf"><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>intersect returns true if segments of two line intersects and false if they do not. It calls the subroutines direction which computes the orientation. </p>
<p class="definition">Definition at line <a class="el" href="../../d8/d6c/line__segment__intersection_8cpp_source.html#l00022">22</a> of file <a class="el" href="../../d8/d6c/line__segment__intersection_8cpp_source.html">line_segment_intersection.cpp</a>.</p>
</div><h2 class="groupheader">Member Function Documentation</h2>
<a id="a3beb2ac1b35d67354f1dbaf9a971e655" name="a3beb2ac1b35d67354f1dbaf9a971e655"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3beb2ac1b35d67354f1dbaf9a971e655">&#9670;&#160;</a></span>direction()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">int SegmentIntersection::direction </td>
<td>(</td>
<td class="paramtype"><a class="el" href="../../d8/dc8/struct_point.html">Point</a></td> <td class="paramname"><span class="paramname"><em>first_point</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="../../d8/dc8/struct_point.html">Point</a></td> <td class="paramname"><span class="paramname"><em>second_point</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="../../d8/dc8/struct_point.html">Point</a></td> <td class="paramname"><span class="paramname"><em>third_point</em></span>&#160;)</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel inline">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>We will find direction of line here respect to @first_point. Here @second_point and @third_point is first and second points of the line respectively. we want a method to determine which way a given angle these three points turns. If returned number is negative, then the angle is counter-clockwise. That means the line is going to right to left. We will fount angle as clockwise if the method returns positive number. </p>
<p class="definition">Definition at line <a class="el" href="../../d8/d6c/line__segment__intersection_8cpp_source.html#l00063">63</a> of file <a class="el" href="../../d8/d6c/line__segment__intersection_8cpp_source.html">line_segment_intersection.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 64</span> {</div>
<div class="line"><span class="lineno"> 65</span> <span class="keywordflow">return</span> ((third_point.x - first_point.x) *</div>
<div class="line"><span class="lineno"> 66</span> (second_point.<a class="code hl_variable" href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">y</a> - first_point.<a class="code hl_variable" href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">y</a>)) -</div>
<div class="line"><span class="lineno"> 67</span> ((second_point.x - first_point.x) *</div>
<div class="line"><span class="lineno"> 68</span> (third_point.<a class="code hl_variable" href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">y</a> - first_point.<a class="code hl_variable" href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">y</a>));</div>
<div class="line"><span class="lineno"> 69</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> <a href="../../d8/d6c/line__segment__intersection_8cpp_source.html#l00014">line_segment_intersection.cpp:14</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="aefd077282f45bd16799b53f8aa430ffd" name="aefd077282f45bd16799b53f8aa430ffd"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aefd077282f45bd16799b53f8aa430ffd">&#9670;&#160;</a></span>intersect()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">bool SegmentIntersection::intersect </td>
<td>(</td>
<td class="paramtype"><a class="el" href="../../d8/dc8/struct_point.html">Point</a></td> <td class="paramname"><span class="paramname"><em>first_point</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="../../d8/dc8/struct_point.html">Point</a></td> <td class="paramname"><span class="paramname"><em>second_point</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="../../d8/dc8/struct_point.html">Point</a></td> <td class="paramname"><span class="paramname"><em>third_point</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="../../d8/dc8/struct_point.html">Point</a></td> <td class="paramname"><span class="paramname"><em>forth_point</em></span>&#160;)</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel inline">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p class="definition">Definition at line <a class="el" href="../../d8/d6c/line__segment__intersection_8cpp_source.html#l00023">23</a> of file <a class="el" href="../../d8/d6c/line__segment__intersection_8cpp_source.html">line_segment_intersection.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 24</span> {</div>
<div class="line"><span class="lineno"> 25</span> <span class="keywordtype">int</span> direction1 = <a class="code hl_function" href="#a3beb2ac1b35d67354f1dbaf9a971e655">direction</a>(third_point, forth_point, first_point);</div>
<div class="line"><span class="lineno"> 26</span> <span class="keywordtype">int</span> direction2 = <a class="code hl_function" href="#a3beb2ac1b35d67354f1dbaf9a971e655">direction</a>(third_point, forth_point, second_point);</div>
<div class="line"><span class="lineno"> 27</span> <span class="keywordtype">int</span> direction3 = <a class="code hl_function" href="#a3beb2ac1b35d67354f1dbaf9a971e655">direction</a>(first_point, second_point, third_point);</div>
<div class="line"><span class="lineno"> 28</span> <span class="keywordtype">int</span> direction4 = <a class="code hl_function" href="#a3beb2ac1b35d67354f1dbaf9a971e655">direction</a>(first_point, second_point, forth_point);</div>
<div class="line"><span class="lineno"> 29</span> </div>
<div class="line"><span class="lineno"> 30</span> <span class="keywordflow">if</span> ((direction1 &lt; 0 || direction2 &gt; 0) &amp;&amp;</div>
<div class="line"><span class="lineno"> 31</span> (direction3 &lt; 0 || direction4 &gt; 0))</div>
<div class="line"><span class="lineno"> 32</span> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><span class="lineno"> 33</span> </div>
<div class="line"><span class="lineno"> 34</span> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (direction1 == 0 &amp;&amp;</div>
<div class="line"><span class="lineno"> 35</span> <a class="code hl_function" href="#a008941b2272866c64cdaf959afa939bf">on_segment</a>(third_point, forth_point, first_point))</div>
<div class="line"><span class="lineno"> 36</span> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><span class="lineno"> 37</span> </div>
<div class="line"><span class="lineno"> 38</span> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (direction2 == 0 &amp;&amp;</div>
<div class="line"><span class="lineno"> 39</span> <a class="code hl_function" href="#a008941b2272866c64cdaf959afa939bf">on_segment</a>(third_point, forth_point, second_point))</div>
<div class="line"><span class="lineno"> 40</span> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><span class="lineno"> 41</span> </div>
<div class="line"><span class="lineno"> 42</span> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (direction3 == 0 &amp;&amp;</div>
<div class="line"><span class="lineno"> 43</span> <a class="code hl_function" href="#a008941b2272866c64cdaf959afa939bf">on_segment</a>(first_point, second_point, third_point))</div>
<div class="line"><span class="lineno"> 44</span> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><span class="lineno"> 45</span> </div>
<div class="line"><span class="lineno"> 46</span> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (direction3 == 0 &amp;&amp;</div>
<div class="line"><span class="lineno"> 47</span> <a class="code hl_function" href="#a008941b2272866c64cdaf959afa939bf">on_segment</a>(first_point, second_point, forth_point))</div>
<div class="line"><span class="lineno"> 48</span> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><span class="lineno"> 49</span> </div>
<div class="line"><span class="lineno"> 50</span> <span class="keywordflow">else</span></div>
<div class="line"><span class="lineno"> 51</span> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><span class="lineno"> 52</span> }</div>
<div class="ttc" id="astruct_segment_intersection_html_a008941b2272866c64cdaf959afa939bf"><div class="ttname"><a href="#a008941b2272866c64cdaf959afa939bf">SegmentIntersection::on_segment</a></div><div class="ttdeci">bool on_segment(Point first_point, Point second_point, Point third_point)</div><div class="ttdef"><b>Definition</b> <a href="../../d8/d6c/line__segment__intersection_8cpp_source.html#l00075">line_segment_intersection.cpp:75</a></div></div>
<div class="ttc" id="astruct_segment_intersection_html_a3beb2ac1b35d67354f1dbaf9a971e655"><div class="ttname"><a href="#a3beb2ac1b35d67354f1dbaf9a971e655">SegmentIntersection::direction</a></div><div class="ttdeci">int direction(Point first_point, Point second_point, Point third_point)</div><div class="ttdef"><b>Definition</b> <a href="../../d8/d6c/line__segment__intersection_8cpp_source.html#l00063">line_segment_intersection.cpp:63</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a008941b2272866c64cdaf959afa939bf" name="a008941b2272866c64cdaf959afa939bf"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a008941b2272866c64cdaf959afa939bf">&#9670;&#160;</a></span>on_segment()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">bool SegmentIntersection::on_segment </td>
<td>(</td>
<td class="paramtype"><a class="el" href="../../d8/dc8/struct_point.html">Point</a></td> <td class="paramname"><span class="paramname"><em>first_point</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="../../d8/dc8/struct_point.html">Point</a></td> <td class="paramname"><span class="paramname"><em>second_point</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="../../d8/dc8/struct_point.html">Point</a></td> <td class="paramname"><span class="paramname"><em>third_point</em></span>&#160;)</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel inline">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>This method determines whether a point known to be colinear with a segment lies on that segment. </p>
<p class="definition">Definition at line <a class="el" href="../../d8/d6c/line__segment__intersection_8cpp_source.html#l00075">75</a> of file <a class="el" href="../../d8/d6c/line__segment__intersection_8cpp_source.html">line_segment_intersection.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 76</span> {</div>
<div class="line"><span class="lineno"> 77</span> <span class="keywordflow">if</span> (std::min(first_point.x, second_point.x) &lt;= third_point.x &amp;&amp;</div>
<div class="line"><span class="lineno"> 78</span> third_point.x &lt;= std::max(first_point.x, second_point.x) &amp;&amp;</div>
<div class="line"><span class="lineno"> 79</span> std::min(first_point.<a class="code hl_variable" href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">y</a>, second_point.<a class="code hl_variable" href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">y</a>) &lt;= third_point.<a class="code hl_variable" href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">y</a> &amp;&amp;</div>
<div class="line"><span class="lineno"> 80</span> third_point.<a class="code hl_variable" href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">y</a> &lt;= std::max(first_point.<a class="code hl_variable" href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">y</a>, second_point.<a class="code hl_variable" href="../../d8/dc8/struct_point.html#a2e1b5fb2b2a83571f5c0bc0f66a73cf7">y</a>))</div>
<div class="line"><span class="lineno"> 81</span> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><span class="lineno"> 82</span> </div>
<div class="line"><span class="lineno"> 83</span> <span class="keywordflow">else</span></div>
<div class="line"><span class="lineno"> 84</span> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><span class="lineno"> 85</span> }</div>
</div><!-- fragment -->
</div>
</div>
<hr/>The documentation for this struct was generated from the following file:<ul>
<li>geometry/<a class="el" href="../../d8/d6c/line__segment__intersection_8cpp_source.html">line_segment_intersection.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="../../d4/db4/struct_segment_intersection.html">SegmentIntersection</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.13.2 </li>
</ul>
</div>
</body>
</html>