latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*---------------------------------------------------------------- 00025 * project ....: LTI Digital Image/Signal Processing Library 00026 * file .......: ltiGeometry.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 19.03.02 00030 * revisions ..: $Id: ltiGeometry.h,v 1.4 2006/02/08 12:25:54 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_GEOMETRY_H_ 00034 #define _LTI_GEOMETRY_H_ 00035 00036 #include "ltiMath.h" 00037 #include "ltiTypes.h" 00038 #include "ltiPoint.h" 00039 00040 /** 00041 * \file ltiGeometry.h 00042 * Definition of some usually used global functions for geometric 00043 * condition like line intersections. 00044 */ 00045 00046 namespace lti { 00047 00048 /** 00049 * compute if the line between p1 and p2 intersects with the line 00050 * between p3 and p4. If they intersect in exactly one point 00051 * (normal case) the function returns true. If the lines are 00052 * parallel or any of the lines have length 0 this function returns 00053 * false. 00054 * 00055 * @param p1 begin of first line 00056 * @param p2 end of first line 00057 * @param p3 begin of first line 00058 * @param p4 end of first line 00059 * @param p intersection point will be written here, in case there is one. 00060 * if there is no intersection point (or infinity) the value 00061 * will not change. 00062 * 00063 * @return true if lines intersect in exactly one point, false otherwise 00064 * 00065 * @ingroup gGeometry 00066 * 00067 * Defined in ltiGeometry.h 00068 */ 00069 template<class T> 00070 bool intersection(const tpoint<T>& p1,const tpoint<T>& p2, 00071 const tpoint<T>& p3,const tpoint<T>& p4, 00072 tpoint<T>& p); 00073 00074 /** 00075 * compute if the line between p1 and p2 intersects with the line 00076 * between p3 and p4. If they intersect in exactly one point 00077 * (normal case) the function returns true. If the lines are 00078 * parallel or any of the lines have length 0 this function returns 00079 * false. 00080 * 00081 * @param p1 begin of first line 00082 * @param p2 end of first line 00083 * @param p3 begin of first line 00084 * @param p4 end of first line 00085 * 00086 * @return true if lines intersect in exactly one point, false otherwise 00087 * 00088 * @ingroup gGeometry 00089 * 00090 * Defined in ltiGeometry.h 00091 */ 00092 template<class T> 00093 inline bool intersection(const tpoint<T>& p1,const tpoint<T>& p2, 00094 const tpoint<T>& p3,const tpoint<T>& p4) { 00095 tpoint<T> p; 00096 return intersection(p1,p2,p3,p4,p); 00097 } 00098 00099 /** 00100 * compute the square of the minimal distance between the line 00101 * segment defined by the points p1 and p2 and the point p3. The 00102 * point within the line with the minimal distance will be stored in 00103 * p. 00104 * 00105 * @param p1 start point of the line segment 00106 * @param p2 end point of the line segment 00107 * @param p3 point, for which the distance to the line segment will be 00108 * computed. 00109 * @param p the point in the line between p1 and p2 with the shortest 00110 * distance will be stored here. 00111 * @return the square of the distance between the line p1_p2 and the point 00112 * p3 00113 * 00114 * @ingroup gGeometry 00115 * 00116 * Defined in ltiGeometry.h 00117 */ 00118 template<class T> 00119 T minDistanceSqr(const tpoint<T>& p1, 00120 const tpoint<T>& p2, 00121 const tpoint<T>& p3, 00122 tpoint<T>& p); 00123 00124 /** 00125 * compute the square of the minimal distance between the line 00126 * segment defined by the points p1 and p2 and the point p3. The 00127 * point within the line with the minimal distance will be stored in 00128 * p. 00129 * 00130 * @param p1 start point of the line segment 00131 * @param p2 end point of the line segment 00132 * @param p3 point, for which the distance to the line segment will be 00133 * computed. 00134 * @return the square of the distance between the line p1_p2 and the point 00135 * p3 00136 * 00137 * @ingroup gGeometry 00138 * 00139 * Defined in ltiGeometry.h 00140 */ 00141 template<class T> 00142 inline T minDistanceSqr(const tpoint<T>& p1, 00143 const tpoint<T>& p2, 00144 const tpoint<T>& p3) { 00145 tpoint<T> tmp; 00146 return minDistanceSqr(p1,p2,p3,tmp); 00147 } 00148 00149 /** 00150 * compute the square of the minimal distance between the line 00151 * segment defined by the points p1 and p2 and the line segment 00152 * defined by the points p3 and p4. The corresponding points with the 00153 * minimal distance will be stored in pa (in p1-p2) and pb (in p3-p4). 00154 * 00155 * @param p1 start point of the first line segment 00156 * @param p2 end point of the first line segment 00157 * @param p3 start point of the second line segment 00158 * @param p4 end point of the second line segment 00159 * @param pa point in the line p1-p2 with the minimal distance to 00160 * the line segment p3-p4. 00161 * @param pb point in the line p3-p4 with the minimal distance to 00162 * the line segment p1-p2. 00163 * @return the square of the distance between the line p1-p2 and p3-p4 00164 * 00165 * @ingroup gGeometry 00166 * 00167 * Defined in ltiGeometry.h 00168 */ 00169 template<class T> 00170 T minDistanceSqr(const tpoint<T>& p1, 00171 const tpoint<T>& p2, 00172 const tpoint<T>& p3, 00173 const tpoint<T>& p4, 00174 tpoint<T>& pa, 00175 tpoint<T>& pb); 00176 00177 /** 00178 * compute if the path that follows the points p0, p1 and p2 00179 * makes a clock-wise turn (+1) a counter-clock-wise turn (-1) or 00180 * stays in a straight line (0). 00181 * 00182 * @param p0 first point 00183 * @param p1 second point 00184 * @param p2 third point 00185 * 00186 * @return +1 for a clockwise turn, -1 for a counter clockwise turn, 0 00187 * if path stays in a straight line. 00188 * 00189 * @ingroup gGeometry 00190 * 00191 * Defined in ltiGeometry.h 00192 */ 00193 template<class T> 00194 int clockwiseTurn(const tpoint<T>& p0, 00195 const tpoint<T>& p1, 00196 const tpoint<T>& p2); 00197 00198 00199 } 00200 #endif