Utils.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Daniel Claes, Maastricht University
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Maastricht University nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef UTILS_H
00031 #define UTILS_H
00032 
00033 #include <cmath>
00034 #include <limits>
00035 #include <vector>
00036 
00037 #include "collvoid_local_planner/Vector2.h"
00038 
00039 static const float EPSILON = 0.001f;
00040 
00041 namespace collvoid
00042 {
00043   struct Line {
00044       Vector2 point;
00045       Vector2 dir;
00046   };
00047 
00048   struct VO {
00049     Vector2 point;
00050 
00051     Vector2 relative_position;
00052     double combined_radius;
00053 
00054     Vector2 left_leg_dir;
00055     Vector2 right_leg_dir;
00056 
00057     Vector2 trunc_line_center;
00058     Vector2 trunc_left;
00059     Vector2 trunc_right;
00060     
00061   };
00062 
00063 
00064   struct VelocitySample {
00065     Vector2 velocity;
00066     double dist_to_pref_vel;
00067   };
00068 
00069   struct ConvexHullPoint{
00070     Vector2 point;
00071     double weight;
00072     int index;
00073     int orig_index;
00074   };
00075 
00076 
00077   inline Vector2 projectPointOnLine(const Vector2& pointLine, const Vector2& dirLine, const Vector2& point) {
00078     const double r = ((point - pointLine) * (dirLine)) / absSqr(dirLine);
00079     return pointLine + r * dirLine;
00080   }
00081 
00091   inline double distSqPointLineSegment(const Vector2& a, const Vector2& b,
00092                                       const Vector2& c)
00093   {
00094     const double r = ((c - a) * (b - a)) / absSqr(b - a);
00095 
00096     if (r < 0.0f) {
00097       return absSqr(c - a);
00098     } else if (r > 1.0f) {
00099       return absSqr(c - b);
00100     } else {
00101       return absSqr(c - (a + r * (b - a)));
00102     }
00103   }
00104 
00114   inline double signedDistPointToLineSegment(const Vector2& a, const Vector2& b, const Vector2& c)
00115   {
00116     return det(a - c, b - a);
00117   }
00118 
00119   inline double left(const Vector2& pointLine, const Vector2& dirLine, const Vector2& point) {
00120     return signedDistPointToLineSegment(pointLine, pointLine+dirLine, point);
00121   }
00122 
00123   inline bool leftOf(const Vector2& pointLine, const Vector2& dirLine, const Vector2& point) {
00124     return signedDistPointToLineSegment(pointLine, pointLine+dirLine, point) > EPSILON;
00125   }
00126 
00127   inline bool rightOf(const Vector2& pointLine, const Vector2& dirLine, const Vector2& point) {
00128     return signedDistPointToLineSegment(pointLine, pointLine+dirLine, point) < -EPSILON;
00129   }
00130 
00131   inline double sign(double x){
00132     return x < 0.0 ? -1.0 : 1.0;
00133   }
00134 
00135   inline double sqr(double a)
00136   {
00137     return a * a;
00138   }
00139 
00140 
00141 
00142 }
00143 
00144 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


collvoid_local_planner
Author(s): Daniel Claes
autogenerated on Sun Aug 25 2013 10:10:23