math.cpp
Go to the documentation of this file.
2 
4 {
5 bool pointWithinPolygon(int x, int y, const std::vector<std::pair<int, int> >& edges)
6 {
7  int cn = 0;
8 
9  // loop through all edges of the polygon
10  for(unsigned int i = 0; i < edges.size(); ++i)
11  {
12  unsigned int i_plus = (i + 1) % edges.size();
13  if ((edges[i].second <= y && edges[i_plus].second > y) ||
14  (edges[i].second > y && edges[i_plus].second <= y))
15  {
16  if (fabs(edges[i_plus].second - edges[i].second) > FLOAT_CMP_THR)
17  {
18  float vt = (float)(y - edges[i].second) / (edges[i_plus].second - edges[i].second);
19  if (x < edges[i].first + vt * (edges[i_plus].first - edges[i].first))
20  cn++;
21  }
22  }
23  }
24  return cn & 1;
25 }
26 
27 void getDeltaStep(const msgs::Foot& current, const msgs::Foot& next, geometry_msgs::Pose& dstep)
28 {
29  tf::Pose current_tf;
30  tf::poseMsgToTF(current.pose, current_tf);
31 
32  tf::Pose next_tf;
33  tf::poseMsgToTF(next.pose, next_tf);
34 
35  tf::Pose dstep_tf;
36  getDeltaStep(current_tf, next_tf, dstep_tf);
37  tf::poseTFToMsg(dstep_tf, dstep);
38 
39  // adjust for the left foot
40  if (current.foot_index != next.foot_index && current.foot_index == msgs::Foot::LEFT)
41  {
42  dstep.position.y = -dstep.position.y;
43 
44  double r, p, y;
45  dstep_tf.getBasis().getRPY(r, p, y);
46  dstep.orientation = tf::createQuaternionMsgFromRollPitchYaw(-r, p, -y);
47 
48 // double dyaw = angles::shortest_angular_distance(current.getYaw(), next.getYaw());
49 // dy = -dy;
50 // dyaw = -dyaw;
51  }
52 }
53 
54 void getDeltaStep(const tf::Pose& current, const tf::Pose& next, tf::Pose& dstep)
55 {
56  // reconstruct step primitive (current -> next, must be mirrored if current is left foot)
57  dstep = current.inverse() * next;
58 }
59 
60 void quaternionToNormalYaw(const geometry_msgs::Quaternion& q, geometry_msgs::Vector3& n, double& yaw)
61 {
62  tf::Quaternion q_tf;
63  tf::quaternionMsgToTF(q, q_tf);
64 
65  double r, p, y;
66  tf::Matrix3x3(q_tf).getRPY(r, p, y);
67 
68  RPYToNormal(r, p, y, n);
69 
70  yaw = y;
71 }
72 
73 void quaternionToNormal(const geometry_msgs::Quaternion& q, geometry_msgs::Vector3& n)
74 {
75  tf::Quaternion q_tf;
76  tf::quaternionMsgToTF(q, q_tf);
77 
78  double r, p, y;
79  tf::Matrix3x3(q_tf).getRPY(r, p, y);
80 
81  RPYToNormal(r, p, y, n);
82 }
83 
84 void normalToQuaternion(const geometry_msgs::Vector3& n, double yaw, geometry_msgs::Quaternion& q)
85 {
86  double r, p;
87  normalToRP(n, yaw, r, p);
89 }
90 
91 void RPYToNormal(double r, double p, double y, geometry_msgs::Vector3& n)
92 {
93  double sin_roll = sin(r);
94  double sin_pitch = sin(p);
95  double sin_yaw = sin(y);
96  double cos_yaw = cos(y);
97 
98  // rotate around z axis
99  n.x = cos_yaw*sin_pitch + sin_yaw*sin_roll;
100  n.y = sin_yaw*sin_pitch - cos_yaw*sin_roll;
101  n.z = sqrt(1.0 - n.x*n.x + n.y*n.y);
102 }
103 
104 void normalToRP(const geometry_msgs::Vector3& n, double yaw, double& r, double& p)
105 {
106  // inverse rotation around z axis
107  double sin_yaw = sin(-yaw);
108  double cos_yaw = cos(-yaw);
109 
110  r = -asin(sin_yaw*n.x + cos_yaw*n.y);
111  p = asin(cos_yaw*n.x - sin_yaw*n.y);
112 }
113 }
bool pointWithinPolygon(int x, int y, const std::vector< std::pair< int, int > > &edges)
Crossing number method to determine whether a point lies within a polygon or not. ...
Definition: math.cpp:5
static void poseMsgToTF(const geometry_msgs::Pose &msg, Pose &bt)
void normalToQuaternion(const geometry_msgs::Vector3 &n, double yaw, geometry_msgs::Quaternion &q)
Definition: math.cpp:84
TFSIMD_FORCE_INLINE Matrix3x3 & getBasis()
static const double FLOAT_CMP_THR
Definition: math.h:49
TFSIMD_FORCE_INLINE const tfScalar & y() const
void quaternionToNormal(const geometry_msgs::Quaternion &q, geometry_msgs::Vector3 &n)
Definition: math.cpp:73
void quaternionToNormalYaw(const geometry_msgs::Quaternion &q, geometry_msgs::Vector3 &n, double &yaw)
Definition: math.cpp:60
void RPYToNormal(double r, double p, double y, geometry_msgs::Vector3 &n)
Definition: math.cpp:91
static void quaternionMsgToTF(const geometry_msgs::Quaternion &msg, Quaternion &bt)
void getRPY(tfScalar &roll, tfScalar &pitch, tfScalar &yaw, unsigned int solution_number=1) const
void normalToRP(const geometry_msgs::Vector3 &n, double yaw, double &r, double &p)
Definition: math.cpp:104
Transform inverse() const
void getDeltaStep(const msgs::Foot &current, const msgs::Foot &next, geometry_msgs::Pose &dstep)
Definition: math.cpp:27
static void poseTFToMsg(const Pose &bt, geometry_msgs::Pose &msg)
static geometry_msgs::Quaternion createQuaternionMsgFromRollPitchYaw(double roll, double pitch, double yaw)


vigir_footstep_planning_lib
Author(s): Alexander Stumpf
autogenerated on Mon Jun 10 2019 15:47:33