geometry_8c-source.html

来自「仿真人工智能是指用人工的方法和技术」· HTML 代码 · 共 754 行 · 第 1/5 页

HTML
754
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Geometry.C Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body bgcolor="#ffffff"><!-- Generated by Doxygen 1.2.12 --><center><a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center><hr><h1>Geometry.C</h1><a href="Geometry_8C.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/*</font>00002 <font class="comment">Copyright (c) 2000,2001, Jelle Kok, University of Amsterdam</font>00003 <font class="comment">All rights reserved.</font>00004 <font class="comment"></font>00005 <font class="comment">Redistribution and use in source and binary forms, with or without </font>00006 <font class="comment">modification, are permitted provided that the following conditions are met:</font>00007 <font class="comment"></font>00008 <font class="comment">1. Redistributions of source code must retain the above copyright notice, this </font>00009 <font class="comment">list of conditions and the following disclaimer. </font>00010 <font class="comment"></font>00011 <font class="comment">2. Redistributions in binary form must reproduce the above copyright notice, </font>00012 <font class="comment">this list of conditions and the following disclaimer in the documentation </font>00013 <font class="comment">and/or other materials provided with the distribution. </font>00014 <font class="comment"></font>00015 <font class="comment">3. Neither the name of the University of Amsterdam nor the names of its </font>00016 <font class="comment">contributors may be used to endorse or promote products derived from this </font>00017 <font class="comment">software without specific prior written permission. </font>00018 <font class="comment"></font>00019 <font class="comment">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" </font>00020 <font class="comment">AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE </font>00021 <font class="comment">IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE </font>00022 <font class="comment">DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE </font>00023 <font class="comment">FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL </font>00024 <font class="comment">DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR </font>00025 <font class="comment">SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER </font>00026 <font class="comment">CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, </font>00027 <font class="comment">OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE </font>00028 <font class="comment">OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</font>00029 <font class="comment">*/</font>00050 <font class="preprocessor">#include "<a class="code" href="Geometry_8h.html">Geometry.h</a>"</font>00051 <font class="preprocessor">#include &lt;stdio.h&gt;</font>    <font class="comment">// needed for sprintf</font>00052 <a name="l00057"></a><a class="code" href="Geometry_8C.html#a0">00057</a> <font class="keywordtype">int</font> <a class="code" href="Geometry_8h.html#a0">sign</a>( <font class="keywordtype">double</font> d1 )00058 {00059   <font class="keywordflow">return</font> (d1&gt;0)?1:-1;00060 }00061 <a name="l00066"></a><a class="code" href="Geometry_8C.html#a1">00066</a> <font class="keywordtype">double</font> <a class="code" href="Geometry_8h.html#a1">max</a>( <font class="keywordtype">double</font> d1, <font class="keywordtype">double</font> d2 )00067 {00068   <font class="keywordflow">return</font> (d1&gt;d2)?d1:d2;00069 }00070 <a name="l00075"></a><a class="code" href="Geometry_8C.html#a2">00075</a> <font class="keywordtype">double</font> <a class="code" href="Geometry_8h.html#a2">min</a>( <font class="keywordtype">double</font> d1, <font class="keywordtype">double</font> d2 )00076 {00077   <font class="keywordflow">return</font> (d1&lt;d2)?d1:d2;00078 }00079 00080 <a name="l00085"></a><a class="code" href="Geometry_8C.html#a3">00085</a> <a class="code" href="Geometry_8h.html#a2">AngDeg</a> <a class="code" href="Geometry_8h.html#a3">Rad2Deg</a>( <a class="code" href="Geometry_8h.html#a1">AngRad</a> x )00086 {00087   <font class="keywordflow">return</font> ( x * 180 / M_PI );00088 }00089 <a name="l00094"></a><a class="code" href="Geometry_8C.html#a4">00094</a> <a class="code" href="Geometry_8h.html#a1">AngRad</a> <a class="code" href="Geometry_8h.html#a4">Deg2Rad</a>( <a class="code" href="Geometry_8h.html#a2">AngDeg</a> x )00095 {00096   <font class="keywordflow">return</font> ( x * M_PI / 180 );00097 }00098 <a name="l00103"></a><a class="code" href="Geometry_8C.html#a5">00103</a> <font class="keywordtype">double</font> <a class="code" href="Geometry_8h.html#a5">cosDeg</a>( <a class="code" href="Geometry_8h.html#a2">AngDeg</a> x )00104 {00105   <font class="keywordflow">return</font> ( cos( <a class="code" href="Geometry_8h.html#a4">Deg2Rad</a>( x ) ) );00106 }00107 <a name="l00112"></a><a class="code" href="Geometry_8C.html#a6">00112</a> <font class="keywordtype">double</font> <a class="code" href="Geometry_8h.html#a6">sinDeg</a>( <a class="code" href="Geometry_8h.html#a2">AngDeg</a> x )00113 {00114   <font class="keywordflow">return</font> ( sin( <a class="code" href="Geometry_8h.html#a4">Deg2Rad</a>( x ) ) );00115 }00116 <a name="l00121"></a><a class="code" href="Geometry_8C.html#a7">00121</a> <font class="keywordtype">double</font> <a class="code" href="Geometry_8h.html#a7">tanDeg</a>( <a class="code" href="Geometry_8h.html#a2">AngDeg</a> x )00122 {00123   <font class="keywordflow">return</font> ( tan( <a class="code" href="Geometry_8h.html#a4">Deg2Rad</a>( x ) ) );00124 }00125 <a name="l00130"></a><a class="code" href="Geometry_8C.html#a8">00130</a> <a class="code" href="Geometry_8h.html#a2">AngDeg</a> <a class="code" href="Geometry_8h.html#a8">atanDeg</a>( <font class="keywordtype">double</font> x )00131 {00132   <font class="keywordflow">return</font> ( <a class="code" href="Geometry_8h.html#a3">Rad2Deg</a>( atan( x ) ) );00133 }00134 <a name="l00143"></a><a class="code" href="Geometry_8C.html#a9">00143</a> <font class="keywordtype">double</font> <a class="code" href="Geometry_8h.html#a9">atan2Deg</a>( <font class="keywordtype">double</font> x, <font class="keywordtype">double</font> y )00144 {00145   <font class="keywordflow">if</font>( fabs( x ) &lt; <a class="code" href="Geometry_8h.html#a0">EPSILON</a> &amp;&amp; fabs( y ) &lt; <a class="code" href="Geometry_8h.html#a0">EPSILON</a> )00146     <font class="keywordflow">return</font> ( 0.0 );00147 00148   <font class="keywordflow">return</font> ( <a class="code" href="Geometry_8h.html#a3">Rad2Deg</a>( atan2( x, y ) ) );00149 }00150 <a name="l00155"></a><a class="code" href="Geometry_8C.html#a10">00155</a> <a class="code" href="Geometry_8h.html#a2">AngDeg</a> <a class="code" href="Geometry_8h.html#a10">acosDeg</a>( <font class="keywordtype">double</font> x )00156 {00157   <font class="keywordflow">if</font>( x &gt;= 1 )00158     <font class="keywordflow">return</font> ( 0.0 );00159   <font class="keywordflow">else</font> <font class="keywordflow">if</font>( x &lt;= -1 )00160     <font class="keywordflow">return</font> ( 180.0 );00161 00162   <font class="keywordflow">return</font> ( <a class="code" href="Geometry_8h.html#a3">Rad2Deg</a>( acos( x ) ) );00163 }00164 <a name="l00169"></a><a class="code" href="Geometry_8C.html#a11">00169</a> <a class="code" href="Geometry_8h.html#a2">AngDeg</a> <a class="code" href="Geometry_8h.html#a11">asinDeg</a>( <font class="keywordtype">double</font> x )00170 {00171   <font class="keywordflow">if</font>( x &gt;= 1 )00172     <font class="keywordflow">return</font> ( 90.0 );00173   <font class="keywordflow">else</font> <font class="keywordflow">if</font> ( x &lt;= -1 )00174     <font class="keywordflow">return</font> ( -90.0 );00175 00176   <font class="keywordflow">return</font> ( <a class="code" href="Geometry_8h.html#a3">Rad2Deg</a>( asin( x ) ) );00177 }00178 <a name="l00187"></a><a class="code" href="Geometry_8C.html#a12">00187</a> <font class="keywordtype">bool</font> <a class="code" href="Geometry_8h.html#a12">isAngInInterval</a>( <a class="code" href="Geometry_8h.html#a2">AngDeg</a> ang, <a class="code" href="Geometry_8h.html#a2">AngDeg</a> angMin, <a class="code" href="Geometry_8h.html#a2">AngDeg</a> angMax )00188 {00189   <font class="comment">// convert all angles to interval 0..360</font>00190   <font class="keywordflow">if</font>( ( ang    + 360 ) &lt; 360 ) ang    += 360;00191   <font class="keywordflow">if</font>( ( angMin + 360 ) &lt; 360 ) angMin += 360;00192   <font class="keywordflow">if</font>( ( angMax + 360 ) &lt; 360 ) angMax += 360;00193 00194   <font class="keywordflow">if</font>( angMin &lt; angMax ) <font class="comment">// 0 ---false-- angMin ---true-----angMax---false--360</font>00195     <font class="keywordflow">return</font> angMin &lt; ang &amp;&amp; ang &lt; angMax ;00196   <font class="keywordflow">else</font>                  <font class="comment">// 0 ---true--- angMax ---false----angMin---true---360</font>00197     <font class="keywordflow">return</font> !( angMax &lt; ang &amp;&amp; ang &lt; angMin );00198 }00199 <a name="l00206"></a><a class="code" href="Geometry_8C.html#a13">00206</a> <a class="code" href="Geometry_8h.html#a2">AngDeg</a> <a class="code" href="Geometry_8h.html#a13">getBisectorTwoAngles</a>( <a class="code" href="Geometry_8h.html#a2">AngDeg</a> angMin, <a class="code" href="Geometry_8h.html#a2">AngDeg</a> angMax )00207 {00208   <font class="comment">// separate sine and cosine part to circumvent boundary problem</font>00209   <font class="keywordflow">return</font> <a class="code" href="classVecPosition.html#d1">VecPosition::normalizeAngle</a>(00210             <a class="code" href="Geometry_8h.html#a9">atan2Deg</a>( (<a class="code" href="Geometry_8h.html#a6">sinDeg</a>( angMin) + <a class="code" href="Geometry_8h.html#a6">sinDeg</a>( angMax ) )/2.0,00211                       (<a class="code" href="Geometry_8h.html#a5">cosDeg</a>( angMin) + <a class="code" href="Geometry_8h.html#a5">cosDeg</a>( angMax ) )/2.0 ) );00212 }00213 00214 <font class="comment">/******************************************************************************/</font>00215 <font class="comment">/********************   CLASS VECPOSITION   ***********************************/</font>00216 <font class="comment">/******************************************************************************/</font>00217 <a name="l00231"></a><a class="code" href="classVecPosition.html#a0">00231</a> <a class="code" href="classVecPosition.html#a0">VecPosition::VecPosition</a>( <font class="keywordtype">double</font> x, <font class="keywordtype">double</font> y, <a class="code" href="Geometry_8h.html#a19">CoordSystemT</a> cs )00232 {00233   <a class="code" href="classVecPosition.html#a29">setVecPosition</a>( x, y, cs );00234 }00235 <a name="l00240"></a><a class="code" href="classVecPosition.html#a1">00240</a> <a class="code" href="classVecPosition.html">VecPosition</a> <a class="code" href="classVecPosition.html#a1">VecPosition::operator - </a>( )00241 {00242   <font class="keywordflow">return</font> ( <a class="code" href="classVecPosition.html#a0">VecPosition</a>( -<a class="code" href="classVecPosition.html#o0">m_x</a>, -<a class="code" href="classVecPosition.html#o1">m_y</a> ) );00243 }00244 <a name="l00253"></a><a class="code" href="classVecPosition.html#a2">00253</a> <a class="code" href="classVecPosition.html">VecPosition</a> <a class="code" href="classVecPosition.html#a2">VecPosition::operator + </a>( <font class="keyword">const</font> <font class="keywordtype">double</font> &amp;d )00254 {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?