00001 /*---------------------------------------------------------------------+ 00002 | Library QgarLib, graphics analysis and recognition | 00003 | Copyright (C) 2002 Qgar Project, LORIA | 00004 | | 00005 | This library is free software; you can redistribute it and/or | 00006 | modify it under the terms of the GNU Lesser General Public | 00007 | License version 2.1, as published by the Free Software Foundation. | 00008 | | 00009 | This library is distributed in the hope that it will be useful, | 00010 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00011 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 00012 | See the GNU Lesser General Public License for more details. | 00013 | | 00014 | The GNU Lesser General Public License is included in the file | 00015 | LICENSE.LGPL, in the root directory of the Qgar packaging. See | 00016 | http://www.gnu.org/licenses/lgpl.html for the terms of the licence. | 00017 | To receive a paper copy, write to the Free Software Foundation, | 00018 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | 00019 | | 00020 | Contact Project Qgar for any information: | 00021 | LORIA - équipe Qgar | 00022 | B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France | 00023 | email: qgar-contact@loria.fr | 00024 | http://www.qgar.org/ | 00025 *---------------------------------------------------------------------*/ 00026 00027 00028 #ifndef ___QGAR_ANGLE_H_INCLUDED__ 00029 #define ___QGAR_ANGLE_H_INCLUDED__ 00030 00031 00032 /** 00033 * @file _QGAR_angle.H 00034 * @brief Global functions to compute angles from primitives. 00035 * 00036 * @warning <b>Not to be used as include file!</b> 00037 * <br>When working with primitives, use header file primitives.H. 00038 * 00039 * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a> 00040 * @date February 03 2005, 18:18 00041 * @since Qgar 2.2 00042 */ 00043 00044 00045 00046 // For RCS/CVS use: Do not delete 00047 /* $Id: _QGAR_angle.H,v 1.2 2005/09/14 10:53:19 masini Exp $ */ 00048 00049 00050 00051 namespace qgar 00052 { 00053 00054 00055 /*-------------------------------------------------------------------* 00056 | | 00057 | GLOBAL FUNCTIONS TO COMPUTE ANGLES FROM PRIMITIVES | 00058 | | 00059 *-------------------------------------------------------------------*/ 00060 00061 00062 00063 00064 /** 00065 * @name Global functions to compute angles between vectors 00066 * 00067 * @warning 00068 @verbatim 00069 O 00070 +---------------> X 00071 |\ | 00072 | \ <-' 00073 | \ angle (in radians unless specified) 00074 | \ 00075 | 00076 v 00077 00078 Y 00079 @endverbatim 00080 * <ul> 00081 * <li>The origin of the coordinate system is at top left corner.</li> 00082 * <li>Angles are clockwise from the X axis.</li> 00083 * </ul> 00084 */ 00085 //@{ 00086 00087 00088 00089 00090 /** 00091 * @ingroup GLOB_PRIM_ANG 00092 * 00093 * @brief Angle (in <b>[0, 2PI[</b> radians) between the X axis 00094 * and the vector formed by the two given points. 00095 @verbatim 00096 ----->/ 00097 O O / / 00098 +---------------> X +---------|-------------> X 00099 | \ | | | / | 00100 | \ <-' angle | angle \_ /__/ 00101 | \ | / 00102 | + aPt1 | + aPt2 00103 | \ | ^ 00104 | \ | / 00105 | v | / 00106 v + aPt2 v + aPt1 00107 00108 Y Y 00109 @endverbatim 00110 * 00111 * @param aPt1 a point 00112 * @param aPt2 a point 00113 * 00114 * @warning The vector orientation is 00115 * <b>first given point</b>--><b>second given point</b>. 00116 */ 00117 template <class T> 00118 double 00119 qgAngle(const GenPoint<T>& aPt1, const GenPoint<T>& aPt2); 00120 00121 00122 /** 00123 * @ingroup GLOB_PRIM_ANG 00124 * 00125 * @brief Same as qgar::qgAngle(const GenPoint<T>&, const GenPoint<T>&), 00126 * but the result is given in <b>[0, 360[</b> degrees. 00127 * 00128 * @param aPt1 a point 00129 * @param aPt2 a point 00130 */ 00131 template <class T> 00132 inline double 00133 qgAngleDegrees(const GenPoint<T>& aPt1, const GenPoint<T>& aPt2); 00134 00135 00136 00137 /** 00138 * @ingroup GLOB_PRIM_ANG 00139 * 00140 * @brief Angle (in <b>[0, 2PI[</b> radians) between two vectors 00141 * determined by 3 points. 00142 * 00143 * 00144 * First vector is <b>aPt1</b>--><b>aPt2</b>, 00145 * second vector is <b>aPt1</b>--><b>aPt3</b>. 00146 @verbatim 00147 0 00148 +---------------------> X +---------------------> X 00149 | | ---- 00150 | | / \ 00151 | aPt1 | | v 00152 | +--------->+ aPt2 | | +------->+ aPt3 00153 | \ | | \ __\ 00154 | \ <-' | \ 00155 | \ | \ 00156 | v | v 00157 | + aPt3 | + aPt2 00158 v v 00159 00160 Y Y 00161 @endverbatim 00162 * 00163 * @param aPt1 a point 00164 * @param aPt2 a point 00165 * @param aPt3 a point 00166 */ 00167 template <class T> 00168 double 00169 qgAngle(const GenPoint<T>& aPt1, 00170 const GenPoint<T>& aPt2, 00171 const GenPoint<T>& aPt3); 00172 00173 00174 /** 00175 * @ingroup GLOB_PRIM_ANG 00176 * 00177 * @brief Same as 00178 * qgar::qgAngle(const GenPoint<T>&,const GenPoint<T>&, const GenPoint<T>&), 00179 * but the result is given in <b>[0, 360[</b> degrees. 00180 */ 00181 template <class T> 00182 inline double 00183 qgAngleDegrees(const GenPoint<T>& aPt1, 00184 const GenPoint<T>& aPt2, 00185 const GenPoint<T>& aPt3); 00186 00187 00188 00189 /** 00190 * @ingroup GLOB_PRIM_ANG 00191 * 00192 * @brief Angle (in <b>[0, 2PI[</b> radians) between two vectors 00193 * determined by 4 points. 00194 * 00195 * First vector is <b>aPt1</b>--><b>aPt2</b>, 00196 * second vector is <b>aPt3</b>--><b>aPt4</b>. 00197 @verbatim 00198 0 00199 +----------------------> X +-------------------------> X 00200 | | ---- 00201 | | / \ 00202 | aPt1 | | v aPt3 00203 | \----+------>+ aPt2 | | \-----+------>+ aPt4 00204 | \ | | \ __\ 00205 | aPt3 + | | \ 00206 | <--' | + aPt1 00207 | \ | \ 00208 | v | v 00209 | + aPt4 | + aPt2 00210 v v 00211 00212 Y Y 00213 @endverbatim 00214 * 00215 * @param aPt1 a point 00216 * @param aPt2 a point 00217 * @param aPt3 a point 00218 * @param aPt4 a point 00219 */ 00220 template <class T> 00221 double 00222 qgAngle(const GenPoint<T>& aPt1, 00223 const GenPoint<T>& aPt2, 00224 const GenPoint<T>& aPt3, 00225 const GenPoint<T>& aPt4); 00226 00227 00228 /** 00229 * @ingroup GLOB_PRIM_ANG 00230 * 00231 * @brief Same as 00232 * qgar::qgAngle(const GenPoint<T>&,const GenPoint<T>&, const GenPoint<T>&, const GenPoint<T>&), 00233 * but the result is given in <b>[0, 360[</b> degrees. 00234 */ 00235 template <class T> 00236 inline double 00237 qgAngleDegrees(const GenPoint<T>& aPt1, 00238 const GenPoint<T>& aPt2, 00239 const GenPoint<T>& aPt3, 00240 const GenPoint<T>& aPt4); 00241 00242 00243 00244 /** 00245 * @ingroup GLOB_PRIM_ANG 00246 * 00247 * @brief Angle (in <b>[0, PI[</b> radians) between the X axis 00248 * and the segment formed by the two given points. 00249 @verbatim 00250 O O 00251 +-----------------> X +-----------------> X 00252 | \ | | \ | 00253 | \ <-' angle | \ <-' angle 00254 | \ | \ 00255 | + aPt1 | + aPt2 00256 | \ | \ 00257 | \ | \ 00258 | \ | \ 00259 v + aPt2 v + aPt1 00260 00261 Y Y 00262 @endverbatim 00263 * 00264 * @param aPt1 a point 00265 * @param aPt2 a point 00266 */ 00267 template <class T> 00268 double 00269 qgSlope(const GenPoint<T>& aPt1, const GenPoint<T>& aPt2); 00270 00271 00272 /** 00273 * @ingroup GLOB_PRIM_ANG 00274 * 00275 * @brief Same as qgar::qgSlope(const GenPoint<T>&, const GenPoint<T>&), 00276 * but the result is given in <b>[0, 180[</b> degrees. 00277 */ 00278 template <class T> 00279 inline double 00280 qgSlopeDegrees(const GenPoint<T>& aPt1, const GenPoint<T>& aPt2); 00281 00282 00283 //@} 00284 00285 00286 /*-------------------------------------------------------------------* 00287 | | 00288 *-------------------------------------------------------------------*/ 00289 00290 00291 } // namespace qgar 00292 00293 00294 #endif /* ___QGAR_GLOBALPRIMITIVEFUNCTIONS_H_INCLUDED__ */