Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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