00001 /** 00002 * @file PfieldGeometry.h 00003 * 00004 * Definition of several geometric functions and objects used by potential fields 00005 * 00006 * @author <a href="mailto:timlaue@informatik.uni-bremen.de">Tim Laue</a> 00007 */ 00008 00009 #ifndef PFIELDGEOMETRY_H_ 00010 #define PFIELDGEOMETRY_H_ 00011 00012 00013 #include "PfieldDatatypes.h" 00014 #include "PotentialFunctions.h" 00015 00016 class Polygon; 00017 class PfieldGeometricObject; 00018 class Line; 00019 class Circle; 00020 00021 00022 /** Definition of the different types of geometric objects*/ 00023 enum GeometryType {POLYGON, LINE, CIRCLE, NONE}; 00024 00025 00026 /** Determines if a point is perpendicular to a line 00027 * @param l1 One end of the line 00028 * @param l2 The other end of the line 00029 * @param p The point 00030 * @param distance The distance to the line, if perpendicular 00031 * @param perpendicularPoint The point on the line, if perpendicular 00032 * @return true, if point is perpendicular. 00033 */ 00034 bool pointPerpendicularToLine(const PfVec& l1, const PfVec& l2, const PfVec& p, 00035 double& distance, PfVec& perpendicularPoint); 00036 00037 00038 /** Reduces the points of a polygon to its convex hull 00039 * @param p The polygon 00040 */ 00041 void reduceToConvexHullByWrapping(Polygon& p); 00042 00043 00044 /** Intersects two geometric objects and returns the intersection points as 00045 * well as significant points of the second object inside the intersection 00046 * @param g1 The first geometric object 00047 * @param g2 The second geometric object 00048 * @param intersections The intersections 00049 */ 00050 void intersectGeometricObjects(PfieldGeometricObject* g1, PfieldGeometricObject* g2, 00051 std::vector<PfVec>& intersections); 00052 00053 00054 /** Intersects a line with another line 00055 * (basic intersection checking has to be done before) 00056 * @param l1 A line 00057 * @param l2 Another line 00058 * @param intersections The intersections found 00059 */ 00060 void intersectLineAndLine(const Line& l1, const Line& l2, 00061 std::vector<PfVec>& intersections); 00062 00063 /** Intersects a line with a circle 00064 * (basic intersection checking has to be done before) 00065 * @param line A line 00066 * @param circle A circle 00067 * @param intersections The intersections found 00068 */ 00069 void intersectLineAndCircle(const Line& line, const Circle& circle, 00070 std::vector<PfVec>& intersections); 00071 00072 /** Intersects a polygon with a circle 00073 * (basic intersection checking has to be done before) 00074 * @param polygon A polygon 00075 * @param circle A circle 00076 * @param intersections The intersections found 00077 */ 00078 void intersectPolygonAndCircle(const Polygon& polygon, const Circle& circle, 00079 std::vector<PfVec>& intersections); 00080 00081 /** Intersects a circle with a circle 00082 * (basic intersection checking has to be done before) 00083 * @param circle1 A circle 00084 * @param circle2 Another circle 00085 * @param intersections The intersections found 00086 */ 00087 void intersectCircleAndCircle(const Circle& circle1, const Circle& circle2, 00088 std::vector<PfVec>& intersections); 00089 00090 00091 /** 00092 * @class PfieldGeometricObject 00093 * 00094 * Abstract base class for geometric objects used by potentialfields 00095 */ 00096 class PfieldGeometricObject 00097 { 00098 public: 00099 /** The radius of a circle around the whole object*/ 00100 double radiusOfCollisionCircle; 00101 /** Flag, true if object is intersectable by other objects*/ 00102 bool intersectable; 00103 /** The position of the object, only used with absolute positions*/ 00104 PfVec position; 00105 00106 /** Virtual destructor */ 00107 virtual ~PfieldGeometricObject() {} 00108 00109 /** Returns the type of a geometric object 00110 * @return The type 00111 */ 00112 virtual GeometryType getType() const = 0; 00113 00114 /** Clones a geometric object 00115 * @return A pointer to a copy of the object 00116 */ 00117 virtual PfieldGeometricObject* clone() const = 0; 00118 00119 /** Computes the distance from the border of the object to a given point 00120 * @param base The pose of the object to which the geometric object is assigned 00121 * @param pos The tested point 00122 * @param contact Returns the next position of the geometric object to the point 00123 * @return The distance 00124 */ 00125 virtual double distanceTo(const PfPose& base, const PfVec& pos, PfVec& contact) const = 0; 00126 00127 /** Computes value of the radiusOfCollisionCircle variable */ 00128 virtual void initRadiusOfCollisionCircle() = 0; 00129 00130 /** Returns the value of radiusOfCollisionCircle 00131 * @return The radius 00132 */ 00133 double getRadiusOfCollisionCircle() const 00134 { return radiusOfCollisionCircle;} 00135 00136 /** Returns the position 00137 * @return The position 00138 */ 00139 PfVec getPosition() const 00140 { return position;} 00141 00142 /** Returns a geometric object with absolute coordinates 00143 * @param base The pose of the object 00144 * @return A pointer to a new geometric object 00145 */ 00146 virtual PfieldGeometricObject* getAbs(const PfPose& base) const = 0; 00147 00148 /** Returns all points of the object 00149 * @param points The list of points to which the object's points will be attached 00150 */ 00151 virtual void getPoints(std::vector<PfVec>& points){} 00152 00153 /** Computes absolute coordinates from a base pose and another, relative 00154 * polygon. Use careful! The other object has to be the same type and 00155 * the size! Only positions are changed, other members will be ignored! 00156 * @param base The new absolute position 00157 * @param other A relative geometric object 00158 */ 00159 virtual void setAbsoluteFromOther(const PfPose& base, PfieldGeometricObject* other) = 0; 00160 }; 00161 00162 00163 /** 00164 * @class Polygon 00165 * 00166 * A class representing a convex polygon 00167 */ 00168 class Polygon: public PfieldGeometricObject 00169 { 00170 public: 00171 /** A list of points.*/ 00172 std::vector<PfVec> pts; 00173 00174 /** Adds a point to the polygon 00175 * @param p The point 00176 */ 00177 void addPoint(const PfVec& p) 00178 {pts.push_back(p);} 00179 00180 /** Returns the type of a geometric object 00181 * @return The type 00182 */ 00183 GeometryType getType() const 00184 { return POLYGON;} 00185 00186 /** Clones a polygon 00187 * @return A pointer to a copy of the object 00188 */ 00189 PfieldGeometricObject* clone() const; 00190 00191 /** Computes the distance from the border of the object to a given point 00192 * @param base The pose of the object to which the geometric object is assigned 00193 * @param pos The tested point 00194 * @param contact Returns the next position of the geometric object to the point 00195 * @return The distance 00196 */ 00197 double distanceTo(const PfPose& base, const PfVec& pos, PfVec& contact) const; 00198 00199 /** Computes value of the radiusOfCollisionCircle variable */ 00200 virtual void initRadiusOfCollisionCircle(); 00201 00202 /** Returns a geometric object with absolute coordinates 00203 * @param base The pose of the object 00204 * @return A pointer to a new geometric object 00205 */ 00206 PfieldGeometricObject* getAbs(const PfPose& base) const; 00207 00208 /** Returns all points of the object 00209 * @param points The list of points to which the object's points will be attached 00210 */ 00211 virtual void getPoints(std::vector<PfVec>& points); 00212 00213 /** Tests if a point is inside the polygon 00214 * @param point The point 00215 * @return true, if the point is inside 00216 */ 00217 bool pointInside(const PfVec& point) const; 00218 00219 /** Computes absolute coordinates from a base pose and another, relative 00220 * polygon. Use careful! The other object has to be the same type and 00221 * the size! Only positions are changed, other members will be ignored! 00222 * @param base The new absolute position 00223 * @param other A relative geometric object 00224 */ 00225 void setAbsoluteFromOther(const PfPose& base, PfieldGeometricObject* other); 00226 }; 00227 00228 00229 /** 00230 * @class Line 00231 * 00232 * A class representing a line 00233 */ 00234 class Line: public PfieldGeometricObject 00235 { 00236 public: 00237 /** One end point of the line */ 00238 PfVec p1; 00239 /** The other end point of the line */ 00240 PfVec p2; 00241 00242 /** Returns the type of a geometric object 00243 * @return The type 00244 */ 00245 GeometryType getType() const 00246 { return LINE;} 00247 00248 /** Clones a line 00249 * @return A pointer to a copy of the object 00250 */ 00251 PfieldGeometricObject* clone() const; 00252 00253 /** Computes the distance from the border of the object to a given point 00254 * @param base The pose of the object to which the geometric object is assigned 00255 * @param pos The tested point 00256 * @param contact Returns the next position of the geometric object to the point 00257 * @return The distance 00258 */ 00259 double distanceTo(const PfPose& base, const PfVec& pos, PfVec& contact) const; 00260 00261 /** Computes value of the radiusOfCollisionCircle variable */ 00262 virtual void initRadiusOfCollisionCircle(); 00263 00264 /** Returns a geometric object with absolute coordinates 00265 * @param base The pose of the object 00266 * @return A pointer to a new geometric object 00267 */ 00268 PfieldGeometricObject* getAbs(const PfPose& base) const; 00269 00270 /** Computes absolute coordinates from a base pose and another, relative 00271 * polygon. Use careful! The other object has to be the same type and 00272 * the size! Only positions are changed, other members will be ignored! 00273 * @param base The new absolute position 00274 * @param other A relative geometric object 00275 */ 00276 void setAbsoluteFromOther(const PfPose& base, PfieldGeometricObject* other); 00277 00278 /** Returns all points of the object 00279 * @param points The list of points to which the object's points will be attached 00280 */ 00281 virtual void getPoints(std::vector<PfVec>& points); 00282 }; 00283 00284 00285 /** 00286 * @class Circle 00287 * 00288 * A class representing a circle 00289 */ 00290 class Circle: public PfieldGeometricObject 00291 { 00292 public: 00293 /** The radius of the circle */ 00294 double radius; 00295 00296 /** Returns the type of a geometric object 00297 * @return The type 00298 */ 00299 GeometryType getType() const 00300 { return CIRCLE;} 00301 00302 /** Clones a circle 00303 * @return A pointer to a copy of the object 00304 */ 00305 PfieldGeometricObject* clone() const; 00306 00307 /** Computes the distance from the border of the object to a given point 00308 * @param base The pose of the object to which the geometric object is assigned 00309 * @param pos The tested point 00310 * @param contact Returns the next position of the geometric object to the point 00311 * @return The distance 00312 */ 00313 double distanceTo(const PfPose& base, const PfVec& pos, PfVec& contact) const; 00314 00315 /** Computes value of the radiusOfCollisionCircle variable */ 00316 virtual void initRadiusOfCollisionCircle(); 00317 00318 /** Returns a geometric object with absolute coordinates 00319 * @param base The pose of the object 00320 * @return A pointer to a new geometric object 00321 */ 00322 PfieldGeometricObject* getAbs(const PfPose& base) const; 00323 00324 /** Computes absolute coordinates from a base pose and another, relative 00325 * polygon. Use careful! The other object has to be the same type and 00326 * the size! Only positions are changed, other members will be ignored! 00327 * @param base The new absolute position 00328 * @param other A relative geometric object 00329 */ 00330 void setAbsoluteFromOther(const PfPose& base, PfieldGeometricObject* other); 00331 00332 /** Returns all points of the object 00333 * @param points The list of points to which the object's points will be attached 00334 */ 00335 virtual void getPoints(std::vector<PfVec>& points); 00336 }; 00337 00338 00339 /** 00340 * @class NoGeometry 00341 * 00342 * A class representing an empty geometric object 00343 */ 00344 class NoGeometry: public PfieldGeometricObject 00345 { 00346 public: 00347 /** Returns the type of a geometric object 00348 * @return The type 00349 */ 00350 GeometryType getType() const 00351 { return NONE;} 00352 00353 /** Clones an empty geometric object 00354 * @return A pointer to a copy of the object 00355 */ 00356 PfieldGeometricObject* clone() const; 00357 00358 /** Computes the distance from the border of the object to a given point 00359 * @param base The pose of the object to which the geometric object is assigned 00360 * @param pos The tested point 00361 * @param contact Returns the next position of the geometric object to the point 00362 * @return The distance 00363 */ 00364 double distanceTo(const PfPose& base, const PfVec& pos, PfVec& contact) const; 00365 00366 /** Computes value of the radiusOfCollisionCircle variable */ 00367 virtual void initRadiusOfCollisionCircle() 00368 { radiusOfCollisionCircle = 0.0;} 00369 00370 /** Returns a geometric object with absolute coordinates 00371 * @param base The pose of the object 00372 * @return A pointer to a new geometric object 00373 */ 00374 PfieldGeometricObject* getAbs(const PfPose& base) const; 00375 00376 /** Computes absolute coordinates from a base pose and another, relative 00377 * polygon. Use careful! The other object has to be the same type and 00378 * the size! Only positions are changed, other members will be ignored! 00379 * @param base The new absolute position 00380 * @param other A relative geometric object 00381 */ 00382 void setAbsoluteFromOther(const PfPose& base, PfieldGeometricObject* other); 00383 }; 00384 00385 00386 /** 00387 * @class Sector 00388 * 00389 * A class representing a sector 00390 */ 00391 class Sector 00392 { 00393 public: 00394 /** The opening angle of the sector*/ 00395 double openingAngle; 00396 /** The function used to compute the gradient to the center of the sector*/ 00397 PotentialfieldFunction* crossFunction; 00398 00399 /** Constructor */ 00400 Sector() 00401 { crossFunction = 0;} 00402 00403 /** Destructor*/ 00404 ~Sector() 00405 { 00406 if(crossFunction != 0) 00407 delete crossFunction; 00408 } 00409 00410 /** Tests if a point is in the sector 00411 * @param base The pose of the object to which the sector is assigned 00412 * @param pos The point to be tested 00413 * @return true, if the point is inside 00414 */ 00415 bool pointInside(const PfPose& base, const PfVec& pos) const; 00416 }; 00417 00418 00419 #endif //PFIELDGEOMETRY_H_ 00420 00421 00422 /* 00423 * $Log: PfieldGeometry.h,v $ 00424 * Revision 1.1.1.1 2004/05/22 17:37:32 cvsadm 00425 * created new repository GT2004_WM 00426 * 00427 * Revision 1.1 2004/01/20 15:42:19 tim 00428 * Added potential fields implementation 00429 * 00430 * Revision 1.5 2003/05/20 12:43:43 tim 00431 * Changed function representation, fixed crash on SuperCore, integrated social functions 00432 * 00433 * Revision 1.4 2003/04/22 14:35:17 tim 00434 * Merged changes from GO 00435 * 00436 * Revision 1.4 2003/04/09 19:03:06 tim 00437 * Last commit before GermanOpen 00438 * 00439 * Revision 1.3 2003/04/04 14:50:53 tim 00440 * Fixed bugs, added minor features 00441 * 00442 * Revision 1.2 2003/03/23 20:32:37 loetzsch 00443 * removed green compiler warning: no newline at end of file 00444 * 00445 * Revision 1.1 2003/03/23 17:51:27 tim 00446 * Added potentialfields 00447 * 00448 */